Skip to content

Fix linking of .cmxs targets that link stubs. #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/ocaml_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ let forpack_flags arg tags =
Ocaml_arch.forpack_flags_of_pathname arg
else N

let include_flags_for_deps deps =
let dirnames = List.union [] (List.map Pathname.dirname deps) in
let include_flags = List.fold_right ocaml_add_include_flag dirnames [] in
S include_flags

let ocamlc_c tags arg out =
let tags = tags++"ocaml"++"byte" in
Cmd (S [!Options.ocamlc; A"-c"; T(tags++"compile");
ocaml_ppflags tags; ocaml_include_flags arg; A"-o"; Px out; P arg])

let ocamlc_link flag tags deps out =
Cmd (S [!Options.ocamlc; flag; T tags;
atomize_paths deps; A"-o"; Px out])
include_flags_for_deps deps; atomize_paths deps; A"-o"; Px out])

let ocamlc_link_lib = ocamlc_link (A"-a")
let ocamlc_link_prog = ocamlc_link N
Expand Down Expand Up @@ -70,19 +75,17 @@ let ocamlopt_c tags arg out =

let ocamlopt_link flag tags deps out =
Cmd (S [!Options.ocamlopt; flag; forpack_flags out tags; T tags;
atomize_paths deps; A"-o"; Px out])
include_flags_for_deps deps; atomize_paths deps; A"-o"; Px out])

let ocamlopt_link_lib = ocamlopt_link (A"-a")
let ocamlopt_link_shared_lib = ocamlopt_link (A"-shared")
let ocamlopt_link_prog = ocamlopt_link N

let ocamlopt_p tags deps out =
let dirnames = List.union [] (List.map Pathname.dirname deps) in
let include_flags = List.fold_right ocaml_add_include_flag dirnames [] in
let mli = Pathname.update_extensions "mli" out in
let cmd =
S [!Options.ocamlopt; A"-pack"; forpack_flags out tags; T tags;
S include_flags; atomize_paths deps;
include_flags_for_deps deps; atomize_paths deps;
A"-o"; Px out] in
if (*FIXME true ||*) Pathname.exists mli then Cmd cmd
else
Expand Down
6 changes: 3 additions & 3 deletions src/ocaml_specific.ml
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ rule "ocaml: cmx & o -> cmxa & a"

rule "ocaml: p.cmxa & p.a -> p.cmxs & p.so"
~prods:["%.p.cmxs"; x_p_dll]
~deps:["%.p.cmxa"; x_p_a]
~deps:["%.p.cmxa"]
(Ocaml_compiler.native_shared_library_link ~tags:["profile";"linkall"] "%.p.cmxa" "%.p.cmxs");;

rule "ocaml: cmxa & a -> cmxs & so"
rule "ocaml: cmxa -> cmxs & so"
~prods:["%.cmxs"; x_dll]
~deps:["%.cmxa"; x_a]
~deps:["%.cmxa"]
~doc:"This rule allows to build a .cmxs from a .cmxa, to avoid having \
to duplicate a .mllib file into a .mldylib."
(Ocaml_compiler.native_shared_library_link ~tags:["linkall"] "%.cmxa" "%.cmxs");;
Expand Down
26 changes: 26 additions & 0 deletions testsuite/internal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,32 @@ let () = test "OutputShared"
T.f "_tags" ~content:"<*.so>: runtime_variant(_pic)"]
~targets:("hello.byte.so",["hello.native.so"]) ();;

let () = test "CmxsStubLink"
~options:[`no_ocamlfind]
~description:".cmxs link rules pass correct -I flags"
~tree:[T.d "src" [
T.f "foo_stubs.c" ~content:"";
T.f "libfoo_stubs.clib" ~content:"foo_stubs.o";
T.f "foo.ml" ~content:"";
];
T.f "_tags" ~content:"
<src/foo.{cma,cmxa}> : record_foo_stubs
<src/foo.cmxs> : link_foo_stubs";
T.f "myocamlbuild.ml" ~content:"
open Ocamlbuild_plugin
let () =
dispatch begin function
| After_rules ->
dep [\"record_foo_stubs\"] [\"src/libfoo_stubs.a\"];
flag_and_dep
[\"link\"; \"ocaml\"; \"link_foo_stubs\"] (P \"src/libfoo_stubs.a\");
flag [\"library\"; \"ocaml\"; \"record_foo_stubs\"]
(S ([A \"-cclib\"; A \"-lfoo_stubs\"]));
| _ -> ()
end
"]
~targets:("src/foo.cmxs",[]) ();;

let () = test "StrictSequenceFlag"
~options:[`no_ocamlfind; `quiet]
~description:"strict_sequence tag"
Expand Down