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

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Apr 16, 2022

Updates ocamlbuild for compatibility with the changes proposed in ocaml/ocaml#11198 in order to silence the alert displayed by that PR.

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"?)

@hhugo
Copy link
Collaborator

hhugo commented May 17, 2024

This can be closed, fixed in #328

@gasche gasche closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants