diff --git a/doc/manual.org b/doc/manual.org index d0201c83..74da2520 100644 --- a/doc/manual.org +++ b/doc/manual.org @@ -361,6 +361,12 @@ the current directory, you only need to list the entry point in and =.bc= is a bytecode executable which requires =ocamlrun= to run. +Note that in case native compilation is not available, =.exe= +will in fact be a custom byte-code executable. Custom in the sense of +=ocamlc -custom=, meaning that it is a native executable that embeds +the =ocamlrun= virtual machine as well as the byte code. As such you +can always rely on =.exe= begin available. + == are: - =(libraries ())= is the same as the diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 21d9f7a4..04467dd4 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -1087,30 +1087,35 @@ module Gen(P : Params) = struct +-----------------------------------------------------------------+ *) let build_exe ~flags ~dir ~requires ~name ~mode ~modules ~dep_graph ~link_flags = - Option.iter (Mode.compiler mode ctx) ~f:(fun compiler -> - let dep_graph = Ml_kind.Dict.get dep_graph Impl in - let exe = Path.relative dir (name ^ Mode.exe_ext mode) in - add_rule - (Build.fanout - (requires - >>> Build.dyn_paths (Build.arr (Lib.archive_files ~mode ~ext_lib:ctx.ext_lib))) - (dep_graph - >>> Build.arr (fun dep_graph -> - names_to_top_closed_cm_files - ~dir - ~dep_graph - ~modules - ~mode - [String.capitalize name])) - >>> - Build.run - (Dep compiler) - [ Ocaml_flags.get flags mode - ; A "-o"; Target exe - ; As link_flags - ; Dyn (fun (libs, _) -> Lib.link_flags libs ~mode) - ; Dyn (fun (_, cm_files) -> Deps cm_files) - ])) + let ext_ext = Mode.exe_ext mode in + let mode, link_flags, compiler = + match Mode.compiler mode ctx with + | Some compiler -> (mode, link_flags, compiler) + | None -> (Byte, "-custom" :: link_flags, ctx.ocamlc) + in + let dep_graph = Ml_kind.Dict.get dep_graph Impl in + let exe = Path.relative dir (name ^ exe_ext) in + add_rule + (Build.fanout + (requires + >>> Build.dyn_paths (Build.arr (Lib.archive_files ~mode ~ext_lib:ctx.ext_lib))) + (dep_graph + >>> Build.arr (fun dep_graph -> + names_to_top_closed_cm_files + ~dir + ~dep_graph + ~modules + ~mode + [String.capitalize name])) + >>> + Build.run + (Dep compiler) + [ Ocaml_flags.get flags mode + ; A "-o"; Target exe + ; As link_flags + ; Dyn (fun (libs, _) -> Lib.link_flags libs ~mode) + ; Dyn (fun (_, cm_files) -> Deps cm_files) + ]) let executables_rules (exes : Executables.t) ~dir ~all_modules = let dep_kind = Build.Required in @@ -1151,7 +1156,6 @@ module Gen(P : Params) = struct build_exe ~flags ~dir ~requires ~name ~mode ~modules ~dep_graph ~link_flags:exes.link_flags)) - (* +-----------------------------------------------------------------+ | User actions | +-----------------------------------------------------------------+ *)