···339339 (Gabriel Scherer, review by Nicolás Ojeda Bär and Florian Angeletti,
340340 report by Kate Deplaix)
341341342342+- #14244: Add -set-runtime-default option to the compiler, allowing the default
343343+ value of the Standard Library location used by the runtime to be overridden.
344344+ (Antonin Décimo, review by David Allsopp, Jonah Beckford, Damien Doligez and
345345+ Samuel Hym)
346346+342347- #14190: `ocaml -e` now also processes `-init` (previously it was ignored).
343348 (Emile Trotignon, review by David Allsopp and @ygrek)
344349
···229229 (fun i name -> compile_phrase (Cmm_helpers.predef_exception i name))
230230 Runtimedef.builtin_exceptions;
231231 if need_stdlib then begin
232232+ let standard_library_default =
233233+ Option.value ~default:Config.standard_library_default
234234+ !Clflags.standard_library_default in
232235 compile_phrase
233236 (Cmm_helpers.emit_global_string_constant
234234- "caml_standard_library_nat" Config.standard_library_default)
237237+ "caml_standard_library_nat" standard_library_default)
235238 end;
236239 compile_phrase (Cmm_helpers.global_table name_list);
237240 let globals_map = make_globals_map units_list ~crc_interfaces in
+10-2
bytecomp/bytelink.ml
···529529 already included in the runtime. *)
530530 if standalone && needs_stdlib then begin
531531 (* OCaml Standard Library Default location *)
532532- output_string outchan Config.standard_library_default;
532532+ let standard_library_default =
533533+ Option.value
534534+ ~default:Config.standard_library_default
535535+ !Clflags.standard_library_default
536536+ in
537537+ output_string outchan standard_library_default;
533538 Bytesections.record toc_writer OSLD
534539 end;
535540 (* The map of global identifiers *)
···639644 Buffer.contents b
640645641646let emit_runtime_standard_library_default outchan =
642642- let literal = c_string_literal_of_string Config.standard_library_default in
647647+ let stdlib =
648648+ let default = Config.standard_library_default in
649649+ Option.value ~default !Clflags.standard_library_default in
650650+ let literal = c_string_literal_of_string stdlib in
643651 Printf.fprintf outchan
644652 "const char_os * caml_runtime_standard_library_default = %s;\n" literal
645653
+13
driver/compenv.ml
···4343 prerr_endline err;
4444 raise (Exit_with_status 2)
45454646+let fatalf fmt = Printf.ksprintf fatal fmt
4747+4648let extract_output = function
4749 | Some s -> s
4850 | None ->
···778780 Printf.sprintf "Usage: %s <options> <files>\nOptions are:" program in
779781 Printf.printf "%s\n%s" help_msg err_msg;
780782 raise (Exit_with_status 0)
783783+784784+let parse_runtime_parameter opt =
785785+ let k, setting =
786786+ try Misc.cut_at opt '='
787787+ with Not_found ->
788788+ fatalf "-set-runtime-default: invalid runtime parameter '%s'. \
789789+ Expected <name>=<value>." opt in
790790+ if k = "standard_library_default" then
791791+ Clflags.standard_library_default := Some setting
792792+ else
793793+ fatalf "-set-runtime-default: unrecognized runtime parameter %s." k
+4
driver/compenv.mli
···2323val print_version_string : unit -> 'a
2424val print_standard_library : unit -> 'a
2525val fatal : string -> 'a
2626+val fatalf : ('a, unit, string, 'b) format4 -> 'a
26272728val first_ccopts : string list ref
2829val first_ppx : string list ref
···7980*)
8081val parse_arguments : ?current:(int ref)
8182 -> string array ref -> Arg.anon_fun -> string -> unit
8383+8484+(** Validate a single -set-runtime-default parameter specification. *)
8585+val parse_runtime_parameter : string -> unit
+8
driver/main_args.ml
···163163 "<dir> Add <dir> to the list of \"hidden\" include directories\n\
164164 \ (Like -I, but the program can not directly reference these dependencies)"
165165166166+let mk_set_runtime_default f =
167167+ "-set-runtime-default", Arg.String f, "<param>=<value> Set the default for \
168168+ runtime parameter <param> to <value> (see the manual for further details)"
169169+166170let mk_impl f =
167171 "-impl", Arg.String f, "<file> Compile <file> as a .ml file"
168172···893897 val _runtime_variant : string -> unit
894898 val _with_runtime : unit -> unit
895899 val _without_runtime : unit -> unit
900900+ val _set_runtime_default : string -> unit
896901 val _short_paths : unit -> unit
897902 val _thread : unit -> unit
898903 val _v : unit -> unit
···11211126 mk_without_runtime F._without_runtime;
11221127 mk_safe_string;
11231128 mk_safer_matching F._safer_matching;
11291129+ mk_set_runtime_default F._set_runtime_default;
11241130 mk_short_paths F._short_paths;
11251131 mk_strict_sequence F._strict_sequence;
11261132 mk_no_strict_sequence F._no_strict_sequence;
···13461352 mk_S F._S;
13471353 mk_safe_string;
13481354 mk_safer_matching F._safer_matching;
13551355+ mk_set_runtime_default F._set_runtime_default;
13491356 mk_shared F._shared;
13501357 mk_short_paths F._short_paths;
13511358 mk_strict_sequence F._strict_sequence;
···18391846 let _plugin _p = plugin := true
18401847 let _pp s = preprocessor := (Some s)
18411848 let _runtime_variant s = runtime_variant := s
18491849+ let _set_runtime_default s = Compenv.parse_runtime_parameter s
18421850 let _stop_after pass =
18431851 let module P = Compiler_pass in
18441852 match P.of_string pass with
+1
driver/main_args.mli
···119119 val _runtime_variant : string -> unit
120120 val _with_runtime : unit -> unit
121121 val _without_runtime : unit -> unit
122122+ val _set_runtime_default : string -> unit
122123 val _short_paths : unit -> unit
123124 val _thread : unit -> unit
124125 val _v : unit -> unit
+1-1
driver/maindriver.ml
···6262 "Please specify at most one of -pack, -a, -c, -output-obj";
6363 | Some ((P.Parsing | P.Typing | P.Lambda) as p) ->
6464 assert (P.is_compilation_pass p);
6565- Printf.ksprintf Compenv.fatal
6565+ Compenv.fatalf
6666 "Options -i and -stop-after (%s) \
6767 are incompatible with -pack, -a, -output-obj"
6868 (String.concat "|"
+1-1
driver/optmaindriver.ml
···7878 -output-obj";
7979 | Some ((P.Parsing | P.Typing | P.Lambda | P.Scheduling | P.Emit) as p) ->
8080 assert (P.is_compilation_pass p);
8181- Printf.ksprintf Compenv.fatal
8181+ Compenv.fatalf
8282 "Options -i and -stop-after (%s) \
8383 are incompatible with -pack, -a, -shared, -output-obj"
8484 (String.concat "|"
+9
man/ocamlc.1
···674674wrongly assumed to be exhaustive. This only impacts GADT and
675675polymorphic variant compilation.
676676.TP
677677+.BI \-set\-runtime\-default " setting=value"
678678+When linking an executable, override the default value for a runtime setting.
679679+The only currently supported setting is:
680680+681681+.B standard_library_default
682682+Specifies the default location used by the executable to locate the Standard
683683+Library. By default, this is the absolute path to the Standard Library the
684684+compiler itself was configured with.
685685+.TP
677686.B \-short\-paths
678687When a type is visible under several module-paths, use the shortest
679688one when printing the type's name in inferred interfaces and error and
+9
man/ocamlopt.1
···593593supported passes are:
594594.BR scheduling .
595595.TP
596596+.BI \-set\-runtime\-default " setting=value"
597597+When linking an executable, override the default value for a runtime setting.
598598+The only currently supported setting is:
599599+600600+.B standard_library_default
601601+Specifies the default location used by the executable to locate the Standard
602602+Library. By default, this is the absolute path to the Standard Library the
603603+compiler itself was configured with.
604604+.TP
596605.B \-shared
597606Build a plugin (usually .cmxs) that can be dynamically loaded with
598607the
+11
manual/src/cmds/unified-options.etex
···711711).
712712}%nat
713713714714+\notop{%
715715+\item["-set-runtime-default" \var{name=value}]
716716+When linking an executable, override the default value for a runtime setting.
717717+The currently supported settings are:
718718+\begin{description}
719719+ \item["standard_library_default"] Specifies the default location used by the
720720+ executable to locate the Standard Library. By default, this is the absolute
721721+ path to the Standard Library the compiler itself was configured with.
722722+\end{description}
723723+}%notop
724724+714725\nat{%
715726\item["-shared"]
716727Build a plugin (usually ".cmxs") that can be dynamically loaded with