Skip to content
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

Support new locations of unix, str and dynlink #317

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 13 additions & 3 deletions src/ocaml_specific.ml
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,19 @@ camlp4_flags' ["camlp4orr", S[A"camlp4of"; A"-parser"; A"reloaded"];

flag ["ocaml"; "pp"; "camlp4:no_quot"] (A"-no_quot");;

ocaml_lib ~extern:true "dynlink";;
ocaml_lib ~extern:true "unix";;
ocaml_lib ~extern:true "str";;
let ocaml_otherlibs_lib =
match split_ocaml_version with
| Some (major, minor, _, _) when (major, minor) >= (5, 0) ->
fun name ->
let dir = "+" ^ name in
ocaml_lib ~extern:true ~dir name;
flag ["ocaml"; "compile"; "use_" ^ name] (S[A"-I"; A dir])
| _ ->
fun name -> ocaml_lib ~extern:true name;;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ocaml_otherlibs_lib "foo" not something you can already do with ocaml_lib ~extern:true ~dir:"+foo" "foo"? I have the impression that the latter already adds ocaml, compile, use_foo: -I +foo .

Documentation:

(** [ocaml_lib <options> library_pathname] Declare an ocaml library.
This informs ocamlbuild and produce tags to use the library;
they are named by default use_#{library_name}.
Example: [ocaml_lib "foo/bar"] will setup the tag use_bar.
At link time it will include:
foo/bar.cma or foo/bar.cmxa
@param dir supply the [~dir:"boo"] option to add '-I boo'
at link and compile time.
@param extern use ~extern:true for non-ocamlbuild handled libraries.
Set this to add libraries whose sources are not in your project.
@param byte use ~byte:false to disable byte mode.
@param native use ~native:false to disable native mode.
@param tag_name Use ~tag_name:"usebar" to override the default
tag name. *)
val ocaml_lib :

Implementation:

let ocaml_lib ?(extern=false) ?(byte=true) ?(native=true) ?dir ?tag_name libpath =
let add_dir x =
match dir with
| Some dir -> S[A"-I"; P dir; x]
| None -> x
in
let tag_name =
match tag_name with
| Some x -> x
| None -> "use_" ^ Pathname.basename libpath
in
let flag_and_dep tags lib =
flag tags (add_dir (A lib));
if not extern then dep tags [lib] (* cannot happen? *)
in
Hashtbl.replace info_libraries tag_name (libpath, extern);
(* adding [tag_name] to [info_libraries] will make this tag
affect include-dir lookups, so it is used even if not
mentioned explicitly in any rule. *)
Flags.mark_tag_used tag_name;
if extern then begin
if byte then
flag_and_dep ["ocaml"; tag_name; "link"; "byte"] (libpath^".cma");
if native then
flag_and_dep ["ocaml"; tag_name; "link"; "native"] (libpath^".cmxa");
end else begin
if not byte && not native then
invalid_arg "ocaml_lib: ~byte:false or ~native:false only works with ~extern:true";
end;
match dir with
| None -> ()
| Some dir ->
List.iter
(fun x -> flag ["ocaml"; tag_name; x] (S[A"-I"; P dir]))
["compile"; "doc"; "infer_interface"]

Copy link
Member

@gasche gasche Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Maybe one needs ocaml_lib ~extern:true ~dir:"+foo" "foo/foo"?)


ocaml_otherlibs_lib "dynlink";;
ocaml_otherlibs_lib "unix";;
ocaml_otherlibs_lib "str";;
ocaml_lib ~extern:true "bigarray";;
ocaml_lib ~extern:true "nums";;
ocaml_lib ~extern:true "dbm";;
Expand Down
10 changes: 8 additions & 2 deletions src/plugin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ module Make(U:sig end) =
let unix_lib =
if use_ocamlfind_pkgs then `Package "unix"
else if use_light_mode then `Nothing
else `Lib "unix" in
else let dir = match split_ocaml_version with
| Some (major, minor, _, _) when (major, minor) >= (5, 0) ->
Some "unix"
| _ -> None
in
`Lib ("unix", dir) in

let ocamlbuild_lib =
if use_ocamlfind_pkgs then `Package "ocamlbuild"
Expand All @@ -198,7 +203,8 @@ module Make(U:sig end) =
let spec = function
| `Nothing -> N
| `Package pkg -> S[A "-package"; A pkg]
| `Lib lib -> P (lib -.- cma)
| `Lib (lib, Some dir) -> S[A "-I"; A ("+" ^ dir); P (lib -.- cma)]
| `Lib (lib, None) -> P (lib -.- cma)
| `Local_lib llib -> S [A "-I"; A dir; P (in_dir (llib -.- cma))]
| `Local_mod lmod -> P (in_dir (lmod -.- cmo)) in

Expand Down