Skip to content

Commit 010d94c

Browse files
authored
Merge pull request #2309 from TheLortex/runtime-variant-path
Add -noruntime option
2 parents 0712982 + 198d650 commit 010d94c

15 files changed

Lines changed: 73 additions & 6 deletions

File tree

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ OCaml 4.09.0
128128
(Jules Aguillon, with help from Armaël Guéneau,
129129
review by Gabriel Scherer and Florian Angeletti)
130130

131+
- #2309: New options -with-runtime and -without-runtime in ocamlopt/ocamlc
132+
that control the inclusion of the runtime system in the generated program.
133+
(Lucas Pluvinage, review by Daniel Bünzli, Damien Doligez, David Allsopp
134+
and Florian Angeletti)
135+
131136
- #2314: Remove support for gprof profiling.
132137
(Mark Shinwell, review by Xavier Clerc and Stephen Dolan)
133138

asmcomp/asmlink.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ let add_ccobjs origin l =
111111
let runtime_lib () =
112112
let libname = "libasmrun" ^ !Clflags.runtime_variant ^ ext_lib in
113113
try
114-
if !Clflags.nopervasives then []
114+
if !Clflags.nopervasives || not !Clflags.with_runtime then []
115115
else [ Load_path.find libname ]
116116
with Not_found ->
117117
raise(Error(File_not_found libname))

bytecomp/bytelink.ml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,15 @@ let link_bytecode ?final_name tolink exec_name standalone =
304304
raise (Error (Wrong_object_name exec_name));
305305
| _ -> ()) tolink;
306306
Misc.remove_file exec_name; (* avoid permission problems, cf PR#8354 *)
307+
let outperm = if !Clflags.with_runtime then 0o777 else 0o666 in
307308
let outchan =
308309
open_out_gen [Open_wronly; Open_trunc; Open_creat; Open_binary]
309-
0o777 exec_name in
310+
outperm exec_name in
310311
Misc.try_finally
311312
~always:(fun () -> close_out outchan)
312313
~exceptionally:(fun () -> remove_file exec_name)
313314
(fun () ->
314-
if standalone then begin
315+
if standalone && !Clflags.with_runtime then begin
315316
(* Copy the header *)
316317
let header =
317318
if String.length !Clflags.use_runtime > 0
@@ -327,7 +328,8 @@ let link_bytecode ?final_name tolink exec_name standalone =
327328
end;
328329
Bytesections.init_record outchan;
329330
(* The path to the bytecode interpreter (in use_runtime mode) *)
330-
if String.length !Clflags.use_runtime > 0 then begin
331+
if String.length !Clflags.use_runtime > 0 && !Clflags.with_runtime then
332+
begin
331333
let runtime = make_absolute !Clflags.use_runtime in
332334
let runtime =
333335
(* shebang mustn't exceed 128 including the #! and \0 *)
@@ -541,7 +543,10 @@ let link_bytecode_as_c tolink outfile =
541543
(* Build a custom runtime *)
542544

543545
let build_custom_runtime prim_name exec_name =
544-
let runtime_lib = "-lcamlrun" ^ !Clflags.runtime_variant in
546+
let runtime_lib =
547+
if not !Clflags.with_runtime
548+
then ""
549+
else "-lcamlrun" ^ !Clflags.runtime_variant in
545550
let debug_prefix_map =
546551
if Config.c_has_debug_prefix_map && not !Clflags.keep_camlprimc_file then
547552
[Printf.sprintf "-fdebug-prefix-map=%s=camlprim.c" prim_name]
@@ -665,7 +670,10 @@ let link objfiles output_name =
665670
else Ccomp.MainDll, Config.bytecomp_c_libraries
666671
in
667672
if not (
668-
let runtime_lib = "-lcamlrun" ^ !Clflags.runtime_variant in
673+
let runtime_lib =
674+
if not !Clflags.with_runtime
675+
then ""
676+
else "-lcamlrun" ^ !Clflags.runtime_variant in
669677
Ccomp.call_linker mode output_name
670678
([obj_file] @ List.rev !Clflags.ccobjs @ [runtime_lib])
671679
c_libs

driver/compenv.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ let read_one_param ppf position name v =
232232

233233
| "pp" -> preprocessor := Some v
234234
| "runtime-variant" -> runtime_variant := v
235+
| "with-runtime" -> set "with-runtime" [ with_runtime ] v
235236
| "open" ->
236237
open_modules := List.rev_append (String.split_on_char ',' v) !open_modules
237238
| "cc" -> c_compiler := Some v

driver/main.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ module Options = Main_args.Make_bytecomp_options (struct
101101
let _rectypes = set recursive_types
102102
let _no_rectypes = unset recursive_types
103103
let _runtime_variant s = runtime_variant := s
104+
let _with_runtime = set with_runtime
105+
let _without_runtime = unset with_runtime
104106
let _safe_string = unset unsafe_string
105107
let _short_paths = unset real_paths
106108
let _strict_sequence = set strict_sequence

driver/main_args.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,16 @@ let mk_runtime_variant f =
454454
"<str> Use the <str> variant of the run-time system"
455455
;;
456456

457+
let mk_with_runtime f =
458+
"-with-runtime", Arg.Unit f,
459+
"Include the runtime system in the generated program (default)"
460+
;;
461+
462+
let mk_without_runtime f =
463+
"-without-runtime", Arg.Unit f,
464+
"Do not include the runtime system in the generated program."
465+
;;
466+
457467
let mk_S f =
458468
"-S", Arg.Unit f, " Keep intermediate assembly file"
459469
;;
@@ -930,6 +940,8 @@ module type Compiler_options = sig
930940
val _no_principal : unit -> unit
931941
val _rectypes : unit -> unit
932942
val _runtime_variant : string -> unit
943+
val _with_runtime : unit -> unit
944+
val _without_runtime : unit -> unit
933945
val _safe_string : unit -> unit
934946
val _short_paths : unit -> unit
935947
val _thread : unit -> unit
@@ -1144,6 +1156,8 @@ struct
11441156
mk_rectypes F._rectypes;
11451157
mk_no_rectypes F._no_rectypes;
11461158
mk_runtime_variant F._runtime_variant;
1159+
mk_with_runtime F._with_runtime;
1160+
mk_without_runtime F._without_runtime;
11471161
mk_safe_string F._safe_string;
11481162
mk_short_paths F._short_paths;
11491163
mk_strict_sequence F._strict_sequence;
@@ -1332,6 +1346,8 @@ struct
13321346
mk_remove_unused_arguments F._remove_unused_arguments;
13331347
mk_rounds F._rounds;
13341348
mk_runtime_variant F._runtime_variant;
1349+
mk_with_runtime F._with_runtime;
1350+
mk_without_runtime F._without_runtime;
13351351
mk_S F._S;
13361352
mk_safe_string F._safe_string;
13371353
mk_shared F._shared;

driver/main_args.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ module type Compiler_options = sig
9696
val _no_principal : unit -> unit
9797
val _rectypes : unit -> unit
9898
val _runtime_variant : string -> unit
99+
val _with_runtime : unit -> unit
100+
val _without_runtime : unit -> unit
99101
val _safe_string : unit -> unit
100102
val _short_paths : unit -> unit
101103
val _thread : unit -> unit

driver/optmain.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ module Options = Main_args.Make_optcomp_options (struct
181181
let _no_rectypes = clear recursive_types
182182
let _remove_unused_arguments = set remove_unused_arguments
183183
let _runtime_variant s = runtime_variant := s
184+
let _with_runtime = set with_runtime
185+
let _without_runtime = clear with_runtime
184186
let _safe_string = clear unsafe_string
185187
let _short_paths = clear real_paths
186188
let _strict_sequence = set strict_sequence

man/ocamlc.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,13 @@ compilation in any way (even if it is fatal). If a warning is enabled,
10561056
.B \-where
10571057
Print the location of the standard library, then exit.
10581058
.TP
1059+
.B \-with-runtime
1060+
Include the runtime system in the generated program. This is the default.
1061+
.TP
1062+
.B \-without-runtime
1063+
The compiler does not include the runtime system (nor a reference to it) in the
1064+
generated program; it must be supplied separately.
1065+
.TP
10591066
.BI \- \ file
10601067
Process
10611068
.I file

man/ocamlopt.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,13 @@ Print the version number of the compiler in short form (e.g. "3.11.0"),
684684
.B \-where
685685
Print the location of the standard library, then exit.
686686
.TP
687+
.B \-with-runtime
688+
Include the runtime system in the generated program. This is the default.
689+
.TP
690+
.B \-without-runtime
691+
The compiler does not include the runtime system (nor a reference to it) in the
692+
generated program; it must be supplied separately.
693+
.TP
687694
.BI \- \ file
688695
Process
689696
.I file

0 commit comments

Comments
 (0)