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 {
884884}
885885
886886const AddCompilerModOptions = struct {
887 optimize: ?std.lang.Optimize,
887 optimize: std.lang.Optimize,
888888 target: std.Build.ResolvedTarget,
889889 strip: ?bool = null,
890890 valgrind: ?bool = null,
lib/std/Build.zig+3-3
......@@ -1194,14 +1194,14 @@ pub const StandardOptimizeOptionOptions = struct {
11941194 preferred_optimize_mode: ?std.builtin.Optimize = null,
11951195};
11961196
1197pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) ?std.builtin.Optimize {
1197pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) std.builtin.Optimize {
11981198 const graph = b.graph;
11991199
12001200 if (options.preferred_optimize_mode) |mode| {
12011201 if (b.option(bool, "release", "optimize for end users") orelse (graph.release_mode != .off)) {
12021202 return mode;
12031203 } else {
1204 return null;
1204 return .debug;
12051205 }
12061206 }
12071207
......@@ -1214,7 +1214,7 @@ pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions)
12141214 }
12151215
12161216 return switch (graph.release_mode) {
1217 .off => null,
1217 .off => .debug,
12181218 .any => {
12191219 std.debug.print("the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small\n", .{});
12201220 process.exit(1);
test/standalone/dependency_options/build.zig+3-3
......@@ -10,14 +10,14 @@ pub fn build(b: *std.Build) !void {
1010
1111 const none_specified_mod = none_specified.module("dummy");
1212 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) {
14 .off => null,
13 const expected_optimize: std.builtin.Optimize = switch (b.graph.release_mode) {
14 .off => .debug,
1515 .any => unreachable,
1616 .fast => .fast,
1717 .safe => .safe,
1818 .small => .small,
1919 };
20 if (none_specified_mod.optimize != expected_optimize) return error.TestFailed;
20 if (none_specified_mod.optimize.? != expected_optimize) return error.TestFailed;
2121
2222 // Passing null is the same as not specifying the option,
2323 // 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 {
5555 }
5656}
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 {
5959 const exe_name = b.fmt("test-posix-{s}{s}{s}", .{
6060 std.fs.path.stem(case.src_path),
6161 if (link_libc) "-libc" else "",
test/tests.zig+6-9
......@@ -20,7 +20,7 @@ pub const LinkContext = @import("src/Link.zig");
2020const ModuleTestTarget = struct {
2121 linkage: ?std.builtin.LinkMode = null,
2222 target: std.Target.Query = .{},
23 optimize_mode: ?std.builtin.Optimize = .debug,
23 optimize_mode: std.builtin.Optimize = .debug,
2424 link_libc: ?bool = null,
2525 single_threaded: ?bool = null,
2626 use_llvm: ?bool = null,
......@@ -2650,7 +2650,7 @@ pub const ModuleTestOptions = struct {
26502650
26512651 pub const TestOnly = union(enum) {
26522652 default: void,
2653 fuzz: ?OptimizeMode,
2653 fuzz: OptimizeMode,
26542654 };
26552655};
26562656
......@@ -2751,9 +2751,6 @@ fn addOneModuleTest(
27512751 options: ModuleTestOptions,
27522752) void {
27532753 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 "";
27572754 const libc_suffix = if (test_target.link_libc == true) "-libc" else "";
27582755 const model_txt = target.cpu.model.name;
27592756
......@@ -2806,11 +2803,11 @@ fn addOneModuleTest(
28062803
28072804 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}", .{
28102807 options.name,
28112808 triple_txt,
28122809 model_txt,
2813 optimize_suffix,
2810 test_target.optimize_mode,
28142811 libc_suffix,
28152812 single_threaded_suffix,
28162813 backend_suffix,
......@@ -2945,11 +2942,11 @@ fn addOneModuleTest(
29452942 }
29462943}
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 {
29492946 if (comptime builtin.cpu.arch.endian() == .big) return true; // https://github.com/ziglang/zig/issues/25961
29502947 if (use_llvm) |x| return x;
29512948 if (query.ofmt == .c) return false;
2952 switch (optimize_mode orelse .debug) {
2949 switch (optimize_mode) {
29532950 .debug => {},
29542951 else => return true,
29552952 }