authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-15 23:19:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:15:04-07:00
log33e3db11fece0a60b226f5d301657ce4294e4ab5
treec3ffa2584a86528deb4015dbdba8d9c0fb39aced
parent34e9bbb9d46babecb8c8e5d694b934186654982b

zig1.c: autodetect host target triple

instead of assuming x8_64-linux in CMake

2 files changed, 40 insertions(+), 2 deletions(-)

CMakeLists.txt-2
...@@ -731,7 +731,6 @@ set(BUILD_ZIG2_ARGS...@@ -731,7 +731,6 @@ set(BUILD_ZIG2_ARGS
731 zig2731 zig2
732 "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst"732 "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst"
733 build-exe src/main.zig -ofmt=c -lc733 build-exe src/main.zig -ofmt=c -lc
734 -target x86_64-linux-musl # TODO: autodetect in zig1.c
735 -OReleaseFast734 -OReleaseFast
736)735)
737 736
...@@ -750,7 +749,6 @@ set(BUILD_COMPILER_RT_ARGS...@@ -750,7 +749,6 @@ set(BUILD_COMPILER_RT_ARGS
750 compiler_rt749 compiler_rt
751 "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst"750 "${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst"
752 build-obj lib/compiler_rt.zig -ofmt=c751 build-obj lib/compiler_rt.zig -ofmt=c
753 -target x86_64-linux-musl # TODO: autodetect in zig1.c
754 -OReleaseFast752 -OReleaseFast
755)753)
756 754
stage1/zig1.c+40
...@@ -22,6 +22,38 @@...@@ -22,6 +22,38 @@
2222
23#include <zstd.h>23#include <zstd.h>
2424
25#if defined(__APPLE__)
26#define ZIG_TRIPLE_OS "macos"
27#elif defined(_WIN32)
28#define ZIG_TRIPLE_OS "windows"
29#elif defined(__linux__)
30#define ZIG_TRIPLE_OS "linux"
31#elif defined(__FreeBSD__)
32#define ZIG_TRIPLE_OS "freebsd"
33#elif defined(__NetBSD__)
34#define ZIG_TRIPLE_OS "netbsd"
35#elif defined(__DragonFly__)
36#define ZIG_TRIPLE_OS "dragonfly"
37#elif defined(__OpenBSD__)
38#define ZIG_TRIPLE_OS "openbsd"
39#elif defined(__HAIKU__)
40#define ZIG_TRIPLE_OS "haiku"
41#elif defined(__sun)
42#define ZIG_TRIPLE_OS "solaris"
43#else
44#error please add more os definitions above this line
45#endif
46
47#if defined(__x86_64__)
48#define ZIG_TRIPLE_ARCH "x86_64"
49#elif defined(__aarch64__)
50#define ZIG_TRIPLE_ARCH "aarch64"
51#elif defined(__ARM_EABI__)
52#define ZIG_TRIPLE_ARCH "arm"
53#else
54#error please add more arch definitions above this line
55#endif
56
25enum wasi_errno_t {57enum wasi_errno_t {
26 WASI_ESUCCESS = 0,58 WASI_ESUCCESS = 0,
27 WASI_E2BIG = 1,59 WASI_E2BIG = 1,
...@@ -4114,6 +4146,14 @@ int main(int argc, char **argv) {...@@ -4114,6 +4146,14 @@ int main(int argc, char **argv) {
4114 new_argv_i += 1;4146 new_argv_i += 1;
4115 }4147 }
41164148
4149 {
4150 new_argv[new_argv_i] = "-target";
4151 new_argv_i += 1;
4152
4153 new_argv[new_argv_i] = ZIG_TRIPLE_ARCH "-" ZIG_TRIPLE_OS;
4154 new_argv_i += 1;
4155 }
4156
4117 if (isatty(STDERR_FILENO) != 0) {4157 if (isatty(STDERR_FILENO) != 0) {
4118 new_argv[new_argv_i] = "--color";4158 new_argv[new_argv_i] = "--color";
4119 new_argv_i += 1;4159 new_argv_i += 1;