Commit 015a5e1982
lib/std/Build.zig
@@ -1635,13 +1635,18 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs
"cpu",
"Target CPU features to add or subtract",
);
+ const ofmt = b.option(
+ []const u8,
+ "ofmt",
+ "Target object format",
+ );
const dynamic_linker = b.option(
[]const u8,
"dynamic-linker",
"Path to interpreter on the target system",
);
- if (maybe_triple == null and mcpu == null and dynamic_linker == null)
+ if (maybe_triple == null and mcpu == null and ofmt == null and dynamic_linker == null)
return args.default_target;
const triple = maybe_triple orelse "native";
@@ -1649,6 +1654,7 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs
const selected_target = parseTargetQuery(.{
.arch_os_abi = triple,
.cpu_features = mcpu,
+ .object_format = ofmt,
.dynamic_linker = dynamic_linker,
}) catch |err| switch (err) {
error.ParseFailed => {
build.zig
@@ -16,12 +16,11 @@ const stack_size = 46 * 1024 * 1024;
pub fn build(b: *std.Build) !void {
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
- const target = t: {
- var default_target: std.Target.Query = .{};
- default_target.ofmt = b.option(std.Target.ObjectFormat, "ofmt", "Object format to target") orelse if (only_c) .c else null;
- break :t b.standardTargetOptions(.{ .default_target = default_target });
- };
-
+ const target = b.standardTargetOptions(.{
+ .default_target = .{
+ .ofmt = if (only_c) .c else null,
+ },
+ });
const optimize = b.standardOptimizeOption(.{});
const flat = b.option(bool, "flat", "Put files into the installation prefix in a manner suited for upstream distribution rather than a posix file system hierarchy standard") orelse false;