change uses of std.builtin.Mode to OptimizeMode (#16745)

std.builtin.Mode is deprecated.
This commit is contained in:
Zachary Raineri 2023-08-09 13:39:34 -05:00 committed by GitHub
parent 72c68f698e
commit 0461a64a93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 28 deletions

View file

@ -400,22 +400,22 @@ pub fn build(b: *std.Build) !void {
test_cases_options.addOption(std.SemanticVersion, "semver", semver); test_cases_options.addOption(std.SemanticVersion, "semver", semver);
test_cases_options.addOption(?[]const u8, "test_filter", test_filter); test_cases_options.addOption(?[]const u8, "test_filter", test_filter);
var chosen_opt_modes_buf: [4]builtin.Mode = undefined; var chosen_opt_modes_buf: [4]builtin.OptimizeMode = undefined;
var chosen_mode_index: usize = 0; var chosen_mode_index: usize = 0;
if (!skip_debug) { if (!skip_debug) {
chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.Debug; chosen_opt_modes_buf[chosen_mode_index] = builtin.OptimizeMode.Debug;
chosen_mode_index += 1; chosen_mode_index += 1;
} }
if (!skip_release_safe) { if (!skip_release_safe) {
chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseSafe; chosen_opt_modes_buf[chosen_mode_index] = builtin.OptimizeMode.ReleaseSafe;
chosen_mode_index += 1; chosen_mode_index += 1;
} }
if (!skip_release_fast) { if (!skip_release_fast) {
chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseFast; chosen_opt_modes_buf[chosen_mode_index] = builtin.OptimizeMode.ReleaseFast;
chosen_mode_index += 1; chosen_mode_index += 1;
} }
if (!skip_release_small) { if (!skip_release_small) {
chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseSmall; chosen_opt_modes_buf[chosen_mode_index] = builtin.OptimizeMode.ReleaseSmall;
chosen_mode_index += 1; chosen_mode_index += 1;
} }
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index]; const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];

View file

@ -475,7 +475,7 @@ pub const ExecutableOptions = struct {
root_source_file: ?LazyPath = null, root_source_file: ?LazyPath = null,
version: ?std.SemanticVersion = null, version: ?std.SemanticVersion = null,
target: CrossTarget = .{}, target: CrossTarget = .{},
optimize: std.builtin.Mode = .Debug, optimize: std.builtin.OptimizeMode = .Debug,
linkage: ?Step.Compile.Linkage = null, linkage: ?Step.Compile.Linkage = null,
max_rss: usize = 0, max_rss: usize = 0,
link_libc: ?bool = null, link_libc: ?bool = null,
@ -509,7 +509,7 @@ pub const ObjectOptions = struct {
name: []const u8, name: []const u8,
root_source_file: ?LazyPath = null, root_source_file: ?LazyPath = null,
target: CrossTarget, target: CrossTarget,
optimize: std.builtin.Mode, optimize: std.builtin.OptimizeMode,
max_rss: usize = 0, max_rss: usize = 0,
link_libc: ?bool = null, link_libc: ?bool = null,
single_threaded: ?bool = null, single_threaded: ?bool = null,
@ -541,7 +541,7 @@ pub const SharedLibraryOptions = struct {
root_source_file: ?LazyPath = null, root_source_file: ?LazyPath = null,
version: ?std.SemanticVersion = null, version: ?std.SemanticVersion = null,
target: CrossTarget, target: CrossTarget,
optimize: std.builtin.Mode, optimize: std.builtin.OptimizeMode,
max_rss: usize = 0, max_rss: usize = 0,
link_libc: ?bool = null, link_libc: ?bool = null,
single_threaded: ?bool = null, single_threaded: ?bool = null,
@ -574,7 +574,7 @@ pub const StaticLibraryOptions = struct {
name: []const u8, name: []const u8,
root_source_file: ?LazyPath = null, root_source_file: ?LazyPath = null,
target: CrossTarget, target: CrossTarget,
optimize: std.builtin.Mode, optimize: std.builtin.OptimizeMode,
version: ?std.SemanticVersion = null, version: ?std.SemanticVersion = null,
max_rss: usize = 0, max_rss: usize = 0,
link_libc: ?bool = null, link_libc: ?bool = null,
@ -608,7 +608,7 @@ pub const TestOptions = struct {
name: []const u8 = "test", name: []const u8 = "test",
root_source_file: LazyPath, root_source_file: LazyPath,
target: CrossTarget = .{}, target: CrossTarget = .{},
optimize: std.builtin.Mode = .Debug, optimize: std.builtin.OptimizeMode = .Debug,
version: ?std.SemanticVersion = null, version: ?std.SemanticVersion = null,
max_rss: usize = 0, max_rss: usize = 0,
filter: ?[]const u8 = null, filter: ?[]const u8 = null,
@ -644,7 +644,7 @@ pub const AssemblyOptions = struct {
name: []const u8, name: []const u8,
source_file: LazyPath, source_file: LazyPath,
target: CrossTarget, target: CrossTarget,
optimize: std.builtin.Mode, optimize: std.builtin.OptimizeMode,
max_rss: usize = 0, max_rss: usize = 0,
zig_lib_dir: ?LazyPath = null, zig_lib_dir: ?LazyPath = null,
}; };
@ -1000,10 +1000,10 @@ pub fn step(self: *Build, name: []const u8, description: []const u8) *Step {
} }
pub const StandardOptimizeOptionOptions = struct { pub const StandardOptimizeOptionOptions = struct {
preferred_optimize_mode: ?std.builtin.Mode = null, preferred_optimize_mode: ?std.builtin.OptimizeMode = null,
}; };
pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptions) std.builtin.Mode { pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptions) std.builtin.OptimizeMode {
if (options.preferred_optimize_mode) |mode| { if (options.preferred_optimize_mode) |mode| {
if (self.option(bool, "release", "optimize for end users") orelse false) { if (self.option(bool, "release", "optimize for end users") orelse false) {
return mode; return mode;
@ -1012,7 +1012,7 @@ pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptio
} }
} else { } else {
return self.option( return self.option(
std.builtin.Mode, std.builtin.OptimizeMode,
"optimize", "optimize",
"Prioritize performance, safety, or binary size (-O flag)", "Prioritize performance, safety, or binary size (-O flag)",
) orelse .Debug; ) orelse .Debug;

View file

@ -27,7 +27,7 @@ step: Step,
name: []const u8, name: []const u8,
target: CrossTarget, target: CrossTarget,
target_info: NativeTargetInfo, target_info: NativeTargetInfo,
optimize: std.builtin.Mode, optimize: std.builtin.OptimizeMode,
linker_script: ?LazyPath = null, linker_script: ?LazyPath = null,
version_script: ?[]const u8 = null, version_script: ?[]const u8 = null,
out_filename: []const u8, out_filename: []const u8,
@ -269,7 +269,7 @@ pub const Options = struct {
name: []const u8, name: []const u8,
root_source_file: ?LazyPath = null, root_source_file: ?LazyPath = null,
target: CrossTarget, target: CrossTarget,
optimize: std.builtin.Mode, optimize: std.builtin.OptimizeMode,
kind: Kind, kind: Kind,
linkage: ?Linkage = null, linkage: ?Linkage = null,
version: ?std.SemanticVersion = null, version: ?std.SemanticVersion = null,

View file

@ -49,7 +49,7 @@ pub const AddExecutableOptions = struct {
name: ?[]const u8 = null, name: ?[]const u8 = null,
version: ?std.SemanticVersion = null, version: ?std.SemanticVersion = null,
target: ?CrossTarget = null, target: ?CrossTarget = null,
optimize: ?std.builtin.Mode = null, optimize: ?std.builtin.OptimizeMode = null,
linkage: ?Step.Compile.Linkage = null, linkage: ?Step.Compile.Linkage = null,
}; };

View file

@ -498,7 +498,7 @@ pub const InitOptions = struct {
/// this flag would be set to disable this machinery to avoid false positives. /// this flag would be set to disable this machinery to avoid false positives.
disable_lld_caching: bool = false, disable_lld_caching: bool = false,
cache_mode: CacheMode = .incremental, cache_mode: CacheMode = .incremental,
optimize_mode: std.builtin.Mode = .Debug, optimize_mode: std.builtin.OptimizeMode = .Debug,
keep_source_files_loaded: bool = false, keep_source_files_loaded: bool = false,
clang_argv: []const []const u8 = &[0][]const u8{}, clang_argv: []const []const u8 = &[0][]const u8{},
lib_dirs: []const []const u8 = &[0][]const u8{}, lib_dirs: []const []const u8 = &[0][]const u8{},
@ -5348,7 +5348,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
\\ .ofmt = object_format, \\ .ofmt = object_format,
\\}}; \\}};
\\pub const object_format = std.Target.ObjectFormat.{}; \\pub const object_format = std.Target.ObjectFormat.{};
\\pub const mode = std.builtin.Mode.{}; \\pub const mode = std.builtin.OptimizeMode.{};
\\pub const link_libc = {}; \\pub const link_libc = {};
\\pub const link_libcpp = {}; \\pub const link_libcpp = {};
\\pub const have_error_return_tracing = {}; \\pub const have_error_return_tracing = {};
@ -5631,7 +5631,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
/// This decides the optimization mode for all zig-provided libraries, including /// This decides the optimization mode for all zig-provided libraries, including
/// compiler-rt, libcxx, libc, libunwind, etc. /// compiler-rt, libcxx, libc, libunwind, etc.
pub fn compilerRtOptMode(comp: Compilation) std.builtin.Mode { pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode {
if (comp.debug_compiler_runtime_libs) { if (comp.debug_compiler_runtime_libs) {
return comp.bin_file.options.optimize_mode; return comp.bin_file.options.optimize_mode;
} }

View file

@ -5640,7 +5640,7 @@ pub fn getTarget(mod: Module) Target {
return mod.comp.bin_file.options.target; return mod.comp.bin_file.options.target;
} }
pub fn optimizeMode(mod: Module) std.builtin.Mode { pub fn optimizeMode(mod: Module) std.builtin.OptimizeMode {
return mod.comp.bin_file.options.optimize_mode; return mod.comp.bin_file.options.optimize_mode;
} }

View file

@ -102,7 +102,7 @@ pub const Options = struct {
target: std.Target, target: std.Target,
output_mode: std.builtin.OutputMode, output_mode: std.builtin.OutputMode,
link_mode: std.builtin.LinkMode, link_mode: std.builtin.LinkMode,
optimize_mode: std.builtin.Mode, optimize_mode: std.builtin.OptimizeMode,
machine_code_model: std.builtin.CodeModel, machine_code_model: std.builtin.CodeModel,
root_name: [:0]const u8, root_name: [:0]const u8,
/// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`. /// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`.

View file

@ -765,7 +765,7 @@ fn buildOutputType(
arg_mode: ArgMode, arg_mode: ArgMode,
) !void { ) !void {
var color: Color = .auto; var color: Color = .auto;
var optimize_mode: std.builtin.Mode = .Debug; var optimize_mode: std.builtin.OptimizeMode = .Debug;
var provided_name: ?[]const u8 = null; var provided_name: ?[]const u8 = null;
var link_mode: ?std.builtin.LinkMode = null; var link_mode: ?std.builtin.LinkMode = null;
var dll_export_fns: ?bool = null; var dll_export_fns: ?bool = null;
@ -1595,7 +1595,7 @@ fn buildOutputType(
} }
} }
if (optimize_mode_string) |s| { if (optimize_mode_string) |s| {
optimize_mode = std.meta.stringToEnum(std.builtin.Mode, s) orelse optimize_mode = std.meta.stringToEnum(std.builtin.OptimizeMode, s) orelse
fatal("unrecognized optimization mode: '{s}'", .{s}); fatal("unrecognized optimization mode: '{s}'", .{s});
} }
}, },

View file

@ -441,7 +441,7 @@ pub fn hasDebugInfo(target: std.Target) bool {
return true; return true;
} }
pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.Mode { pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMode {
if (target.cpu.arch.isWasm() and target.os.tag == .freestanding) { if (target.cpu.arch.isWasm() and target.os.tag == .freestanding) {
return .ReleaseSmall; return .ReleaseSmall;
} else { } else {

View file

@ -74,7 +74,7 @@ pub const Case = struct {
/// In order to be able to run e.g. Execution updates, this must be set /// In order to be able to run e.g. Execution updates, this must be set
/// to Executable. /// to Executable.
output_mode: std.builtin.OutputMode, output_mode: std.builtin.OutputMode,
optimize_mode: std.builtin.Mode = .Debug, optimize_mode: std.builtin.OptimizeMode = .Debug,
updates: std.ArrayList(Update), updates: std.ArrayList(Update),
emit_bin: bool = true, emit_bin: bool = true,
emit_h: bool = false, emit_h: bool = false,

View file

@ -323,7 +323,7 @@ const Code = struct {
name: []const u8, name: []const u8,
source_token: Token, source_token: Token,
just_check_syntax: bool, just_check_syntax: bool,
mode: std.builtin.Mode, mode: std.builtin.OptimizeMode,
link_objects: []const []const u8, link_objects: []const []const u8,
target_str: ?[]const u8, target_str: ?[]const u8,
link_libc: bool, link_libc: bool,
@ -589,7 +589,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {s}", .{code_kind_str}); return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {s}", .{code_kind_str});
} }
var mode: std.builtin.Mode = .Debug; var mode: std.builtin.OptimizeMode = .Debug;
var link_objects = std.ArrayList([]const u8).init(allocator); var link_objects = std.ArrayList([]const u8).init(allocator);
defer link_objects.deinit(); defer link_objects.deinit();
var target_str: ?[]const u8 = null; var target_str: ?[]const u8 = null;