diff --git a/build.zig b/build.zig index e89d48cf11411cbc0fdbc0920b957c8f2381c917..13bafd5f8f7527de65e97a296cd0d541ca77db20 100644 --- a/build.zig +++ b/build.zig @@ -884,7 +884,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { } const AddCompilerModOptions = struct { - optimize: ?std.lang.Optimize, + optimize: std.lang.Optimize, target: std.Build.ResolvedTarget, strip: ?bool = null, valgrind: ?bool = null, diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 86f36b3722e359c1076236d16cce94d3b900b369..7e52047b126e83bf914d67a024e061bac0bbd573 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1194,14 +1194,14 @@ pub const StandardOptimizeOptionOptions = struct { preferred_optimize_mode: ?std.builtin.Optimize = null, }; -pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) ?std.builtin.Optimize { +pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) std.builtin.Optimize { const graph = b.graph; if (options.preferred_optimize_mode) |mode| { if (b.option(bool, "release", "optimize for end users") orelse (graph.release_mode != .off)) { return mode; } else { - return null; + return .debug; } } @@ -1214,7 +1214,7 @@ pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) } return switch (graph.release_mode) { - .off => null, + .off => .debug, .any => { std.debug.print("the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small\n", .{}); process.exit(1); diff --git a/test/standalone/dependency_options/build.zig b/test/standalone/dependency_options/build.zig index bf431dc9f4ed6bdf73bcabb566c628269e3934ea..5465cf7157a2d77378f2cd44b7369d70c2fe02c4 100644 --- a/test/standalone/dependency_options/build.zig +++ b/test/standalone/dependency_options/build.zig @@ -10,14 +10,14 @@ pub fn build(b: *std.Build) !void { const none_specified_mod = none_specified.module("dummy"); if (!none_specified_mod.resolved_target.?.query.eql(b.graph.host.query)) return error.TestFailed; - const expected_optimize: ?std.builtin.OptimizeMode = switch (b.graph.release_mode) { - .off => null, + const expected_optimize: std.builtin.Optimize = switch (b.graph.release_mode) { + .off => .debug, .any => unreachable, .fast => .fast, .safe => .safe, .small => .small, }; - if (none_specified_mod.optimize != expected_optimize) return error.TestFailed; + if (none_specified_mod.optimize.? != expected_optimize) return error.TestFailed; // Passing null is the same as not specifying the option, // so this should resolve to the same cached dependency instance. diff --git a/test/standalone/posix/build.zig b/test/standalone/posix/build.zig index 34575df0e54bd790f88d5921129a16b0cb35eff4..d2353e010c7c8681cc74829a4a5c9f052edb1e24 100644 --- a/test/standalone/posix/build.zig +++ b/test/standalone/posix/build.zig @@ -55,7 +55,7 @@ pub fn build(b: *std.Build) void { } } -fn run_exe(b: *std.Build, optimize: ?std.builtin.Optimize, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run { +fn run_exe(b: *std.Build, optimize: std.builtin.Optimize, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run { const exe_name = b.fmt("test-posix-{s}{s}{s}", .{ std.fs.path.stem(case.src_path), if (link_libc) "-libc" else "", diff --git a/test/tests.zig b/test/tests.zig index fc060c1519b6c1a8b53786beebc9a97ff4d790f6..ba0079b752ffb808a2cebe89fb5776e1663aa34f 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -20,7 +20,7 @@ pub const LinkContext = @import("src/Link.zig"); const ModuleTestTarget = struct { linkage: ?std.builtin.LinkMode = null, target: std.Target.Query = .{}, - optimize_mode: ?std.builtin.Optimize = .debug, + optimize_mode: std.builtin.Optimize = .debug, link_libc: ?bool = null, single_threaded: ?bool = null, use_llvm: ?bool = null, @@ -2650,7 +2650,7 @@ pub const ModuleTestOptions = struct { pub const TestOnly = union(enum) { default: void, - fuzz: ?OptimizeMode, + fuzz: OptimizeMode, }; }; @@ -2751,9 +2751,6 @@ fn addOneModuleTest( options: ModuleTestOptions, ) void { const target = &resolved_target.result; - const optimize_suffix = if (test_target.optimize_mode) |mode| switch (mode) { - inline else => |t| "-" ++ @tagName(t), - } else ""; const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; const model_txt = target.cpu.model.name; @@ -2806,11 +2803,11 @@ fn addOneModuleTest( for (options.include_paths) |include_path| these_tests.root_module.addIncludePath(b.path(include_path)); - const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}{s}{s}{s}{s}", .{ + const qualified_name = b.fmt("{s}-{s}-{s}-{t}{s}{s}{s}{s}{s}{s}", .{ options.name, triple_txt, model_txt, - optimize_suffix, + test_target.optimize_mode, libc_suffix, single_threaded_suffix, backend_suffix, @@ -2945,11 +2942,11 @@ fn addOneModuleTest( } } -pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: ?OptimizeMode) bool { +pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool { if (comptime builtin.cpu.arch.endian() == .big) return true; // https://github.com/ziglang/zig/issues/25961 if (use_llvm) |x| return x; if (query.ofmt == .c) return false; - switch (optimize_mode orelse .debug) { + switch (optimize_mode) { .debug => {}, else => return true, }