Skip to content

Commit 660965a

Browse files
committed
zig1.c: autodetect host target triple
instead of assuming x8_64-linux in CMake
1 parent 851a7a1 commit 660965a

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ set(BUILD_ZIG2_ARGS
731731
zig2
732732
"${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst"
733733
build-exe src/main.zig -ofmt=c -lc
734-
-target x86_64-linux-musl # TODO: autodetect in zig1.c
735734
-OReleaseFast
736735
)
737736

@@ -750,7 +749,6 @@ set(BUILD_COMPILER_RT_ARGS
750749
compiler_rt
751750
"${CMAKE_SOURCE_DIR}/stage1/zig1.wasm.zst"
752751
build-obj lib/compiler_rt.zig -ofmt=c
753-
-target x86_64-linux-musl # TODO: autodetect in zig1.c
754752
-OReleaseFast
755753
)
756754

stage1/zig1.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,38 @@
2222

2323
#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+
2557
enum wasi_errno_t {
2658
WASI_ESUCCESS = 0,
2759
WASI_E2BIG = 1,
@@ -4114,6 +4146,14 @@ int main(int argc, char **argv) {
41144146
new_argv_i += 1;
41154147
}
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+
41174157
if (isatty(STDERR_FILENO) != 0) {
41184158
new_argv[new_argv_i] = "--color";
41194159
new_argv_i += 1;

0 commit comments

Comments
 (0)