← Files ISA-L ZipARCHIVED FILE

native/build/cc-wrapper/main.go

994 Bytes · Nov 30, 2026 · 00:22 UTC

↓ Download file

// Copyright (c) 2026 Tarek Wasfy. Licensed under MIT.
// Small CMake/Go cgo compiler driver for Zig's C cross-compiler.
package main

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
)

func main() {
	z := os.Getenv("ISA_ZIG")
	if z == "" {
		fmt.Fprintln(os.Stderr, "ISA_ZIG must point to zig.exe")
		os.Exit(2)
	}
	name := filepath.Base(os.Args[0])
	var args []string
	switch name {
	case "cc-win.exe":
		args = []string{"cc", "-target", "x86_64-windows-gnu"}
	case "cc-linux.exe":
		args = []string{"cc", "-target", "x86_64-linux-musl"}
	case "ar.exe":
		args = []string{"ar"}
	case "ranlib.exe":
		args = []string{"ranlib"}
	default:
		fmt.Fprintln(os.Stderr, "unknown wrapper name", name)
		os.Exit(2)
	}
	cmd := exec.Command(z, append(args, os.Args[1:]...)...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	if err := cmd.Run(); err != nil {
		if e, ok := err.(*exec.ExitError); ok {
			os.Exit(e.ExitCode())
		}
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}
}

SHA-256: 9fcafe2c4e8c3f41d20ec7f00570523c59efde1da49ddbb7689dc227fdbdef81