| author | |
| committer | |
| log | aa8c774e0f15617137f56eb15c667e259b3be75a |
| tree | 8e8148a43d71ff452a2fba5404ffa8b29802fb60 |
| parent | 3944c72a148096e3933745a9fda0397c0dd67cbf |
In order to allow the compiler to default to ReleaseSafe when compiling
for fuzzing, Build.standardOptimizeOption has been changed to return an
optional value.5 files changed, 17 insertions(+), 14 deletions(-)
build.zig+1-1| ... | @@ -883,7 +883,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { | ... | @@ -883,7 +883,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | const AddCompilerModOptions = struct { | 885 | const AddCompilerModOptions = struct { |
| 886 | optimize: std.lang.Optimize, | 886 | optimize: ?std.lang.Optimize, |
| 887 | target: std.Build.ResolvedTarget, | 887 | target: std.Build.ResolvedTarget, |
| 888 | strip: ?bool = null, | 888 | strip: ?bool = null, |
| 889 | valgrind: ?bool = null, | 889 | valgrind: ?bool = null, |
lib/std/Build.zig+3-3| ... | @@ -1190,14 +1190,14 @@ pub const StandardOptimizeOptionOptions = struct { | ... | @@ -1190,14 +1190,14 @@ pub const StandardOptimizeOptionOptions = struct { |
| 1190 | preferred_optimize_mode: ?std.builtin.Optimize = null, | 1190 | preferred_optimize_mode: ?std.builtin.Optimize = null, |
| 1191 | }; | 1191 | }; |
| 1192 | 1192 | ||
| 1193 | pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) std.builtin.Optimize { | 1193 | pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) ?std.builtin.Optimize { |
| 1194 | const graph = b.graph; | 1194 | const graph = b.graph; |
| 1195 | 1195 | ||
| 1196 | if (options.preferred_optimize_mode) |mode| { | 1196 | if (options.preferred_optimize_mode) |mode| { |
| 1197 | if (b.option(bool, "release", "optimize for end users") orelse (graph.release_mode != .off)) { | 1197 | if (b.option(bool, "release", "optimize for end users") orelse (graph.release_mode != .off)) { |
| 1198 | return mode; | 1198 | return mode; |
| 1199 | } else { | 1199 | } else { |
| 1200 | return .debug; | 1200 | return null; |
| 1201 | } | 1201 | } |
| 1202 | } | 1202 | } |
| 1203 | 1203 | ||
| ... | @@ -1210,7 +1210,7 @@ pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) | ... | @@ -1210,7 +1210,7 @@ pub fn standardOptimizeOption(b: *Build, options: StandardOptimizeOptionOptions) |
| 1210 | } | 1210 | } |
| 1211 | 1211 | ||
| 1212 | return switch (graph.release_mode) { | 1212 | return switch (graph.release_mode) { |
| 1213 | .off => .debug, | 1213 | .off => null, |
| 1214 | .any => { | 1214 | .any => { |
| 1215 | std.debug.print("the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small\n", .{}); | 1215 | std.debug.print("the project does not declare a preferred optimization mode. choose: --release=fast, --release=safe, or --release=small\n", .{}); |
| 1216 | process.exit(1); | 1216 | 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 { |
| 10 | 10 | ||
| 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.Optimize = switch (b.graph.release_mode) { | 13 | const expected_optimize: ?std.builtin.OptimizeMode = switch (b.graph.release_mode) { |
| 14 | .off => .debug, | 14 | .off => null, |
| 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; |
| 21 | 21 | ||
| 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 | } |
| 57 | 57 | ||
| 58 | fn run_exe(b: *std.Build, optimize: std.builtin.Optimize, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run { | 58 | fn 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+9-6| ... | @@ -20,7 +20,7 @@ pub const LinkContext = @import("src/Link.zig"); | ... | @@ -20,7 +20,7 @@ pub const LinkContext = @import("src/Link.zig"); |
| 20 | const ModuleTestTarget = struct { | 20 | const 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, |
| ... | @@ -2795,7 +2795,7 @@ pub const ModuleTestOptions = struct { | ... | @@ -2795,7 +2795,7 @@ pub const ModuleTestOptions = struct { |
| 2795 | 2795 | ||
| 2796 | pub const TestOnly = union(enum) { | 2796 | pub const TestOnly = union(enum) { |
| 2797 | default: void, | 2797 | default: void, |
| 2798 | fuzz: OptimizeMode, | 2798 | fuzz: ?OptimizeMode, |
| 2799 | }; | 2799 | }; |
| 2800 | }; | 2800 | }; |
| 2801 | 2801 | ||
| ... | @@ -2896,6 +2896,9 @@ fn addOneModuleTest( | ... | @@ -2896,6 +2896,9 @@ fn addOneModuleTest( |
| 2896 | options: ModuleTestOptions, | 2896 | options: ModuleTestOptions, |
| 2897 | ) void { | 2897 | ) void { |
| 2898 | const target = &resolved_target.result; | 2898 | const target = &resolved_target.result; |
| 2899 | const optimize_suffix = if (test_target.optimize_mode) |mode| switch (mode) { | ||
| 2900 | inline else => |t| "-" ++ @tagName(t), | ||
| 2901 | } else ""; | ||
| 2899 | const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; | 2902 | const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; |
| 2900 | const model_txt = target.cpu.model.name; | 2903 | const model_txt = target.cpu.model.name; |
| 2901 | 2904 | ||
| ... | @@ -2948,11 +2951,11 @@ fn addOneModuleTest( | ... | @@ -2948,11 +2951,11 @@ fn addOneModuleTest( |
| 2948 | 2951 | ||
| 2949 | for (options.include_paths) |include_path| these_tests.root_module.addIncludePath(b.path(include_path)); | 2952 | for (options.include_paths) |include_path| these_tests.root_module.addIncludePath(b.path(include_path)); |
| 2950 | 2953 | ||
| 2951 | const qualified_name = b.fmt("{s}-{s}-{s}-{t}{s}{s}{s}{s}{s}{s}", .{ | 2954 | const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}{s}{s}{s}{s}", .{ |
| 2952 | options.name, | 2955 | options.name, |
| 2953 | triple_txt, | 2956 | triple_txt, |
| 2954 | model_txt, | 2957 | model_txt, |
| 2955 | test_target.optimize_mode, | 2958 | optimize_suffix, |
| 2956 | libc_suffix, | 2959 | libc_suffix, |
| 2957 | single_threaded_suffix, | 2960 | single_threaded_suffix, |
| 2958 | backend_suffix, | 2961 | backend_suffix, |
| ... | @@ -3087,11 +3090,11 @@ fn addOneModuleTest( | ... | @@ -3087,11 +3090,11 @@ fn addOneModuleTest( |
| 3087 | } | 3090 | } |
| 3088 | } | 3091 | } |
| 3089 | 3092 | ||
| 3090 | pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool { | 3093 | pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: ?OptimizeMode) bool { |
| 3091 | if (comptime builtin.cpu.arch.endian() == .big) return true; // https://github.com/ziglang/zig/issues/25961 | 3094 | if (comptime builtin.cpu.arch.endian() == .big) return true; // https://github.com/ziglang/zig/issues/25961 |
| 3092 | if (use_llvm) |x| return x; | 3095 | if (use_llvm) |x| return x; |
| 3093 | if (query.ofmt == .c) return false; | 3096 | if (query.ofmt == .c) return false; |
| 3094 | switch (optimize_mode) { | 3097 | switch (optimize_mode orelse .debug) { |
| 3095 | .debug => {}, | 3098 | .debug => {}, |
| 3096 | else => return true, | 3099 | else => return true, |
| 3097 | } | 3100 | } |