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;...@@ -16,12 +16,11 @@ const stack_size = 46 * 1024 * 1024;
1616
17pub fn build(b: *std.Build) !void {17pub fn build(b: *std.Build) !void {
18 const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;18 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: {19 const target = b.standardTargetOptions(.{
20 var default_target: std.Target.Query = .{};20 .default_target = .{
21 default_target.ofmt = b.option(std.Target.ObjectFormat, "ofmt", "Object format to target") orelse if (only_c) .c else null;21 .ofmt = if (only_c) .c else null,
22 break :t b.standardTargetOptions(.{ .default_target = default_target });22 },
23 };23 });
24
25 const optimize = b.standardOptimizeOption(.{});24 const optimize = b.standardOptimizeOption(.{});
2625
27 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;26 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...@@ -1635,13 +1635,18 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs
1635 "cpu",1635 "cpu",
1636 "Target CPU features to add or subtract",1636 "Target CPU features to add or subtract",
1637 );1637 );
1638 const ofmt = b.option(
1639 []const u8,
1640 "ofmt",
1641 "Target object format",
1642 );
1638 const dynamic_linker = b.option(1643 const dynamic_linker = b.option(
1639 []const u8,1644 []const u8,
1640 "dynamic-linker",1645 "dynamic-linker",
1641 "Path to interpreter on the target system",1646 "Path to interpreter on the target system",
1642 );1647 );
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)
1645 return args.default_target;1650 return args.default_target;
16461651
1647 const triple = maybe_triple orelse "native";1652 const triple = maybe_triple orelse "native";
...@@ -1649,6 +1654,7 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs...@@ -1649,6 +1654,7 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs
1649 const selected_target = parseTargetQuery(.{1654 const selected_target = parseTargetQuery(.{
1650 .arch_os_abi = triple,1655 .arch_os_abi = triple,
1651 .cpu_features = mcpu,1656 .cpu_features = mcpu,
1657 .object_format = ofmt,
1652 .dynamic_linker = dynamic_linker,1658 .dynamic_linker = dynamic_linker,
1653 }) catch |err| switch (err) {1659 }) catch |err| switch (err) {
1654 error.ParseFailed => {1660 error.ParseFailed => {