From bf3e0ca3795f8fb01ab36982237ad0d7e876e39b Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Thu, 11 Jun 2026 17:49:50 -0400 Subject: [PATCH] adds wasm64 (Memory64) as a first-class target (#25900) This pull request allows setting `--cpu:wasm64`, allowing wasm64 as a first class target. This avoids having to set `-cpu:riscv64` as a workaround. Sane defaults for the emscripten toolchain are also provided. (cherry picked from commit b44d373b7df1611b19594357b90002b1ac90df37) --- compiler/options.nim | 1 + compiler/platform.nim | 5 +++-- config/nim.cfg | 13 +++++++++++++ lib/system/platforms.nim | 4 +++- tools/nim.zsh-completion | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/compiler/options.nim b/compiler/options.nim index 2e7de72656..ba77a92e8d 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -650,6 +650,7 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool = of "x86": result = conf.target.targetCPU == cpuI386 of "itanium": result = conf.target.targetCPU == cpuIa64 of "x8664": result = conf.target.targetCPU == cpuAmd64 + of "wasm": result = conf.target.targetCPU in {cpuWasm32, cpuWasm64} of "posix", "unix": result = conf.target.targetOS in {osLinux, osMorphos, osSkyos, osIrix, osPalmos, osQnx, osAtari, osAix, diff --git a/compiler/platform.nim b/compiler/platform.nim index 4b99cd8936..62c8e3e90f 100644 --- a/compiler/platform.nim +++ b/compiler/platform.nim @@ -211,7 +211,7 @@ type cpuPowerpc64el, cpuSparc, cpuVm, cpuHppa, cpuIa64, cpuAmd64, cpuMips, cpuMipsel, cpuArm, cpuArm64, cpuJS, cpuNimVM, cpuAVR, cpuMSP430, cpuSparc64, cpuS390x, cpuMips64, cpuMips64el, cpuRiscV32, cpuRiscV64, - cpuEsp, cpuWasm32, cpuE2k, cpuLoongArch64 + cpuEsp, cpuWasm32, cpuE2k, cpuLoongArch64, cpuWasm64 type TInfoCPU* = tuple[name: string, intSize: int, endian: Endianness, @@ -249,7 +249,8 @@ const (name: "esp", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32), (name: "wasm32", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32), (name: "e2k", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64), - (name: "loongarch64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64)] + (name: "loongarch64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64), + (name: "wasm64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64)] type Target* = object diff --git a/config/nim.cfg b/config/nim.cfg index 038c3c9bec..6a259321fb 100644 --- a/config/nim.cfg +++ b/config/nim.cfg @@ -168,6 +168,19 @@ nimblepath="$home/.nimble/pkgs/" switch_gcc.cpp.options.always = "-g -Wall -O2 -ffunction-sections -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -D__SWITCH__ -fno-rtti -fno-exceptions -std=gnu++11" @end +# Emscripten toolchain for WebAssembly (wasm32, or wasm64/Memory64). +@if emscripten: + cc = clang + clang.exe = "emcc" + clang.linkerexe = "emcc" + clang.cpp.exe = "emcc" + clang.cpp.linkerexe = "emcc" + @if wasm64: + passC = "-sMEMORY64=1" + passL = "-sMEMORY64=1" + @end +@end + # Configuration for the Intel C/C++ compiler: @if windows: icl.options.speed = "/Ox /arch:SSE2" diff --git a/lib/system/platforms.nim b/lib/system/platforms.nim index 0619f3fcaa..17df7188f5 100644 --- a/lib/system/platforms.nim +++ b/lib/system/platforms.nim @@ -40,7 +40,8 @@ type wasm32, ## WASM, 32-bit e2k, ## MCST Elbrus 2000 loongarch64, ## LoongArch 64-bit processor - s390x ## IBM Z + s390x, ## IBM Z + wasm64 ## WASM, 64-bit OsPlatform* {.pure.} = enum ## the OS this program will run on. none, dos, windows, os2, linux, morphos, skyos, solaris, @@ -101,5 +102,6 @@ const elif defined(e2k): CpuPlatform.e2k elif defined(loongarch64): CpuPlatform.loongarch64 elif defined(s390x): CpuPlatform.s390x + elif defined(wasm64): CpuPlatform.wasm64 else: CpuPlatform.none ## the CPU this program will run on. diff --git a/tools/nim.zsh-completion b/tools/nim.zsh-completion index 2300cea033..0c34c660a2 100644 --- a/tools/nim.zsh-completion +++ b/tools/nim.zsh-completion @@ -78,7 +78,7 @@ _nim() { '--opt\:-[optimization mode]:x:(none speed size)' '--debugger\:native[use native debugger (gdb)]' '--app\:-[generate this type of app (lib=dynamic)]:x:(console gui lib staticlib)' - '--cpu\:-[target architecture]:x:(alpha amd64 arm arm64 avr e2k esp hppa i386 ia64 js loongarch64 m68k mips mipsel mips64 mips64el msp430 nimvm powerpc powerpc64 powerpc64el riscv32 riscv64 sparc sparc64 s390x vm wasm32)' + '--cpu\:-[target architecture]:x:(alpha amd64 arm arm64 avr e2k esp hppa i386 ia64 js loongarch64 m68k mips mipsel mips64 mips64el msp430 nimvm powerpc powerpc64 powerpc64el riscv32 riscv64 sparc sparc64 s390x vm wasm32 wasm64)' '--gc\:-[memory management algorithm to use (default\: refc)]:x:(refc arc orc markAndSweep boehm go regions none)' '--os\:-[operating system to compile for]:x:(AIX Amiga Android Any Atari DOS DragonFly FreeBSD FreeRTOS Genode Haiku iOS Irix JS Linux MacOS MacOSX MorphOS NetBSD Netware NimVM NintendoSwitch OS2 OpenBSD PalmOS Standalone QNX SkyOS Solaris VxWorks Windows)' '--panics\:-[turn panics into process termination (default\: off)]:x:(off on)'