diff --git a/eng/pipelines/common/global-build-job.yml b/eng/pipelines/common/global-build-job.yml index 95d61c4d6c6a..c9f9f749e9fb 100644 --- a/eng/pipelines/common/global-build-job.yml +++ b/eng/pipelines/common/global-build-job.yml @@ -177,8 +177,8 @@ jobs: df -h displayName: Disk Usage before Build - - ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.platform, 'browser_wasm_win')) }}: # Install Wasm dependencies: emscripten, LLVM, NodeJS + - ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.archType, 'wasm')) }}: - script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-emscripten.cmd $(Build.SourcesDirectory)\wasm-tools displayName: Install/activate emscripten - script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-llvm.cmd $(Build.SourcesDirectory)\wasm-tools $(Build.SourcesDirectory) ${{ parameters.buildConfig }} @@ -187,11 +187,7 @@ jobs: displayName: Install NodeJS - ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.platform, 'wasi_wasm_win')) }}: - # Install Wasi Wasm dependencies: emscripten, LLVM, wasi-sdk - - script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-emscripten.cmd $(Build.SourcesDirectory)\wasm-tools - displayName: Install/activate emscripten - - script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-llvm.cmd $(Build.SourcesDirectory)\wasm-tools $(Build.SourcesDirectory) ${{ parameters.buildConfig }} - displayName: Install/build LLVM + # Install Wasi Wasm dependencies: wasi-sdk, wasmer - script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-wasi-sdk.cmd $(Build.SourcesDirectory)\wasm-tools displayName: Install wasi-sdk - script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-wasmer.cmd $(Build.SourcesDirectory)\wasm-tools diff --git a/eng/pipelines/runtimelab/install-nodejs.ps1 b/eng/pipelines/runtimelab/install-nodejs.ps1 index 48a606739f44..4327ac43761c 100644 --- a/eng/pipelines/runtimelab/install-nodejs.ps1 +++ b/eng/pipelines/runtimelab/install-nodejs.ps1 @@ -1,5 +1,5 @@ $InstallPath = $Args[0] -$NodeJSVersion = "v18.16.0" +$NodeJSVersion = "v20.2.0" $NodeJSInstallName = "node-$NodeJSVersion-win-x64" $NodeJSZipName = "$NodeJSInstallName.zip" diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index c713a1c1e08d..0d83602097ba 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -168,11 +168,12 @@ extern "C" int __managed__Main(int argc, char* argv[]); #else #define NATIVEAOT_ENTRYPOINT __managed__Startup extern "C" void __managed__Startup(); + +#ifdef TARGET_WASI // _initialize is a function generated by the WASI SDK libc that calls the LLVM synthesized __wasm_call_ctors function for reactor components: // https://github.com/WebAssembly/wasi-libc/blob/9f51a7102085ec6a6ced5778f0864c9af9f50000/libc-bottom-half/crt/crt1-reactor.c#L7-L27 // We define and call it for NATIVEAOT_DLL and TARGET_WASI to call all the global c++ static constructors. This ensures the runtime is initialized -// when calling into WebAssembly Component Model components -#if defined(NATIVEAOT_DLL) && defined(TARGET_WASI) +// when calling into WebAssembly Component Model components. extern "C" void _initialize(); // CustomNativeMain programs are built using the same libbootstrapperdll as NATIVEAOT_DLL but wasi-libc will not provide an _initialize implementation, @@ -181,13 +182,20 @@ __attribute__((weak)) void _initialize() { } +// Guard the "_initialize" call so that well-behaving hosts do not get affected by this workaround. +static bool g_CalledInitialize = false; +struct WasiInitializationFlag { WasiInitializationFlag() { *(volatile bool*)&g_CalledInitialize = true; } }; +WasiInitializationFlag g_WasiInitializationFlag; #endif // TARGET_WASI #endif // !NATIVEAOT_DLL static int InitializeRuntime() { #if defined(NATIVEAOT_DLL) && defined(TARGET_WASI) - _initialize(); + if (!g_CalledInitialize) + { + _initialize(); + } #endif if (!RhInitialize()) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index 389f7cef6408..ea046c82edf7 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -116,7 +116,7 @@ The .NET Foundation licenses this file to you under the MIT license. -O2 -Oz - wasm32-wasi + wasm32-unknown-wasi @@ -371,10 +371,17 @@ The .NET Foundation licenses this file to you under the MIT license. + + + + + @@ -393,7 +400,7 @@ The .NET Foundation licenses this file to you under the MIT license. - -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -disable-lsr --sysroot="$(WASI_SDK_PATH)/share/wasi-sysroot" -target wasm32-wasi -c + -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -disable-lsr --sysroot="$(WASI_SDK_PATH)/share/wasi-sysroot" -target $(IlcLlvmTarget) -c $(CompileWasmArgs) $(WasmOptimizationSetting) $(CompileWasmArgs) -g3 @@ -413,11 +420,7 @@ The .NET Foundation licenses this file to you under the MIT license. - - - + + + + + + + + @@ -535,13 +545,7 @@ The .NET Foundation licenses this file to you under the MIT license. - - - - + - + diff --git a/src/tests/Common/scripts/nativeaottest.cmd b/src/tests/Common/scripts/nativeaottest.cmd index cf91085db3fb..09a52929d4ba 100644 --- a/src/tests/Common/scripts/nativeaottest.cmd +++ b/src/tests/Common/scripts/nativeaottest.cmd @@ -16,6 +16,11 @@ set __JsFileName=%2 set __JsFileName=%__JsFileName:~0,-4%.js set __JsFilePath=%1\native\%__JsFileName% +REM also probe for .mjs +if not exist %__JsFilePath% ( + set __JsFilePath=%__JsFilePath:~0,-3%.mjs +) + set __WasmFileName=%2 set __WasmFileName=%__WasmFileName:~0,-4%.wasm set __WasmFilePath=%1native\%__WasmFileName% diff --git a/src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.csproj b/src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.csproj index 1a8ad38bada3..d107e58e3f78 100644 --- a/src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.csproj +++ b/src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.csproj @@ -2,7 +2,6 @@ Exe BuildAndRun - 0 true