diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index 4a6bd162063682..d48996ac579dbe 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -2,26 +2,38 @@ rem rem This file invokes cmake and generates the build system for windows. -setlocal +set __argCount=0 +for %%x in (%*) do set /A __argCount+=1 -set argC=0 -for %%x in (%*) do Set /A argC+=1 +if %__argCount% lss 4 goto :USAGE +if %1=="/?" goto :USAGE -if %argC% lss 4 GOTO :USAGE -if %1=="/?" GOTO :USAGE - -setlocal enabledelayedexpansion +set __Os=%5 set "__repoRoot=%~dp0..\.." :: normalize for %%i in ("%__repoRoot%") do set "__repoRoot=%%~fi" +:: Set up the EMSDK environment before setlocal so that it propagates to the caller. +if /i "%__Os%" == "browser" ( + if "%EMSDK_PATH%" == "" ( + if not exist "%__repoRoot%\src\mono\browser\emsdk" ( + echo Error: Should set EMSDK_PATH environment variable pointing to emsdk root. + exit /B 1 + ) + set EMSDK_QUIET=1 && call "%__repoRoot%\src\mono\browser\emsdk\emsdk_env" + ) else ( + set EMSDK_QUIET=1 && call "%EMSDK_PATH%\emsdk_env" + ) +) + +setlocal enabledelayedexpansion + set __SourceDir=%1 set __IntermediatesDir=%2 set __VSVersion=%3 set __Arch=%4 -set __Os=%5 set __CmakeGenerator=Visual Studio -set __UseEmcmake=0 +set __ExtraCmakeParams= if /i "%__Ninja%" == "1" ( set __CmakeGenerator=Ninja ) else ( @@ -38,22 +50,14 @@ if /i "%__Ninja%" == "1" ( ) if /i "%__Arch%" == "wasm" ( - if "%__Os%" == "" ( echo Error: Please add target OS parameter exit /B 1 ) if /i "%__Os%" == "browser" ( - if "%EMSDK_PATH%" == "" ( - echo Error: Should set EMSDK_PATH environment variable pointing to emsdk root. - exit /B 1 - ) - set CMakeToolPrefix=emcmake ) if /i "%__Os%" == "wasi" ( - set "__repoRoot=!__repoRoot:\=/!" - if not "!__repoRoot:~-1!" == "/" set "__repoRoot=!__repoRoot!/" if "%WASI_SDK_PATH%" == "" ( if not exist "%__repoRoot%\src\mono\wasi\wasi-sdk" ( echo Error: Should set WASI_SDK_PATH environment variable pointing to WASI SDK root. @@ -62,11 +66,8 @@ if /i "%__Arch%" == "wasm" ( set "WASI_SDK_PATH=%__repoRoot%\src\mono\wasi\wasi-sdk" ) - :: replace backslash with forward slash and append last slash - set "WASI_SDK_PATH=!WASI_SDK_PATH:\=/!" - if not "!WASI_SDK_PATH:~-1!" == "/" set "WASI_SDK_PATH=!WASI_SDK_PATH!/" set __CmakeGenerator=Ninja - set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm "-DWASI_SDK_PREFIX=!WASI_SDK_PATH!" "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_SYSROOT=!WASI_SDK_PATH!share/wasi-sysroot" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1" + set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1" ) ) else ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0" @@ -140,6 +141,6 @@ exit /B %errorlevel% :USAGE echo "Usage..." echo "gen-buildsys.cmd " - echo "Specify the path to the top level CMake file - /src/NDP" - echo "Specify the VSVersion to be used - VS2017 or VS2019" + echo "Specify the path to the top level CMake file" + echo "Specify the VSVersion to be used, e. g. 17.0 for VS2022" EXIT /B 1 diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index d4028cb9577ade..588a1cc6509799 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -97,9 +97,26 @@ fi cmake_extra_defines_wasm=() if [[ "$host_arch" == "wasm" ]]; then if [[ "$target_os" == "browser" ]]; then + if [[ -z "$EMSDK_PATH" ]]; then + if [[ -d "$reporoot"/src/mono/browser/emsdk/ ]]; then + export EMSDK_PATH="$reporoot"/src/mono/browser/emsdk/ + else + echo "Error: You need to set the EMSDK_PATH environment variable pointing to the emscripten SDK root." + exit 1 + fi + fi + export EMSDK_QUIET=1 && source "$EMSDK_PATH"/emsdk_env.sh cmake_command="emcmake $cmake_command" elif [[ "$target_os" == "wasi" ]]; then - cmake_extra_defines_wasm=("-DCLR_CMAKE_TARGET_OS=wasi" "-DCLR_CMAKE_TARGET_ARCH=wasm" "-DWASI_SDK_PREFIX=$WASI_SDK_PATH" "-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_SYSROOT=${WASI_SDK_PATH}/share/wasi-sysroot" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1") + if [[ -z "$WASI_SDK_PATH" ]]; then + if [[ -d "$reporoot"/src/mono/wasi/wasi-sdk ]]; then + export WASI_SDK_PATH="$reporoot"/src/mono/wasi/wasi-sdk + else + echo "Error: You need to set the WASI_SDK_PATH environment variable pointing to the WASI SDK root." + exit 1 + fi + fi + cmake_extra_defines_wasm=("-DCLR_CMAKE_TARGET_OS=wasi" "-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1") else echo "target_os was not specified" exit 1 diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index efe3c5bf21cb4a..f18b970698520d 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -109,8 +109,6 @@ <_CoreClrBuildScript Condition="$([MSBuild]::IsOsPlatform(Windows))">build-runtime.cmd <_CoreClrBuildScript Condition="!$([MSBuild]::IsOsPlatform(Windows))">build-runtime.sh <_CoreClrBuildCommand>"$(MSBuildThisFileDirectory)$(_CoreClrBuildScript)" @(_CoreClrBuildArg, ' ') - <_CoreClrBuildCommand Condition="'$(TargetsBrowser)' == 'true' and $([MSBuild]::IsOsPlatform(Windows))">call "$([MSBuild]::NormalizePath('$(RepoRoot)src/mono/browser/emsdk', 'emsdk_env.cmd'))" && $(_CoreClrBuildCommand) - <_CoreClrBuildCommand Condition="'$(TargetsBrowser)' == 'true' and !$([MSBuild]::IsOsPlatform(Windows))">bash -c 'source "$(RepoRoot)src/mono/browser/emsdk/emsdk_env.sh" && $(_CoreClrBuildCommand)' diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index cf8b2b47fbd67b..4061e33130e8e0 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -119,10 +119,6 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) add_subdirectory(System.IO.Ports.Native) endif () - if (MONO_WASM_MT) - add_definitions(-DMONO_WASM_MT) - endif() - if (CMAKE_C_COMPILER_ID MATCHES "Clang") add_compile_options(-Weverything) add_compile_options(-Wno-format-nonliteral) diff --git a/src/native/libs/build-native.cmd b/src/native/libs/build-native.cmd index 8dd3ad108dee0b..232b7d95b30d6d 100644 --- a/src/native/libs/build-native.cmd +++ b/src/native/libs/build-native.cmd @@ -19,7 +19,6 @@ set __TargetOS=windows set CMAKE_BUILD_TYPE=Debug set __Ninja=1 set __icuDir="" -set __usePThreads=0 set __ExtraCmakeParams= set __CrossTarget=0 @@ -39,15 +38,11 @@ if /i [%1] == [wasm] ( set __BuildArch=wasm&&shift&goto Arg_Loop) if /i [%1] == [outconfig] ( set __outConfig=%2&&shift&&shift&goto Arg_Loop) -if /i [%1] == [browser] ( set __TargetOS=browser&&shift&goto Arg_Loop) -if /i [%1] == [wasi] ( set __TargetOS=wasi&&shift&goto Arg_Loop) - if /i [%1] == [rebuild] ( set __BuildTarget=rebuild&&shift&goto Arg_Loop) if /i [%1] == [msbuild] ( set __Ninja=0&&shift&goto Arg_Loop) if /i [%1] == [icudir] ( set __icuDir=%2&&shift&&shift&goto Arg_Loop) -if /i [%1] == [usepthreads] ( set __usePThreads=1&&shift&goto Arg_Loop) if /i [%1] == [-fsanitize] ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLR_CMAKE_ENABLE_SANITIZERS=$2"&&shift&&shift&goto Arg_Loop) if /i [%1] == [-cmakeargs] ( set __ExtraCmakeParams=%__ExtraCmakeParams% %2&&shift&&shift&goto Arg_Loop) @@ -77,16 +72,11 @@ if %__CrossTarget% EQU 0 ( call powershell -NoProfile -ExecutionPolicy ByPass -File "%__repoRoot%\eng\native\version\copy_version_files.ps1" ) -:: cmake requires forward slashes in paths -set __cmakeRepoRoot=%__repoRoot:\=/% -set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_REPO_ROOT=%__cmakeRepoRoot%" set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%" if NOT %__icuDir% == "" ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_ICU_DIR=%__icuDir%" ) -set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_USE_PTHREADS=%__usePThreads%" - if [%__outConfig%] == [] set __outConfig=%__TargetOS%-%__BuildArch%-%CMAKE_BUILD_TYPE% diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index 32965c2e584c58..4bb1f0164d9e83 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -13,13 +13,13 @@ <_RuntimeVariant /> <_RuntimeVariant Condition="'$(WasmEnableThreads)' == 'true'">-threads - <_UsePThreads /> - <_UsePThreads Condition="'$(WasmEnableThreads)' == 'true'"> usepthreads - <_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native <_IcuDirArg Condition="'$(_IcuDir)' != ''"> icudir "$(_IcuDir)" - <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_UsePThreads) + <_CMakeArgs Condition="'$(CMakeArgs)' != ''"> -cmakeargs "$(CMakeArgs)" + <_CMakeArgs Condition="'$(WasmEnableThreads)' == 'true'">$(_CMakeArgs) -cmakeargs "-DCMAKE_USE_PTHREADS=1" + + <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_CMakeArgs) @@ -50,17 +50,14 @@ <_PortableBuildArg Condition="'$(PortableBuild)' != 'true'"> -portablebuild=false <_CrossBuildArg Condition="'$(CrossBuild)' == 'true'"> -cross <_KeepNativeSymbolsBuildArg Condition="'$(KeepNativeSymbols)' != 'false'"> -keepnativesymbols - <_MonoWasmMTCMakeArgs Condition="'$(WasmEnableThreads)' == 'true'"> -DMONO_WASM_MT=1 - <_CMakeArgs Condition="'$(CMakeArgs)' != '' or '$(_MonoWasmMTCMakeArgs)' != ''"> -cmakeargs "$(CMakeArgs)$(_MonoWasmMTCMakeArgs)" <_BuildNativeCompilerArg Condition="'$(BuildNativeCompiler)' != ''"> $(BuildNativeCompiler) - <_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessorCountArg)$(_PortableBuildArg)$(_CrossBuildArg)$(_BuildNativeCompilerArg)$(_KeepNativeSymbolsBuildArg)$(_CMakeArgs) $(Compiler) + <_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessorCountArg)$(_PortableBuildArg)$(_CrossBuildArg)$(_BuildNativeCompilerArg)$(_KeepNativeSymbolsBuildArg) $(Compiler) <_BuildNativeBuildCommand>"$(MSBuildThisFileDirectory)build-native.sh" $(_BuildNativeUnixArgs) - <_BuildNativeBuildCommand Condition="'$(TargetsBrowser)' == 'true'">bash -c 'source "$(RepoRoot)src/mono/browser/emsdk/emsdk_env.sh" && $(_BuildNativeBuildCommand)' @@ -100,11 +97,7 @@ Condition="$([MSBuild]::IsOsPlatform(Windows))"> <_BuildNativeArgs Condition="'$(Ninja)' == 'false'">$(_BuildNativeArgs) msbuild - <_MonoWasmMTCMakeArgs Condition="'$(WasmEnableThreads)' == 'true'">-DMONO_WASM_MT=1 - <_MonoWasmMTCMakeArgs Condition="'$(CMakeArgs)' != ''"> $(_MonoWasmMTCMakeArgs) - <_BuildNativeArgs Condition="'$(CMakeArgs)' != '' or '$(_MonoWasmMTCMakeArgs)' != ''">$(_BuildNativeArgs) -cmakeargs "$(CMakeArgs)$(_MonoWasmMTCMakeArgs)" <_BuildNativeBuildCommand>"$(MSBuildThisFileDirectory)build-native.cmd" $(_BuildNativeArgs) - <_BuildNativeBuildCommand Condition="'$(TargetsBrowser)' == 'true'">call "$([MSBuild]::NormalizePath('$(RepoRoot)src/mono/browser/emsdk', 'emsdk_env.cmd'))" && $(_BuildNativeBuildCommand) diff --git a/src/native/libs/build-native.sh b/src/native/libs/build-native.sh index 5055b05839de15..51d24980e7e9cb 100755 --- a/src/native/libs/build-native.sh +++ b/src/native/libs/build-native.sh @@ -21,10 +21,6 @@ handle_arguments() { __ShiftArgs=1 ;; - usepthreads|-usepthreads) - __usePThreads=1 - ;; - staticliblink|-staticliblink) __StaticLibLink=1 ;; @@ -48,36 +44,11 @@ __StaticLibLink=0 __UnprocessedBuildArgs= __VerboseBuild=false __icuDir="" -__usePThreads=0 source "$__RepoRootDir"/eng/native/build-commons.sh # Set cross build -if [[ "$__TargetOS" == browser ]]; then - if [[ -z "$EMSDK_PATH" ]]; then - if [[ -d "$__RepoRootDir"/src/mono/browser/emsdk/ ]]; then - export EMSDK_PATH="$__RepoRootDir"/src/mono/browser/emsdk/ - else - echo "Error: You need to set the EMSDK_PATH environment variable pointing to the emscripten SDK root." - exit 1 - fi - fi - source "$EMSDK_PATH"/emsdk_env.sh - export CLR_CC=$(which emcc) -elif [[ "$__TargetOS" == wasi ]]; then - if [[ -z "$WASI_SDK_PATH" ]]; then - if [[ -d "$__RepoRootDir"/src/mono/wasi/wasi-sdk ]]; then - export WASI_SDK_PATH="$__RepoRootDir"/src/mono/wasi/wasi-sdk - else - echo "Error: You need to set the WASI_SDK_PATH environment variable pointing to the WASI SDK root." - exit 1 - fi - fi - export WASI_SDK_PATH="${WASI_SDK_PATH%/}/" - export CLR_CC="$WASI_SDK_PATH"bin/clang - export TARGET_BUILD_ARCH=wasm - __CMakeArgs="-DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm -DWASI_SDK_PREFIX=$WASI_SDK_PATH -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-p2.cmake $__CMakeArgs" -elif [[ "$__TargetOS" == ios || "$__TargetOS" == iossimulator ]]; then +if [[ "$__TargetOS" == browser || "$__TargetOS" == wasi || "$__TargetOS" == ios || "$__TargetOS" == iossimulator ]]; then # nothing to do here true elif [[ "$__TargetOS" == tvos || "$__TargetOS" == tvossimulator ]]; then @@ -158,7 +129,6 @@ fi if [[ -n "$__icuDir" ]]; then __CMakeArgs="-DCMAKE_ICU_DIR=\"$__icuDir\" $__CMakeArgs" fi -__CMakeArgs="-DCMAKE_USE_PTHREADS=$__usePThreads $__CMakeArgs" # Set the remaining variables based upon the determined build configuration __outConfig="${__outConfig:-"$__TargetOS-$__TargetArch-$__BuildType"}" diff --git a/src/native/minipal/descriptorlimit.c b/src/native/minipal/descriptorlimit.c index b1550fdc8f74e3..e0605552705d7a 100644 --- a/src/native/minipal/descriptorlimit.c +++ b/src/native/minipal/descriptorlimit.c @@ -13,7 +13,7 @@ bool minipal_increase_descriptor_limit(void) { -#if TARGET_WASM +#ifdef __wasm__ // WebAssembly cannot set limits #elif TARGET_LINUX_MUSL // Setting RLIMIT_NOFILE breaks debugging of coreclr on Alpine Linux for some reason diff --git a/src/native/minipal/memorybarrierprocesswide.c b/src/native/minipal/memorybarrierprocesswide.c index b2fcad9ef789c0..7582332f86c9e9 100644 --- a/src/native/minipal/memorybarrierprocesswide.c +++ b/src/native/minipal/memorybarrierprocesswide.c @@ -2,14 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. #ifndef HOST_WINDOWS -#include -#include + #include #include +#include +#include + +#ifndef HOST_WASM +#include #include #include #include -#include #ifdef __APPLE__ #include @@ -72,7 +75,7 @@ static bool CanFlushUsingMembarrier(void) static bool s_flushUsingMemBarrier = false; #endif // HAVE_SYS_MEMBARRIER_H -#if !defined(HOST_APPLE) && !defined(HOST_WASM) +#ifndef HOST_APPLE // Helper memory page used by the fallback path static uint8_t* g_helperPage = NULL; @@ -80,7 +83,8 @@ static uint8_t* g_helperPage = NULL; static pthread_mutex_t g_flushProcessWriteBuffersMutex; static size_t s_pageSize = 0; -#endif // !TARGET_APPLE && !HOST_WASM +#endif // !HOST_APPLE +#endif // !HOST_WASM static bool s_initializedMemoryBarrierSuccessfullyInitialized = false; diff --git a/src/native/minipal/thread.h b/src/native/minipal/thread.h index 48405dfb3195ae..a407cf28c69c60 100644 --- a/src/native/minipal/thread.h +++ b/src/native/minipal/thread.h @@ -43,7 +43,7 @@ extern "C" { */ static inline size_t minipal_get_current_thread_id(void) { -#if defined(__wasm) && defined(MONO_WASM_MT) +#if defined(__wasm) && !defined(_REENTRANT) return 0; #else #if defined(__GNUC__) && !defined(__clang__) && defined(__cplusplus)