authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-01-24 08:11:16+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-01-25 20:39:10+01:00
log015a5e198246f782415586235e0da7085867eb22
tree2622778ba47d3299438d510f0f1dd41572463788
parentd0d5ca2b6c8253c27e945ed8d973a90c28a3cbf5

std.Build: Make ofmt part of standardTargetOptions().


2 files changed, 12 insertions(+), 7 deletions(-)

build.zig+5-6
......@@ -16,12 +16,11 @@ const stack_size = 46 * 1024 * 1024;
1616
1717pub fn build(b: *std.Build) !void {
1818 const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
19 const target = t: {
20 var default_target: std.Target.Query = .{};
21 default_target.ofmt = b.option(std.Target.ObjectFormat, "ofmt", "Object format to target") orelse if (only_c) .c else null;
22 break :t b.standardTargetOptions(.{ .default_target = default_target });
23 };
24
19 const target = b.standardTargetOptions(.{
20 .default_target = .{
21 .ofmt = if (only_c) .c else null,
22 },
23 });
2524 const optimize = b.standardOptimizeOption(.{});
2625
2726 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;
lib/std/Build.zig+7-1
......@@ -1635,13 +1635,18 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs
16351635 "cpu",
16361636 "Target CPU features to add or subtract",
16371637 );
1638 const ofmt = b.option(
1639 []const u8,
1640 "ofmt",
1641 "Target object format",
1642 );
16381643 const dynamic_linker = b.option(
16391644 []const u8,
16401645 "dynamic-linker",
16411646 "Path to interpreter on the target system",
16421647 );
16431648
1644 if (maybe_triple == null and mcpu == null and dynamic_linker == null)
1649 if (maybe_triple == null and mcpu == null and ofmt == null and dynamic_linker == null)
16451650 return args.default_target;
16461651
16471652 const triple = maybe_triple orelse "native";
......@@ -1649,6 +1654,7 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs
16491654 const selected_target = parseTargetQuery(.{
16501655 .arch_os_abi = triple,
16511656 .cpu_features = mcpu,
1657 .object_format = ofmt,
16521658 .dynamic_linker = dynamic_linker,
16531659 }) catch |err| switch (err) {
16541660 error.ParseFailed => {