Skip to content

Commit

Permalink
Add a .mllib -> .cmxs rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaël Guéneau committed Dec 1, 2016
1 parent 09d4cd0 commit 89888f2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ NEXT_RELEASE:
- #127: install ocamlbuild's man pages, missing since 4.02
(Gabriel Scherer)

- #132: add a rule producing .cmxs from .mllib files.
Previously, .mllib files would only produce .cm{x,}a files, and .cmxs were
only produced by a separate (and in most cases redundant) .mldylib file.
This rule allows to produce .cmxs from .mllib files; .mldylib files
still take precedence when they exist.
(Armaël Guéneau, requested by Daniel Bünzli)

0.9.3 (6 Oct 2016):
-------------------

Expand Down
27 changes: 22 additions & 5 deletions src/ocaml_specific.ml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ rule "ocaml: mllib & cmx* & o* -> cmxa & a"
as the .cma rule above. Note that whereas bytecode .cma can \
be used both for static and dynamic linking, .cmxa only support \
static linking. For an archive usable with Dynlink, \
see the rule producing a .cmxs from a .mldylib."
see the rules producing a .cmxs from a .mllib or a .mldylib."
(Ocaml_compiler.native_library_link_mllib "%.mllib" "%.cmxa");;

rule "ocaml: p.cmx & p.o -> p.cmxa & p.a"
Expand Down Expand Up @@ -363,6 +363,19 @@ rule "ocaml: mldylib & cmx* & o* -> cmxs & so"
the modules listed in the corresponding .mldylib file."
(Ocaml_compiler.native_shared_library_link_mldylib "%.mldylib" "%.cmxs");;

rule "ocaml: mllib & p.cmx* & p.o* -> p.cmxs & p.so"
~prods:["%.cmxs"; x_p_dll]
~dep:"%.mllib"
(Ocaml_compiler.native_profile_shared_library_link_mldylib "%.mllib" "%.cmxs");;

rule "ocaml: mllib & cmx* & o* -> cmxs & so"
~prods:["%.cmxs"; x_dll]
~dep:"%.mllib"
~doc:"Builds a .cmxs containing exactly the modules listed in the \
corresponding .mllib file. This rule triggers only when no .mldylib \
could be found."
(Ocaml_compiler.native_shared_library_link_mldylib "%.mllib" "%.cmxs");;

rule "ocaml: p.cmx & p.o -> p.cmxs & p.so"
~prods:["%.p.cmxs"; x_p_dll]
~deps:["%.p.cmx"; x_p_o]
Expand All @@ -376,9 +389,9 @@ rule "ocaml: p.cmxa & p.a -> p.cmxs & p.so"
rule "ocaml: cmx & o -> cmxs"
~prods:["%.cmxs"]
~deps:["%.cmx"; x_o]
~doc:"If you have not created a foo.mldylib file for a compilation unit \
foo.cmx, the target foo.cmxs will produce a .cmxs file containing \
exactly the .cmx.
~doc:"If you have not created a foo.mldylib or foo.mllib file for a \
compilation unit foo.cmx, the target foo.cmxs will produce a .cmxs \
file containing exactly the .cmx.
\
Note: this differs from the behavior of .cmxa targets \
Expand All @@ -397,7 +410,11 @@ rule "ocaml: cmxa & a -> cmxs & so"
~prods:["%.cmxs"; x_dll]
~deps:["%.cmxa"; x_a]
~doc:"This rule allows to build a .cmxs from a .cmxa, to avoid having \
to duplicate a .mllib file into a .mldylib."
to duplicate a .mllib file into a .mldylib.
\
Another way of avoiding duplication is by producing the .cmxs directly \
from the .mllib file, using the corresponding rule."
(Ocaml_compiler.native_shared_library_link ~tags:["linkall"] "%.cmxa" "%.cmxs");;

rule "ocaml dependencies ml"
Expand Down
19 changes: 19 additions & 0 deletions testsuite/internal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,23 @@ CAMLprim value hello_world(value unit)
]
~targets:("libtest.a", []) ();;

let () = test "MldylibOverridesMllib"
~description:"Check that the rule producing a cmxs from a .mllib only \
triggers if there is no .mldylib"
(*
GPR #132 (requested by issue #131) adds a new rule which allows producing a
.cmxs from a .mllib, where previously this was only possible by providing
a separate .mldylib file. This test ensures that the added rule behaves
conservatively, i.e. only triggers when no .mldylib file can be found.
*)
~options:[`no_ocamlfind; `no_plugin]
~matching:[_build [M.Not (M.f "bar.cmi")]]
~tree:[
T.f "foo.ml";
T.f "bar.ml";
T.f "mylib.mllib" ~content:"Foo\nBar";
T.f "mylib.mldylib" ~content:"Foo";
]
~targets:("mylib.cmxs", []) ();;

run ~root:"_test_internal";;

0 comments on commit 89888f2

Please sign in to comment.