authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-17 12:25:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-17 12:25:32-07:00
log21141cb88a130fb113f8c17647bae34ae74efa05
tree22f94667a981801ebbeac3909c4ed462fe1a3f9d
parentf2f0d97a9b9df2e4aa43c1e4b7876bcc97cb83ff

Revert "allow standardOptimizeOption to return null"

This reverts commit aa8c774e0f15617137f56eb15c667e259b3be75a. In retrospect, the breaking change is quite invasive and I don't think we have fully considered the alternatives.

5 files changed, 14 insertions(+), 17 deletions(-)

build.zig+1-1
...@@ -884,7 +884,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {...@@ -884,7 +884,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
884}884}
885885
886const AddCompilerModOptions = struct {886const AddCompilerModOptions = struct {
887 optimize: ?std.lang.Optimize,887 optimize: std.lang.Optimize,
888 target: std.Build.ResolvedTarget,888 target: std.Build.ResolvedTarget,
889 strip: ?bool = null,889 strip: ?bool = null,
890 valgrind: ?bool = null,890 valgrind: ?bool = null,
lib/std/Build.zig+3-3
...@@ -1194,14 +1194,14 @@ pub const StandardOptimizeOptionOptions = struct {...@@ -1194,14 +1194,14 @@ pub const StandardOptimizeOptionOptions = struct {
1194 preferred_optimize_mode: ?std.builtin.Optimize = null,1194 preferred_optimize_mode: ?std.builtin.Optimize = null,
1195};1195};
11961196
1197pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) ?std.builtin.Optimize {1197pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) std.builtin.Optimize {
1198 const graph = b.graph;1198 const graph = b.graph;
11991199
1200 if (options.preferred_optimize_mode) |mode| {1200 if (options.preferred_optimize_mode) |mode| {
1201 if (b.option(bool, "release", "optimize for end users") orelse (graph.release_mode != .off)) {1201 if (b.option(bool, "release", "optimize for end users") orelse (graph.release_mode != .off)) {
1202 return mode;1202 return mode;
1203 } else {1203 } else {
1204 return null;1204 return .debug;
1205 }1205 }
1206 }1206 }
12071207
...@@ -1214,7 +1214,7 @@ pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions)...@@ -1214,7 +1214,7 @@ pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions)
1214 }1214 }
12151215
1216 return switch (graph.release_mode) {1216 return switch (graph.release_mode) {
1217 .off => null,1217 .off => .debug,
1218 .any => {1218 .any => {
1219 std.debug.print("the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small\n", .{});1219 std.debug.print("the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small\n", .{});
1220 process.exit(1);1220 process.exit(1);
test/standalone/dependency_options/build.zig+3-3
...@@ -10,14 +10,14 @@ pub fn build(b: *std.Build) !void {...@@ -10,14 +10,14 @@ pub fn build(b: *std.Build) !void {
1010
11 const none_specified_mod = none_specified.module("dummy");11 const none_specified_mod = none_specified.module("dummy");
12 if (!none_specified_mod.resolved_target.?.query.eql(b.graph.host.query)) return error.TestFailed;12 if (!none_specified_mod.resolved_target.?.query.eql(b.graph.host.query)) return error.TestFailed;
13 const expected_optimize: ?std.builtin.OptimizeMode = switch (b.graph.release_mode) {13 const expected_optimize: std.builtin.Optimize = switch (b.graph.release_mode) {
14 .off => null,14 .off => .debug,
15 .any => unreachable,15 .any => unreachable,
16 .fast => .fast,16 .fast => .fast,
17 .safe => .safe,17 .safe => .safe,
18 .small => .small,18 .small => .small,
19 };19 };
20 if (none_specified_mod.optimize != expected_optimize) return error.TestFailed;20 if (none_specified_mod.optimize.? != expected_optimize) return error.TestFailed;
2121
22 // Passing null is the same as not specifying the option,22 // Passing null is the same as not specifying the option,
23 // so this should resolve to the same cached dependency instance.23 // so this should resolve to the same cached dependency instance.
test/standalone/posix/build.zig+1-1
...@@ -55,7 +55,7 @@ pub fn build(b: *std.Build) void {...@@ -55,7 +55,7 @@ pub fn build(b: *std.Build) void {
55 }55 }
56}56}
5757
58fn run_exe(b: *std.Build, optimize: ?std.builtin.Optimize, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run {58fn run_exe(b: *std.Build, optimize: std.builtin.Optimize, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run {
59 const exe_name = b.fmt("test-posix-{s}{s}{s}", .{59 const exe_name = b.fmt("test-posix-{s}{s}{s}", .{
60 std.fs.path.stem(case.src_path),60 std.fs.path.stem(case.src_path),
61 if (link_libc) "-libc" else "",61 if (link_libc) "-libc" else "",
test/tests.zig+6-9
...@@ -20,7 +20,7 @@ pub const LinkContext = @import("src/Link.zig");...@@ -20,7 +20,7 @@ pub const LinkContext = @import("src/Link.zig");
20const ModuleTestTarget = struct {20const ModuleTestTarget = struct {
21 linkage: ?std.builtin.LinkMode = null,21 linkage: ?std.builtin.LinkMode = null,
22 target: std.Target.Query = .{},22 target: std.Target.Query = .{},
23 optimize_mode: ?std.builtin.Optimize = .debug,23 optimize_mode: std.builtin.Optimize = .debug,
24 link_libc: ?bool = null,24 link_libc: ?bool = null,
25 single_threaded: ?bool = null,25 single_threaded: ?bool = null,
26 use_llvm: ?bool = null,26 use_llvm: ?bool = null,
...@@ -2650,7 +2650,7 @@ pub const ModuleTestOptions = struct {...@@ -2650,7 +2650,7 @@ pub const ModuleTestOptions = struct {
26502650
2651 pub const TestOnly = union(enum) {2651 pub const TestOnly = union(enum) {
2652 default: void,2652 default: void,
2653 fuzz: ?OptimizeMode,2653 fuzz: OptimizeMode,
2654 };2654 };
2655};2655};
26562656
...@@ -2751,9 +2751,6 @@ fn addOneModuleTest(...@@ -2751,9 +2751,6 @@ fn addOneModuleTest(
2751 options: ModuleTestOptions,2751 options: ModuleTestOptions,
2752) void {2752) void {
2753 const target = &resolved_target.result;2753 const target = &resolved_target.result;
2754 const optimize_suffix = if (test_target.optimize_mode) |mode| switch (mode) {
2755 inline else => |t| "-" ++ @tagName(t),
2756 } else "";
2757 const libc_suffix = if (test_target.link_libc == true) "-libc" else "";2754 const libc_suffix = if (test_target.link_libc == true) "-libc" else "";
2758 const model_txt = target.cpu.model.name;2755 const model_txt = target.cpu.model.name;
27592756
...@@ -2806,11 +2803,11 @@ fn addOneModuleTest(...@@ -2806,11 +2803,11 @@ fn addOneModuleTest(
28062803
2807 for (options.include_paths) |include_path| these_tests.root_module.addIncludePath(b.path(include_path));2804 for (options.include_paths) |include_path| these_tests.root_module.addIncludePath(b.path(include_path));
28082805
2809 const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}{s}{s}{s}{s}", .{2806 const qualified_name = b.fmt("{s}-{s}-{s}-{t}{s}{s}{s}{s}{s}{s}", .{
2810 options.name,2807 options.name,
2811 triple_txt,2808 triple_txt,
2812 model_txt,2809 model_txt,
2813 optimize_suffix,2810 test_target.optimize_mode,
2814 libc_suffix,2811 libc_suffix,
2815 single_threaded_suffix,2812 single_threaded_suffix,
2816 backend_suffix,2813 backend_suffix,
...@@ -2945,11 +2942,11 @@ fn addOneModuleTest(...@@ -2945,11 +2942,11 @@ fn addOneModuleTest(
2945 }2942 }
2946}2943}
29472944
2948pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: ?OptimizeMode) bool {2945pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool {
2949 if (comptime builtin.cpu.arch.endian() == .big) return true; // https://github.com/ziglang/zig/issues/259612946 if (comptime builtin.cpu.arch.endian() == .big) return true; // https://github.com/ziglang/zig/issues/25961
2950 if (use_llvm) |x| return x;2947 if (use_llvm) |x| return x;
2951 if (query.ofmt == .c) return false;2948 if (query.ofmt == .c) return false;
2952 switch (optimize_mode orelse .debug) {2949 switch (optimize_mode) {
2953 .debug => {},2950 .debug => {},
2954 else => return true,2951 else => return true,
2955 }2952 }