From a8932910d9cc2201214b3a0dc730c67765ede20f Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 25 Sep 2024 21:01:00 +0200 Subject: [PATCH] wasm32 / wasm64 targets are use-libc=no by default. --- .github/workflows/main.yml | 4 ++-- releasenotes.md | 1 + src/build/builder.c | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b95a98cb2..0931b25ba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -324,7 +324,7 @@ jobs: - name: Test WASM run: | cd resources/testfragments - ../../build/c3c compile --reloc=none --target wasm32 -g0 --link-libc=no --no-entry -Os wasm4.c3 + ../../build/c3c compile --target wasm32 -g0 --no-entry -Os wasm4.c3 - name: Install QEMU and Risc-V toolchain run: | @@ -558,7 +558,7 @@ jobs: - name: Test WASM run: | cd resources/testfragments - ../../build/c3c compile --reloc=none --target wasm32 -g0 --link-libc=no --no-entry -Os wasm4.c3 + ../../build/c3c compile --reloc=none --target wasm32 -g0 --no-entry -Os wasm4.c3 - name: Build testproject direct linker run: | diff --git a/releasenotes.md b/releasenotes.md index 52e88fa05..38b59acc1 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -26,6 +26,7 @@ - Deprecated inline generic types outside of struct definitions and macros unless marked `@adhoc`. - Improved method detection in earlier stages of checking. - Allow `^` suffix for non-recursive imports #1480. +- wasm32 / wasm64 targets are use-libc=no by default. ### Fixes - Issue where a lambda wasn't correctly registered as external. #1408 diff --git a/src/build/builder.c b/src/build/builder.c index 74f75c2a7..558818d7e 100644 --- a/src/build/builder.c +++ b/src/build/builder.c @@ -229,6 +229,43 @@ void update_build_target_with_opt_level(BuildTarget *target, OptimizationSetting COPY_IF_DEFAULT(target->single_module, single_module); } +static LinkLibc libc_from_arch_os(ArchOsTarget target) +{ + switch (target) + { + case ANDROID_AARCH64: + case FREEBSD_X86: + case FREEBSD_X64: + case IOS_AARCH64: + case LINUX_AARCH64: + case LINUX_RISCV32: + case LINUX_RISCV64: + case LINUX_X86: + case LINUX_X64: + case MACOS_AARCH64: + case MACOS_X64: + case MINGW_X64: + case NETBSD_X86: + case NETBSD_X64: + case OPENBSD_X86: + case OPENBSD_X64: + case WINDOWS_AARCH64: + case WINDOWS_X64: + return LINK_LIBC_ON; + case WASM32: + case WASM64: + case MCU_X86: + case ARCH_OS_TARGET_DEFAULT: + case ELF_AARCH64: + case ELF_RISCV32: + case ELF_RISCV64: + case ELF_X86: + case ELF_X64: + case ELF_XTENSA: + return LINK_LIBC_OFF; + } + UNREACHABLE +} static void update_build_target_from_options(BuildTarget *target, BuildOptions *options) { @@ -470,6 +507,10 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions * } if (target->optsetting == OPT_SETTING_NOT_SET) target->optsetting = OPT_SETTING_O0; update_build_target_with_opt_level(target, target->optsetting); + if (target->link_libc == LINK_LIBC_NOT_SET) + { + target->link_libc = libc_from_arch_os(target->arch_os_target); + } } void init_default_build_target(BuildTarget *target, BuildOptions *options)