-
Notifications
You must be signed in to change notification settings - Fork 33
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
Rewrite gen_link_flags
in OCaml
#1189
Changes from 7 commits
55a2928
1b27d4f
9d2b767
a1c50d3
b11fa2b
8eaf2e0
dd336d3
1370591
400e8ff
2985a27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
(documentation | ||
(package alt-ergo)) | ||
|
||
(executable | ||
(name gen_link_flags) | ||
(libraries unix fmt stdcompat cmdliner) | ||
(modules gen_link_flags) | ||
(promote (until-clean))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be no need to promote this executable, let's not clutter the source directory. |
||
|
||
(rule | ||
(with-stdout-to link_flags.dune | ||
(run ./gen-link-flags.sh %{env:LINK_MODE=dynamic} %{ocaml-config:system}))) | ||
(target link_flags.dune) | ||
(deps (:gen gen_link_flags.exe)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is not needed and you can just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My first attempt was:
But it does not work. It works if I add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right,
|
||
(action | ||
(with-stdout-to link_flags.dune | ||
(run %{gen} %{env:LINK_MODE=dynamic} %{ocaml-config:system})))) | ||
|
||
(executable | ||
(name Main_text) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
let pkgconfig lib archive = | ||
let cmd = Fmt.str "pkg-config %s --variable libdir" lib in | ||
let output = | ||
Unix.open_process_in cmd | ||
|> Stdcompat.In_channel.input_line | ||
|> Option.get | ||
in | ||
Fmt.str "%s/%s" output archive | ||
|
||
let pp_lib ppf s = Fmt.pf ppf "-cclib %s" s | ||
|
||
let () = | ||
let mixed_flags = ["-noautolink"] in | ||
(* Note: for OCaml 5, use -lcamlstrnat and -lunixnat and mind zlib | ||
https://github.com/ocaml/ocaml/issues/12562 *) | ||
let mixed_cclib = [ | ||
"-lstdcompat_stubs"; | ||
"-lcamlzip"; | ||
"-lzarith"; | ||
"-lcamlstr"; | ||
"-lunix"; | ||
"-lz" | ||
] | ||
in | ||
let libs = ["gmp"] in | ||
let link_mode = Sys.argv.(1) and os = Sys.argv.(2) in | ||
let flags, cclib = | ||
match link_mode, os with | ||
| "dynamic", _ -> [], [] | ||
| "static", "linux" -> [], ["-static"; "-no-pie"] | ||
| "mixed", "linux" -> | ||
let cclib = mixed_cclib @ List.map (fun s -> "-l" ^ s) libs in | ||
mixed_flags, "-Wl,-Bdynamic" :: "-Wl,-Bstatic" :: cclib | ||
| "mixed", "macosx" -> | ||
let cclib = mixed_cclib @ | ||
List.map | ||
(fun lib -> | ||
let archive = | ||
if Stdcompat.String.starts_with | ||
~prefix:"lib" lib then | ||
Fmt.str "%s.a" lib | ||
else | ||
Fmt.str "lib%s.a" lib | ||
in | ||
pkgconfig lib archive | ||
) libs | ||
in | ||
mixed_flags, cclib | ||
| _ -> Fmt.invalid_arg "unsupported mode %s and OS %s" link_mode os | ||
in | ||
Fmt.pr "@[(-linkall %a %a)@]" | ||
Fmt.(list ~sep:sp string) flags | ||
Fmt.(list ~sep:sp pp_lib) cclib; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like we use
cmdliner
, it should not be a dependency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote a previous version with
cmdliner
but it was a bit over-engineering. I forgot to remove the dependency.