Skip to content

Commit

Permalink
fix(duild-info): reapply flambda fix from ocaml#3599 removed in ocaml…
Browse files Browse the repository at this point in the history
…#5049

With flambda, Sys.opaque_identity is needed around the placeholder
string or else flambda is able to compile it away. This prevents the
rewriting done by e.g. `dune install` from working.

Signed-off-by: Josh Berdine <[email protected]>
  • Loading branch information
jberdine committed Aug 20, 2022
1 parent 5226892 commit 0bdea22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions otherlibs/build-info/test/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ Check what the generated build info module looks like:
None
[@@inline never]

let p1 = eval "%%DUNE_PLACEHOLDER:64:vcs-describe:1:a%%%%%%%%%%%%%%%%%%%%%%%%%%"
let p2 = eval "%%DUNE_PLACEHOLDER:64:vcs-describe:1:b%%%%%%%%%%%%%%%%%%%%%%%%%%"
let p0 = eval "%%DUNE_PLACEHOLDER:64:vcs-describe:1:c%%%%%%%%%%%%%%%%%%%%%%%%%%"
let p1 = eval (Sys.opaque_identity "%%DUNE_PLACEHOLDER:64:vcs-describe:1:a%%%%%%%%%%%%%%%%%%%%%%%%%%")
let p2 = eval (Sys.opaque_identity "%%DUNE_PLACEHOLDER:64:vcs-describe:1:b%%%%%%%%%%%%%%%%%%%%%%%%%%")
let p0 = eval (Sys.opaque_identity "%%DUNE_PLACEHOLDER:64:vcs-describe:1:c%%%%%%%%%%%%%%%%%%%%%%%%%%")

let version = p0

Expand Down
9 changes: 8 additions & 1 deletion src/dune_rules/link_time_code_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ let build_info_code cctx ~libs ~api_version =
((Lib.name lib, v) :: libs, placeholders))
in
let libs = List.rev libs in
let context = CC.context cctx in
let ocaml_version = Ocaml.Version.of_ocaml_config context.ocaml_config in
let buf = Buffer.create 1024 in
(* Parse the replacement format described in [artifact_substitution.ml]. *)
pr buf
Expand All @@ -167,7 +169,12 @@ let build_info_code cctx ~libs ~api_version =
None
[@@inline never]
|ocaml};
let fmt_eval : _ format6 = "let %s = eval %S" in
let fmt_eval : _ format6 =
if Ocaml.Version.has_sys_opaque_identity ocaml_version then
"let %s = eval (Sys.opaque_identity %S)"
else
"let %s = eval %S"
in
Path.Source.Map.iteri placeholders ~f:(fun path var ->
pr buf fmt_eval var
(Artifact_substitution.encode ~min_len:64 (Vcs_describe path)));
Expand Down

0 comments on commit 0bdea22

Please sign in to comment.