diff --git a/build.zig b/build.zig index daea8c1ca7..5c5c7cc0ae 100644 --- a/build.zig +++ b/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *Builder) !void { b.setPreferredReleaseMode(.ReleaseFast); const test_step = b.step("test", "Run all the tests"); const mode = b.standardReleaseOptions(); - const target = b.standardTargetOptions(.{}); + var target = b.standardTargetOptions(.{}); const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode"); const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false; @@ -141,6 +141,10 @@ pub fn build(b: *Builder) !void { break :blk 4; }; + if (only_c) { + target.ofmt = .c; + } + const main_file: ?[]const u8 = mf: { if (!have_stage1) break :mf "src/main.zig"; if (use_zig0) break :mf null; @@ -172,10 +176,6 @@ pub fn build(b: *Builder) !void { test_cases.want_lto = false; } - if (only_c) { - exe.ofmt = .c; - } - const exe_options = b.addOptions(); exe.addOptions("build_options", exe_options); diff --git a/lib/std/build.zig b/lib/std/build.zig index 3f903a0b12..8c6af98eea 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1622,7 +1622,6 @@ pub const LibExeObjStep = struct { use_stage1: ?bool = null, use_llvm: ?bool = null, use_lld: ?bool = null, - ofmt: ?std.Target.ObjectFormat = null, output_path_source: GeneratedFile, output_lib_path_source: GeneratedFile, @@ -2490,7 +2489,7 @@ pub const LibExeObjStep = struct { } } - if (self.ofmt) |ofmt| { + if (self.target.ofmt) |ofmt| { try zig_args.append(try std.fmt.allocPrint(builder.allocator, "-ofmt={s}", .{@tagName(ofmt)})); } diff --git a/test/tests.zig b/test/tests.zig index 266d2a37d0..81be2c9d5c 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -52,6 +52,9 @@ const test_targets = blk: { }, .{ + .target = .{ + .ofmt = .c, + }, .link_libc = true, .backend = .stage2_c, }, @@ -720,7 +723,6 @@ pub fn addPkgTests( .stage2_c => { these_tests.use_stage1 = false; these_tests.use_llvm = false; - these_tests.ofmt = .c; }, else => { these_tests.use_stage1 = false;