diff --git a/otherlibs/build-info/test/run.t b/otherlibs/build-info/test/run.t index cb80f04a2a91..a78f1a86134b 100644 --- a/otherlibs/build-info/test/run.t +++ b/otherlibs/build-info/test/run.t @@ -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 diff --git a/src/dune_rules/link_time_code_gen.ml b/src/dune_rules/link_time_code_gen.ml index af04506b842c..16a7fb63e181 100644 --- a/src/dune_rules/link_time_code_gen.ml +++ b/src/dune_rules/link_time_code_gen.ml @@ -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 @@ -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)));