diff --git a/src/dune/exe.ml b/src/dune/exe.ml index d989e3fbc82..f6fc4f6d1f9 100644 --- a/src/dune/exe.ml +++ b/src/dune/exe.ml @@ -12,6 +12,12 @@ module Program = struct } end +let custom_or_output_complete_exe ctx = + if Ocaml_version.supports_output_complete_exe ctx.Context.version then + "-output-complete-exe" + else + "-custom" + module Linkage = struct type t = { mode : Mode.t @@ -23,11 +29,15 @@ module Linkage = struct let native = { mode = Native; ext = ".exe"; flags = [] } - let custom = { mode = Byte; ext = ".exe"; flags = [ "-custom" ] } + let custom context = + { mode = Byte + ; ext = ".exe" + ; flags = [ custom_or_output_complete_exe context ] + } let native_or_custom (context : Context.t) = match context.ocamlopt with - | None -> custom + | None -> custom context | Some _ -> native let js = { mode = Byte; ext = ".bc.js"; flags = [] } @@ -83,7 +93,7 @@ module Linkage = struct | Js -> [] | Exe -> ( match (wanted_mode, real_mode) with - | Native, Byte -> [ "-custom" ] + | Native, Byte -> [ custom_or_output_complete_exe ctx ] | _ -> [] ) | Object -> o_flags | Shared_object -> ( diff --git a/src/dune/exe.mli b/src/dune/exe.mli index 3a8012c1da4..f2cad9954ed 100644 --- a/src/dune/exe.mli +++ b/src/dune/exe.mli @@ -18,8 +18,9 @@ module Linkage : sig (** Native compilation, extension [.exe] *) val native : t - (** Byte compilation, link with [-custom], extension [.exe] *) - val custom : t + (** Byte compilation, link with [-custom] or [-output-complete-exe], + extension [.exe] *) + val custom : Context.t -> t (** [native] if supported, [custom] if not *) val native_or_custom : Context.t -> t diff --git a/src/dune/exe_rules.ml b/src/dune/exe_rules.ml index d7aba501174..59fec846488 100644 --- a/src/dune/exe_rules.ml +++ b/src/dune/exe_rules.ml @@ -73,7 +73,7 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info && (not (L.Set.mem exes.modes L.native)) && not (L.Set.mem exes.modes L.exe) then - Exe.Linkage.custom :: l + Exe.Linkage.custom ctx :: l else l in diff --git a/src/dune/ocaml_version.ml b/src/dune/ocaml_version.ml index 8c9ec4f8f83..cd31c77bbed 100644 --- a/src/dune/ocaml_version.ml +++ b/src/dune/ocaml_version.ml @@ -31,3 +31,5 @@ let ooi_supports_no_approx version = version >= (4, 05, 0) let ooi_supports_no_code version = version >= (4, 05, 0) let supports_let_syntax version = version >= (4, 08, 0) + +let supports_output_complete_exe version = version >= (4, 10, 0) diff --git a/src/dune/ocaml_version.mli b/src/dune/ocaml_version.mli index 7d50a1519a1..ef293cd71b5 100644 --- a/src/dune/ocaml_version.mli +++ b/src/dune/ocaml_version.mli @@ -47,3 +47,6 @@ val ooi_supports_no_code : t -> bool (** Whether the language supports custom let operators *) val supports_let_syntax : t -> bool + +(** Does this support [-output-complete-exe]? *) +val supports_output_complete_exe : t -> bool diff --git a/src/dune/toplevel.ml b/src/dune/toplevel.ml index 8f8e114656e..992b153cd59 100644 --- a/src/dune/toplevel.ml +++ b/src/dune/toplevel.ml @@ -80,7 +80,7 @@ let setup_module_rules t = Super_context.add_rule sctx ~dir main_ml let setup_rules t = - let linkage = Exe.Linkage.custom in + let linkage = Exe.Linkage.custom (Compilation_context.context t.cctx) in let program = Source.program t.source in let sctx = Compilation_context.super_context t.cctx in Exe.build_and_link t.cctx ~program ~linkages:[ linkage ]