Skip to content

Commit d622fb6

Browse files
authored
add byte code compatiable dune build (#14)
1 parent 4e7d870 commit d622fb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1691
-1357
lines changed

Makefile

Lines changed: 2 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,10 @@
1-
################################################################################
2-
# Variables to override #
3-
################################################################################
4-
5-
INTERNAL_MODULES=src/stubs
6-
7-
################################################################################
8-
# OS-dependent stuff #
9-
################################################################################
10-
11-
ifeq ($(UNAME_S), Linux)
12-
INOTIFY=src/third-party/inotify
13-
INOTIFY_STUBS=$(INOTIFY)/inotify_stubs.c
14-
FSNOTIFY=src/fsnotify_linux
15-
FSNOTIFY_STUBS=
16-
RT=rt
17-
FRAMEWORKS=
18-
EXE=
19-
endif
20-
ifeq ($(UNAME_S), Darwin)
21-
INOTIFY=src/fsevents
22-
INOTIFY_STUBS=$(INOTIFY)/fsevents_stubs.c
23-
FSNOTIFY=src/fsnotify_darwin
24-
FSNOTIFY_STUBS=
25-
RT=
26-
FRAMEWORKS=CoreServices CoreFoundation
27-
EXE=
28-
endif
29-
ifeq ($(UNAME_S), Windows)
30-
INOTIFY=
31-
INOTIFY_STUBS=
32-
FSNOTIFY=src/fsnotify_win
33-
FSNOTIFY_STUBS=$(FSNOTIFY)/fsnotify_stubs.c
34-
RT=
35-
FRAMEWORKS=
36-
EXE=.exe
37-
endif
38-
39-
################################################################################
40-
# Definitions #
41-
################################################################################
42-
43-
MODULES=\
44-
src/third-party/lz4\
45-
src/heap\
46-
src/injection/default_injector\
47-
src/procs\
48-
src/socket\
49-
src/third-party/hack_core\
50-
src/utils\
51-
src/utils/collections\
52-
src/utils/disk\
53-
src/utils/hh_json\
54-
$(INOTIFY)\
55-
$(FSNOTIFY)\
56-
$(INTERNAL_MODULES)
57-
58-
NATIVE_C_FILES=\
59-
$(INOTIFY_STUBS)\
60-
$(FSNOTIFY_STUBS)\
61-
src/heap/hh_shared.c\
62-
src/utils/files.c\
63-
src/utils/handle_stubs.c\
64-
src/utils/nproc.c\
65-
src/utils/realpath.c\
66-
src/utils/sysinfo.c\
67-
src/utils/priorities.c\
68-
$(sort $(wildcard src/third-party/lz4/*.c))
69-
70-
NATIVE_LIBRARIES=\
71-
hp\
72-
pthread\
73-
$(RT)
74-
75-
################################################################################
76-
# Rules #
77-
################################################################################
78-
79-
NATIVE_C_DIRS=$(patsubst %/,%,$(sort $(dir $(NATIVE_C_FILES))))
80-
ALL_HEADER_FILES=$(addprefix _build/,$(shell find $(NATIVE_C_DIRS) -name '*.h'))
81-
82-
83-
NATIVE_OBJECT_FILES=$(patsubst %.c,%.o,$(NATIVE_C_FILES))
84-
85-
BUILT_OBJECT_FILES=$(addprefix _build/,$(NATIVE_OBJECT_FILES))
86-
NATIVE_LIB_OPTS=$(foreach lib, $(NATIVE_LIBRARIES),-cclib -l -cclib $(lib))
87-
88-
LINKER_FLAGS=$(NATIVE_LIB_OPTS)
89-
90-
INCLUDE_OPTS=$(foreach dir,$(MODULES),-I $(dir))
91-
92-
BUILT_C_DIRS=$(addprefix _build/,$(NATIVE_C_DIRS))
93-
BUILT_C_FILES=$(addprefix _build/,$(NATIVE_C_FILES))
94-
CC_FLAGS=-DNO_SQLITE3
95-
CC_OPTS=$(foreach flag, $(CC_FLAGS), -ccopt $(flag))
96-
97-
ALL_INCLUDE_PATHS=$(sort $(realpath $(BUILT_C_DIRS)))
98-
EXTRA_INCLUDE_OPTS=$(foreach dir, $(ALL_INCLUDE_PATHS),-ccopt -I -ccopt $(dir))
99-
100-
%.h: $(subst _build/,,$@)
101-
mkdir -p $(dir $@)
102-
cp $(subst _build/,,$@) $@
103-
1041
.PHONY: all
105-
all: libhp.a
106-
mkdir -p _build/default
107-
cp static_libs/libhp.a _build/default/
108-
dune build @install -j auto --profile dev
2+
all:
3+
dune build -j auto --profile dev
1094

110-
.PHONY: install
1115
install:
1126
dune install
1137

114-
.PHONY: generate_install
115-
generate_install:
116-
find _build -type f '('\
117-
-name '*.a' -o\
118-
-name '*.annot' -o\
119-
-name '*.cma' -o\
120-
-name '*.cmi' -o\
121-
-name '*.cmo' -o\
122-
-name '*.cmt' -o\
123-
-name '*.cmti' -o\
124-
-name '*.cmx' -o\
125-
-name '*.cmxa' -o\
126-
-name '*.ml' -o\
127-
-name '*.mli'\
128-
')'\
129-
> install.txt
130-
131-
.PHONY: remove
132-
remove:
133-
dune uninstall
134-
1358
.PHONY: clean
1369
clean:
137-
rm -rf static_libs
13810
dune clean
139-
140-
$(BUILT_C_FILES): _build/%.c: %.c
141-
mkdir -p $(dir $@)
142-
cp $< $@
143-
144-
$(BUILT_OBJECT_FILES): %.o: %.c $(ALL_HEADER_FILES)
145-
cd $(dir $@) && ocamlopt $(EXTRA_INCLUDE_OPTS) $(CC_OPTS) -c $(notdir $<)
146-
147-
libhp.a: $(BUILT_OBJECT_FILES)
148-
ar -cvq libhp.a $(BUILT_OBJECT_FILES)
149-
mkdir -p static_libs
150-
mv libhp.a static_libs

dune

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
(copy_files# static_libs/*)
2-
31
(env
42
(dev
5-
(flags (:standard -w A-3-4-6-27-29-34-32-35-39-40-41-42-44-45-48-49-50-57))))
3+
(flags (:standard -w A-3-4-23-40-41-42-44-45-48-49-50-57))
4+
(ocamlopt_flags (-g -Oclassic)))
5+
(release
6+
(flags (:standard -w A-3-4-23-40-41-42-44-45-48-49-50-57))
7+
(ocamlopt_flags (-O3))))
68

79
(library
8-
(name hack_parallel)
9-
(public_name hack_parallel)
10-
(c_library_flags -L static_libs -l hp)
11-
(libraries
12-
str
13-
core
14-
hack_parallel.scheduler
15-
hack_parallel.memory))
16-
17-
(install
18-
(section lib)
19-
(files static_libs/libhp.a))
10+
(name hack_parallel)
11+
(public_name hack_parallel)
12+
(library_flags (-cclib -l -cclib pthread -cclib -l -cclib sqlite3))
13+
(libraries
14+
hack_parallel.scheduler
15+
hack_parallel.memory))

dune-project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(lang dune 1.11)
2+
(name hack_parallel)

hack_parallel.opam

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ bug-reports: "https://github.com/rvantonder/hack-parallel/issues"
66
dev-repo: "git+https://github.com/rvantonder/hack-parallel.git"
77
license: "MIT"
88
build: [
9-
[make "libhp.a"]
109
["dune" "build" "-p" name "-j" jobs "@install"]
1110
]
1211
depends: [
1312
"core"
1413
"ocaml" {>= "4.03.0"}
1514
"ppx_deriving"
16-
"ppxlib"
17-
"sexplib"
1815
"str"
1916
]
2017
synopsis: "Parallel and shared memory library"

scripts/dune

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(rule
2+
(targets get_build_id.c)
3+
(deps gen_build_id.ml script_utils.ml)
4+
(action
5+
(run ocaml -I scripts -w -3 -unsafe-string unix.cma gen_build_id.ml get_build_id.c)))

scripts/gen_build_id.ml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
(**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
#use "script_utils.ml"
9+
10+
(**
11+
* Computes some build identifiers based on the current commit. These IDs are
12+
* used to ensure that clients and servers are the same version, even between
13+
* releases. For example, if you build revision A and start a server, then check
14+
* out and build revision B, it's convenient for the server to restart itself
15+
* using revision B.
16+
*
17+
* This fails gracefully when neither hg nor git are installed, or when neither
18+
* .hg nor .git exist (e.g. when building from a tarball). This is fine because
19+
* you can't move between commits in such a snapshot.
20+
*)
21+
let () =
22+
let out_file = Sys.argv.(1) in
23+
let rev =
24+
try read_process_stdout "git" [|"git"; "rev-parse"; "HEAD"|]
25+
with Failure msg -> (
26+
Printf.eprintf "Failed git rev-parse: %s\n%!" msg;
27+
try read_process_stdout "hg" [|"hg"; "id"; "-i"|]
28+
with Failure msg -> (
29+
Printf.eprintf "Failed hg id: %s\n%!" msg;
30+
""
31+
)
32+
)
33+
in
34+
let time =
35+
try read_process_stdout "git" [|"git"; "log"; "-1"; "--pretty=tformat:%ct"|]
36+
with Failure msg -> (
37+
Printf.eprintf "Failed git log: %s\n%!" msg;
38+
try
39+
let raw = read_process_stdout "hg" [|"hg"; "log"; "-r"; "."; "-T"; "{date|hgdate}\\n"|] in
40+
String.sub raw 0 (String.index raw ' ')
41+
with
42+
| Failure msg -> (
43+
Printf.eprintf "Failed hg log: %s\n%!" msg;
44+
"0"
45+
)
46+
| Not_found -> "0"
47+
)
48+
in
49+
let content = Printf.sprintf
50+
"const char* const BuildInfo_kRevision = %S;\nconst unsigned long BuildInfo_kRevisionCommitTimeUnix = %sul;\n"
51+
rev time in
52+
let do_dump =
53+
not (Sys.file_exists out_file) || string_of_file out_file <> content in
54+
if do_dump then
55+
with_out_channel out_file @@ fun oc ->
56+
output_string oc content

scripts/script_utils.ml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
let with_pipe f =
9+
let fd_r, fd_w = Unix.pipe () in
10+
try
11+
let res = f (fd_r, fd_w) in
12+
Unix.close fd_r;
13+
Unix.close fd_w;
14+
res
15+
with exn ->
16+
Unix.close fd_r;
17+
Unix.close fd_w;
18+
raise exn
19+
20+
let with_in_channel filename f =
21+
let ic = open_in_bin filename in
22+
try let res = f ic in close_in ic; res
23+
with exn -> close_in ic; raise exn
24+
25+
let with_out_channel filename f =
26+
let oc = open_out_bin filename in
27+
try let res = f oc in close_out oc; res
28+
with exn -> close_out oc; raise exn
29+
30+
let read_process name args (in_r, _in_w) (out_r, out_w) (err_r, err_w) =
31+
let pid =
32+
try Unix.create_process name args in_r out_w err_w
33+
with Unix.Unix_error (Unix.ENOENT, _, _) ->
34+
(* On Windows, this is what happens if you call create_process
35+
* non_existent_thing *)
36+
raise (Failure (name ^ ": command not found"))
37+
in
38+
match Unix.waitpid [] pid with
39+
| _, Unix.WEXITED 0 ->
40+
input_line (Unix.in_channel_of_descr out_r)
41+
| _, Unix.WEXITED 127 ->
42+
(* On Linux & OSX, this is what happens if you call create_process
43+
* non_existent_thing *)
44+
raise (Failure (name ^ ": command not found"))
45+
| _, Unix.WEXITED 128 ->
46+
raise (Failure (input_line (Unix.in_channel_of_descr err_r)))
47+
| _, Unix.WEXITED code ->
48+
raise (Failure (name ^ ": exited code "^(string_of_int code)))
49+
| _, Unix.WSIGNALED signal ->
50+
raise (Failure (name ^ ": killed by signal " ^ (string_of_int signal)))
51+
| _, Unix.WSTOPPED signal ->
52+
raise (Failure (name ^ ": stopped by signal " ^ (string_of_int signal)))
53+
54+
(* Read the first line in stdout or stderr of an external command. *)
55+
let read_process_output name args =
56+
with_pipe @@ fun in_pipe ->
57+
with_pipe @@ fun out_pipe ->
58+
read_process name args in_pipe out_pipe out_pipe
59+
60+
(* Read the first line in stdout of an external command. *)
61+
let read_process_stdout name args =
62+
with_pipe @@ fun in_pipe ->
63+
with_pipe @@ fun out_pipe ->
64+
with_pipe @@ fun err_pipe ->
65+
read_process name args in_pipe out_pipe err_pipe
66+
67+
let string_of_file filename =
68+
with_in_channel filename @@ fun ic ->
69+
let s = Bytes.create 32759 in
70+
let b = Buffer.create 1000 in
71+
let rec iter ic b s =
72+
let nread = input ic s 0 32759 in
73+
if nread > 0 then begin
74+
Buffer.add_subbytes b s 0 nread;
75+
iter ic b s
76+
end in
77+
iter ic b s;
78+
Buffer.contents b

src/heap/dune

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
(library
2-
(name heap)
3-
(public_name hack_parallel.heap)
4-
(wrapped false)
5-
(libraries
6-
hack_core
7-
hack_parallel.stubs
8-
hack_parallel.utilities))
2+
(name heap)
3+
(public_name hack_parallel.heap)
4+
(wrapped false)
5+
(modules (:standard))
6+
(c_names
7+
hh_assert
8+
hh_shared
9+
hh_shared_sqlite)
10+
(c_flags (:standard -I%{project_root}/src/third-party/lz4))
11+
(c_library_flags (-lsqlite3))
12+
(libraries
13+
hack_parallel.collections
14+
hack_parallel.lz4
15+
hack_parallel.stubs
16+
hack_parallel.utils))

src/heap/hh_assert.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the "hack" directory of this source tree.
7+
*
8+
*/
9+
10+
#include "hh_assert.h"
11+
12+
#define CAML_NAME_SPACE
13+
#include <caml/callback.h>
14+
#include <caml/fail.h>
15+
16+
void raise_assertion_failure(char * msg) {
17+
caml_raise_with_string(*caml_named_value("c_assertion_failure"), msg);
18+
}

0 commit comments

Comments
 (0)