diff --git a/CHANGES.md b/CHANGES.md index bb62986e4c8..78790122655 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ Unreleased ---------- +- Add a `%{toolchain}` expansion variable (#4899, fixes #3949, @rgrinberg) + - Include dependencies of executables when creating toplevels (either `dune top` or `dune utop`) (#4882, fixes #4872, @Gopiancode) diff --git a/src/dune_engine/pform.ml b/src/dune_engine/pform.ml index dd356cd7558..376c0ed90c6 100644 --- a/src/dune_engine/pform.ml +++ b/src/dune_engine/pform.ml @@ -44,6 +44,7 @@ module Var = struct | Test | Corrected_suffix | Inline_tests + | Toolchain let compare : t -> t -> Ordering.t = Poly.compare @@ -94,6 +95,7 @@ module Var = struct | Test -> "Test" | Corrected_suffix -> "Corrected_suffix" | Inline_tests -> "Inline_tests" + | Toolchain -> "Toolchain" in Dyn.Variant (cstr, []) end @@ -285,6 +287,7 @@ let encode_to_latest_dune_lang_version t = | Test -> Some "test" | Corrected_suffix -> Some "corrected-suffix" | Inline_tests -> Some "inline_tests" + | Toolchain -> Some "toolchain" with | None -> Pform_was_deleted | Some name -> Success { name; payload = None }) @@ -469,6 +472,7 @@ module Env = struct ; ("input-file", since ~version:(1, 0) Var.Input_file) ; ("corrected-suffix", No_info Corrected_suffix) ; ("inline_tests", No_info Inline_tests) + ; ("toolchains", since ~version:(3, 0) Var.Toolchain) ] in String.Map.of_list_exn (List.concat [ lowercased; uppercased; other ]) diff --git a/src/dune_engine/pform.mli b/src/dune_engine/pform.mli index e59ff7db8d6..5ee89094c79 100644 --- a/src/dune_engine/pform.mli +++ b/src/dune_engine/pform.mli @@ -44,6 +44,7 @@ module Var : sig | Test | Corrected_suffix | Inline_tests + | Toolchain val compare : t -> t -> Ordering.t diff --git a/src/dune_rules/expander.ml b/src/dune_rules/expander.ml index c662ab73388..0a3eef11f0e 100644 --- a/src/dune_rules/expander.ml +++ b/src/dune_rules/expander.ml @@ -371,7 +371,16 @@ let expand_pform_gen ~(context : Context.t) ~bindings ~dir ~source | Ccomp_type -> static (string - (Ocaml_config.Ccomp_type.to_string context.lib_config.ccomp_type))) + (Ocaml_config.Ccomp_type.to_string context.lib_config.ccomp_type)) + | Toolchain -> + static + (string + (match context.findlib_toolchain with + | Some toolchain -> Context_name.to_string toolchain + | None -> + let loc = Dune_lang.Template.Pform.loc source in + User_error.raise ~loc + [ Pp.text "No toolchain defined for this context" ]))) | Macro (macro, s) -> ( match macro with | Ocaml_config ->