Skip to content

Commit 89888f2

Browse files
author
Armaël Guéneau
committed
Add a .mllib -> .cmxs rule
1 parent 09d4cd0 commit 89888f2

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

Changes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ NEXT_RELEASE:
2626
- #127: install ocamlbuild's man pages, missing since 4.02
2727
(Gabriel Scherer)
2828

29+
- #132: add a rule producing .cmxs from .mllib files.
30+
Previously, .mllib files would only produce .cm{x,}a files, and .cmxs were
31+
only produced by a separate (and in most cases redundant) .mldylib file.
32+
This rule allows to produce .cmxs from .mllib files; .mldylib files
33+
still take precedence when they exist.
34+
(Armaël Guéneau, requested by Daniel Bünzli)
35+
2936
0.9.3 (6 Oct 2016):
3037
-------------------
3138

src/ocaml_specific.ml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ rule "ocaml: mllib & cmx* & o* -> cmxa & a"
334334
as the .cma rule above. Note that whereas bytecode .cma can \
335335
be used both for static and dynamic linking, .cmxa only support \
336336
static linking. For an archive usable with Dynlink, \
337-
see the rule producing a .cmxs from a .mldylib."
337+
see the rules producing a .cmxs from a .mllib or a .mldylib."
338338
(Ocaml_compiler.native_library_link_mllib "%.mllib" "%.cmxa");;
339339

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

366+
rule "ocaml: mllib & p.cmx* & p.o* -> p.cmxs & p.so"
367+
~prods:["%.cmxs"; x_p_dll]
368+
~dep:"%.mllib"
369+
(Ocaml_compiler.native_profile_shared_library_link_mldylib "%.mllib" "%.cmxs");;
370+
371+
rule "ocaml: mllib & cmx* & o* -> cmxs & so"
372+
~prods:["%.cmxs"; x_dll]
373+
~dep:"%.mllib"
374+
~doc:"Builds a .cmxs containing exactly the modules listed in the \
375+
corresponding .mllib file. This rule triggers only when no .mldylib \
376+
could be found."
377+
(Ocaml_compiler.native_shared_library_link_mldylib "%.mllib" "%.cmxs");;
378+
366379
rule "ocaml: p.cmx & p.o -> p.cmxs & p.so"
367380
~prods:["%.p.cmxs"; x_p_dll]
368381
~deps:["%.p.cmx"; x_p_o]
@@ -376,9 +389,9 @@ rule "ocaml: p.cmxa & p.a -> p.cmxs & p.so"
376389
rule "ocaml: cmx & o -> cmxs"
377390
~prods:["%.cmxs"]
378391
~deps:["%.cmx"; x_o]
379-
~doc:"If you have not created a foo.mldylib file for a compilation unit \
380-
foo.cmx, the target foo.cmxs will produce a .cmxs file containing \
381-
exactly the .cmx.
392+
~doc:"If you have not created a foo.mldylib or foo.mllib file for a \
393+
compilation unit foo.cmx, the target foo.cmxs will produce a .cmxs \
394+
file containing exactly the .cmx.
382395
383396
\
384397
Note: this differs from the behavior of .cmxa targets \
@@ -397,7 +410,11 @@ rule "ocaml: cmxa & a -> cmxs & so"
397410
~prods:["%.cmxs"; x_dll]
398411
~deps:["%.cmxa"; x_a]
399412
~doc:"This rule allows to build a .cmxs from a .cmxa, to avoid having \
400-
to duplicate a .mllib file into a .mldylib."
413+
to duplicate a .mllib file into a .mldylib.
414+
415+
\
416+
Another way of avoiding duplication is by producing the .cmxs directly \
417+
from the .mllib file, using the corresponding rule."
401418
(Ocaml_compiler.native_shared_library_link ~tags:["linkall"] "%.cmxa" "%.cmxs");;
402419

403420
rule "ocaml dependencies ml"

testsuite/internal.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,23 @@ CAMLprim value hello_world(value unit)
380380
]
381381
~targets:("libtest.a", []) ();;
382382

383+
let () = test "MldylibOverridesMllib"
384+
~description:"Check that the rule producing a cmxs from a .mllib only \
385+
triggers if there is no .mldylib"
386+
(*
387+
GPR #132 (requested by issue #131) adds a new rule which allows producing a
388+
.cmxs from a .mllib, where previously this was only possible by providing
389+
a separate .mldylib file. This test ensures that the added rule behaves
390+
conservatively, i.e. only triggers when no .mldylib file can be found.
391+
*)
392+
~options:[`no_ocamlfind; `no_plugin]
393+
~matching:[_build [M.Not (M.f "bar.cmi")]]
394+
~tree:[
395+
T.f "foo.ml";
396+
T.f "bar.ml";
397+
T.f "mylib.mllib" ~content:"Foo\nBar";
398+
T.f "mylib.mldylib" ~content:"Foo";
399+
]
400+
~targets:("mylib.cmxs", []) ();;
401+
383402
run ~root:"_test_internal";;

0 commit comments

Comments
 (0)