Function standardTargetOptionsQueryOnly [src]

Exposes standard zig build options for choosing a target.

Prototype

pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs) Target.Query

Parameters

b: *Buildargs: StandardTargetOptionsArgs

Source

pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs) Target.Query { const maybe_triple = b.option( []const u8, "target", "The CPU architecture, OS, and ABI to build for", ); const mcpu = b.option( []const u8, "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 ofmt == null and dynamic_linker == null) return args.default_target; const triple = maybe_triple orelse "native"; const selected_target = parseTargetQuery(.{ .arch_os_abi = triple, .cpu_features = mcpu, .object_format = ofmt, .dynamic_linker = dynamic_linker, }) catch |err| switch (err) { error.ParseFailed => { b.markInvalidUserInput(); return args.default_target; }, }; const whitelist = args.whitelist orelse return selected_target; // Make sure it's a match of one of the list. for (whitelist) |q| { if (q.eql(selected_target)) return selected_target; } for (whitelist) |q| { log.info("allowed target: -Dtarget={s} -Dcpu={s}", .{ q.zigTriple(b.allocator) catch @panic("OOM"), q.serializeCpuAlloc(b.allocator) catch @panic("OOM"), }); } log.err("chosen target '{s}' does not match one of the allowed targets", .{ selected_target.zigTriple(b.allocator) catch @panic("OOM"), }); b.markInvalidUserInput(); return args.default_target; }