feat(dist): bundled-zig link backend for hermetic macOS/Linux/Windows builds
Drive a bundled `zig` as `zig cc` for the AOT link step, supplying lld + CRT + libc (musl/glibc/mingw) so `sx build` produces native binaries with no host toolchain. Default Linux output is static musl (portable-anywhere). - src/zig_backend.zig: discover zig ($SX_ZIG / bundled-next-to-exe / PATH); bundled-vs-PATH provenance gates auto-activation. - src/target.zig: selectZigLinker + emitZigLinkArgv + zigTargetTriple, dispatched before the per-OS branches; macOS/Linux/Windows in scope. - src/ir/emit_llvm.zig: LLVMNormalizeTargetTriple so vendor-less zig triples (e.g. x86_64-windows-gnu) parse to the correct OS/object format (COFF not ELF). - src/main.zig: --self-contained / --no-self-contained; linux-musl, linux-musl-arm, windows-gnu shorthands; de-vendor linux/linux-arm to match the corpus runner. - examples/1660: Windows Win32 print-42 + exit(0) via kernel32 (ir-only off-Windows). Auto-activates only for a bundled zig; a PATH-only zig engages under --self-contained, so native dev/CI builds are never silently rerouted. Docs: readme Cross-Compilation, design/bundled-zig-link-backend-design.md, current/PLAN-DIST.md.
This commit is contained in:
14
src/main.zig
14
src/main.zig
@@ -50,11 +50,17 @@ pub fn main(init: std.process.Init) !void {
|
||||
else if (std.mem.eql(u8, raw, "macos-x86"))
|
||||
try macosTripleForArch(allocator, "x86_64")
|
||||
else if (std.mem.eql(u8, raw, "linux") or std.mem.eql(u8, raw, "linux-x86"))
|
||||
"x86_64-unknown-linux-gnu"
|
||||
"x86_64-linux-gnu"
|
||||
else if (std.mem.eql(u8, raw, "linux-arm"))
|
||||
"aarch64-unknown-linux-gnu"
|
||||
"aarch64-linux-gnu"
|
||||
else if (std.mem.eql(u8, raw, "linux-musl"))
|
||||
"x86_64-linux-musl"
|
||||
else if (std.mem.eql(u8, raw, "linux-musl-arm"))
|
||||
"aarch64-linux-musl"
|
||||
else if (std.mem.eql(u8, raw, "windows"))
|
||||
"x86_64-windows-msvc"
|
||||
else if (std.mem.eql(u8, raw, "windows-gnu"))
|
||||
"x86_64-windows-gnu"
|
||||
else if (std.mem.eql(u8, raw, "ios") or std.mem.eql(u8, raw, "ios-arm"))
|
||||
"arm64-apple-ios14.0"
|
||||
else if (std.mem.eql(u8, raw, "ios-sim") or std.mem.eql(u8, raw, "ios-sim-arm"))
|
||||
@@ -88,6 +94,10 @@ pub fn main(init: std.process.Init) !void {
|
||||
i += 1;
|
||||
if (i >= args.len) { std.debug.print("error: --linker requires a value\n", .{}); return; }
|
||||
target_config.linker = args[i];
|
||||
} else if (std.mem.eql(u8, arg, "--self-contained")) {
|
||||
target_config.self_contained = .on;
|
||||
} else if (std.mem.eql(u8, arg, "--no-self-contained")) {
|
||||
target_config.self_contained = .off;
|
||||
} else if (std.mem.eql(u8, arg, "--sysroot")) {
|
||||
i += 1;
|
||||
if (i >= args.len) { std.debug.print("error: --sysroot requires a value\n", .{}); return; }
|
||||
|
||||
Reference in New Issue
Block a user