zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 33e3db11fece0a60b226f5d301657ce4294e4ab5 (tree)
parent 34e9bbb9d46babecb8c8e5d694b934186654982b
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue, 15 Nov 2022 23:19:24 -0700

zig1.c: autodetect host target triple

instead of assuming x8_64-linux in CMake

Diffstat:
MCMakeLists.txt | 2--
Mstage1/zig1.c | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -731,7 +731,6 @@ set(BUILD_ZIG2_ARGS zig2 "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst" build-exe src/main.zig -ofmt=c -lc - -target x86_64-linux-musl # TODO: autodetect in zig1.c -OReleaseFast ) @@ -750,7 +749,6 @@ set(BUILD_COMPILER_RT_ARGS compiler_rt "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst" build-obj lib/compiler_rt.zig -ofmt=c - -target x86_64-linux-musl # TODO: autodetect in zig1.c -OReleaseFast ) diff --git a/stage1/zig1.c b/stage1/zig1.c @@ -22,6 +22,38 @@ #include <zstd.h> +#if defined(__APPLE__) +#define ZIG_TRIPLE_OS "macos" +#elif defined(_WIN32) +#define ZIG_TRIPLE_OS "windows" +#elif defined(__linux__) +#define ZIG_TRIPLE_OS "linux" +#elif defined(__FreeBSD__) +#define ZIG_TRIPLE_OS "freebsd" +#elif defined(__NetBSD__) +#define ZIG_TRIPLE_OS "netbsd" +#elif defined(__DragonFly__) +#define ZIG_TRIPLE_OS "dragonfly" +#elif defined(__OpenBSD__) +#define ZIG_TRIPLE_OS "openbsd" +#elif defined(__HAIKU__) +#define ZIG_TRIPLE_OS "haiku" +#elif defined(__sun) +#define ZIG_TRIPLE_OS "solaris" +#else +#error please add more os definitions above this line +#endif + +#if defined(__x86_64__) +#define ZIG_TRIPLE_ARCH "x86_64" +#elif defined(__aarch64__) +#define ZIG_TRIPLE_ARCH "aarch64" +#elif defined(__ARM_EABI__) +#define ZIG_TRIPLE_ARCH "arm" +#else +#error please add more arch definitions above this line +#endif + enum wasi_errno_t { WASI_ESUCCESS = 0, WASI_E2BIG = 1, @@ -4114,6 +4146,14 @@ int main(int argc, char **argv) { new_argv_i += 1; } + { + new_argv[new_argv_i] = "-target"; + new_argv_i += 1; + + new_argv[new_argv_i] = ZIG_TRIPLE_ARCH "-" ZIG_TRIPLE_OS; + new_argv_i += 1; + } + if (isatty(STDERR_FILENO) != 0) { new_argv[new_argv_i] = "--color"; new_argv_i += 1;