@@ -96,6 +96,16 @@ initialized_deps: *InitializedDepMap,
96
96
/// A mapping from dependency names to package hashes.
97
97
available_deps : AvailableDeps ,
98
98
99
+ release_mode : ReleaseMode ,
100
+
101
+ pub const ReleaseMode = enum {
102
+ off ,
103
+ any ,
104
+ fast ,
105
+ safe ,
106
+ small ,
107
+ };
108
+
99
109
/// Shared state among all Build instances.
100
110
/// Settings that are here rather than in Build are not configurable per-package.
101
111
pub const Graph = struct {
@@ -295,6 +305,7 @@ pub fn create(
295
305
.named_writefiles = std .StringArrayHashMap (* Step .WriteFile ).init (arena ),
296
306
.initialized_deps = initialized_deps ,
297
307
.available_deps = available_deps ,
308
+ .release_mode = .off ,
298
309
};
299
310
try self .top_level_steps .put (arena , self .install_tls .step .name , & self .install_tls );
300
311
try self .top_level_steps .put (arena , self .uninstall_tls .step .name , & self .uninstall_tls );
@@ -386,6 +397,7 @@ fn createChildOnly(
386
397
.named_writefiles = std .StringArrayHashMap (* Step .WriteFile ).init (allocator ),
387
398
.initialized_deps = parent .initialized_deps ,
388
399
.available_deps = pkg_deps ,
400
+ .release_mode = parent .release_mode ,
389
401
};
390
402
try child .top_level_steps .put (allocator , child .install_tls .step .name , & child .install_tls );
391
403
try child .top_level_steps .put (allocator , child .uninstall_tls .step .name , & child .uninstall_tls );
@@ -1230,20 +1242,33 @@ pub const StandardOptimizeOptionOptions = struct {
1230
1242
preferred_optimize_mode : ? std.builtin.OptimizeMode = null ,
1231
1243
};
1232
1244
1233
- pub fn standardOptimizeOption (self : * Build , options : StandardOptimizeOptionOptions ) std.builtin.OptimizeMode {
1245
+ pub fn standardOptimizeOption (b : * Build , options : StandardOptimizeOptionOptions ) std.builtin.OptimizeMode {
1234
1246
if (options .preferred_optimize_mode ) | mode | {
1235
- if (self .option (bool , "release" , "optimize for end users" ) orelse false ) {
1247
+ if (b .option (bool , "release" , "optimize for end users" ) orelse ( b . release_mode != .off ) ) {
1236
1248
return mode ;
1237
1249
} else {
1238
1250
return .Debug ;
1239
1251
}
1240
- } else {
1241
- return self .option (
1242
- std .builtin .OptimizeMode ,
1243
- "optimize" ,
1244
- "Prioritize performance, safety, or binary size (-O flag)" ,
1245
- ) orelse .Debug ;
1246
1252
}
1253
+
1254
+ if (b .option (
1255
+ std .builtin .OptimizeMode ,
1256
+ "optimize" ,
1257
+ "Prioritize performance, safety, or binary size (-O flag)" ,
1258
+ )) | mode | {
1259
+ return mode ;
1260
+ }
1261
+
1262
+ return switch (b .release_mode ) {
1263
+ .off = > .Debug ,
1264
+ .any = > {
1265
+ std .debug .print ("the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small\n " , .{});
1266
+ process .exit (1 );
1267
+ },
1268
+ .fast = > .ReleaseFast ,
1269
+ .safe = > .ReleaseSafe ,
1270
+ .small = > .ReleaseSmall ,
1271
+ };
1247
1272
}
1248
1273
1249
1274
pub const StandardTargetOptionsArgs = struct {
0 commit comments