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:
@@ -255,10 +255,16 @@ pub const LLVMEmitter = struct {
|
||||
const llvm_module = c.LLVMModuleCreateWithNameInContext(module_name, ctx);
|
||||
const builder = c.LLVMCreateBuilderInContext(ctx);
|
||||
|
||||
// Set target triple
|
||||
const triple_owned = target_config.triple == null;
|
||||
const triple = target_config.triple orelse c.LLVMGetDefaultTargetTriple();
|
||||
defer if (triple_owned) c.LLVMDisposeMessage(@constCast(triple));
|
||||
// Set target triple. Normalize first: zig-scheme, vendor-less triples
|
||||
// (e.g. "x86_64-windows-gnu") would otherwise have "windows" land in
|
||||
// LLVM's vendor slot under its positional parser, leaving OS=unknown
|
||||
// and the object format silently falling back to ELF. Normalization is
|
||||
// LLVM's own reordering — not a hand-maintained translation table.
|
||||
const raw_owned = target_config.triple == null;
|
||||
const raw_triple = target_config.triple orelse c.LLVMGetDefaultTargetTriple();
|
||||
defer if (raw_owned) c.LLVMDisposeMessage(@constCast(raw_triple));
|
||||
const triple = c.LLVMNormalizeTargetTriple(raw_triple);
|
||||
defer c.LLVMDisposeMessage(triple);
|
||||
|
||||
c.LLVMSetTarget(llvm_module, triple);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user