Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions eng/native/gen-buildsys.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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.
Expand All @@ -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"
Expand Down Expand Up @@ -140,6 +141,6 @@ exit /B %errorlevel%
:USAGE
echo "Usage..."
echo "gen-buildsys.cmd <path to top level CMakeLists.txt> <path to location for intermediate files> <VSVersion> <arch> <os>"
echo "Specify the path to the top level CMake file - <ProjectK>/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
19 changes: 18 additions & 1 deletion eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@
<_CoreClrBuildScript Condition="$([MSBuild]::IsOsPlatform(Windows))">build-runtime.cmd</_CoreClrBuildScript>
<_CoreClrBuildScript Condition="!$([MSBuild]::IsOsPlatform(Windows))">build-runtime.sh</_CoreClrBuildScript>
<_CoreClrBuildCommand>&quot;$(MSBuildThisFileDirectory)$(_CoreClrBuildScript)&quot; @(_CoreClrBuildArg, ' ')</_CoreClrBuildCommand>
<_CoreClrBuildCommand Condition="'$(TargetsBrowser)' == 'true' and $([MSBuild]::IsOsPlatform(Windows))">call &quot;$([MSBuild]::NormalizePath('$(RepoRoot)src/mono/browser/emsdk', 'emsdk_env.cmd'))&quot; &amp;&amp; $(_CoreClrBuildCommand)</_CoreClrBuildCommand>
<_CoreClrBuildCommand Condition="'$(TargetsBrowser)' == 'true' and !$([MSBuild]::IsOsPlatform(Windows))">bash -c 'source &quot;$(RepoRoot)src/mono/browser/emsdk/emsdk_env.sh&quot; &amp;&amp; $(_CoreClrBuildCommand)'</_CoreClrBuildCommand>
</PropertyGroup>

<!-- Use IgnoreStandardErrorWarningFormat because Arcade sets WarnAsError and we want to avoid upgrading compiler warnings to errors in release branches -->
Expand Down
4 changes: 0 additions & 4 deletions src/native/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions src/native/libs/build-native.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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%

Expand Down
17 changes: 5 additions & 12 deletions src/native/libs/build-native.proj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

<_RuntimeVariant />
<_RuntimeVariant Condition="'$(WasmEnableThreads)' == 'true'">-threads</_RuntimeVariant>
<_UsePThreads />
<_UsePThreads Condition="'$(WasmEnableThreads)' == 'true'"> usepthreads</_UsePThreads>

<_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native</_IcuDir>
<_IcuDirArg Condition="'$(_IcuDir)' != ''"> icudir "$(_IcuDir)"</_IcuDirArg>

<_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_UsePThreads)</_BuildNativeArgs>
<_CMakeArgs Condition="'$(CMakeArgs)' != ''"> -cmakeargs "$(CMakeArgs)"</_CMakeArgs>
<_CMakeArgs Condition="'$(WasmEnableThreads)' == 'true'">$(_CMakeArgs) -cmakeargs "-DCMAKE_USE_PTHREADS=1"</_CMakeArgs>

<_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_CMakeArgs)</_BuildNativeArgs>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -50,17 +50,14 @@
<_PortableBuildArg Condition="'$(PortableBuild)' != 'true'"> -portablebuild=false</_PortableBuildArg>
<_CrossBuildArg Condition="'$(CrossBuild)' == 'true'"> -cross</_CrossBuildArg>
<_KeepNativeSymbolsBuildArg Condition="'$(KeepNativeSymbols)' != 'false'"> -keepnativesymbols</_KeepNativeSymbolsBuildArg>
<_MonoWasmMTCMakeArgs Condition="'$(WasmEnableThreads)' == 'true'"> -DMONO_WASM_MT=1</_MonoWasmMTCMakeArgs>
<_CMakeArgs Condition="'$(CMakeArgs)' != '' or '$(_MonoWasmMTCMakeArgs)' != ''"> -cmakeargs "$(CMakeArgs)$(_MonoWasmMTCMakeArgs)"</_CMakeArgs>

<!--
BuildNativeCompiler is a pass-through argument, to pass an argument to build-native.sh. It is intended to be
used to force a specific compiler toolset.
-->
<_BuildNativeCompilerArg Condition="'$(BuildNativeCompiler)' != ''"> $(BuildNativeCompiler)</_BuildNativeCompilerArg>
<_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessorCountArg)$(_PortableBuildArg)$(_CrossBuildArg)$(_BuildNativeCompilerArg)$(_KeepNativeSymbolsBuildArg)$(_CMakeArgs) $(Compiler)</_BuildNativeUnixArgs>
<_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessorCountArg)$(_PortableBuildArg)$(_CrossBuildArg)$(_BuildNativeCompilerArg)$(_KeepNativeSymbolsBuildArg) $(Compiler)</_BuildNativeUnixArgs>
<_BuildNativeBuildCommand>&quot;$(MSBuildThisFileDirectory)build-native.sh&quot; $(_BuildNativeUnixArgs)</_BuildNativeBuildCommand>
<_BuildNativeBuildCommand Condition="'$(TargetsBrowser)' == 'true'">bash -c 'source &quot;$(RepoRoot)src/mono/browser/emsdk/emsdk_env.sh&quot; &amp;&amp; $(_BuildNativeBuildCommand)'</_BuildNativeBuildCommand>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -100,11 +97,7 @@
Condition="$([MSBuild]::IsOsPlatform(Windows))">
<PropertyGroup>
<_BuildNativeArgs Condition="'$(Ninja)' == 'false'">$(_BuildNativeArgs) msbuild</_BuildNativeArgs>
<_MonoWasmMTCMakeArgs Condition="'$(WasmEnableThreads)' == 'true'">-DMONO_WASM_MT=1</_MonoWasmMTCMakeArgs>
<_MonoWasmMTCMakeArgs Condition="'$(CMakeArgs)' != ''"> $(_MonoWasmMTCMakeArgs)</_MonoWasmMTCMakeArgs>
<_BuildNativeArgs Condition="'$(CMakeArgs)' != '' or '$(_MonoWasmMTCMakeArgs)' != ''">$(_BuildNativeArgs) -cmakeargs "$(CMakeArgs)$(_MonoWasmMTCMakeArgs)"</_BuildNativeArgs>
<_BuildNativeBuildCommand>&quot;$(MSBuildThisFileDirectory)build-native.cmd&quot; $(_BuildNativeArgs)</_BuildNativeBuildCommand>
<_BuildNativeBuildCommand Condition="'$(TargetsBrowser)' == 'true'">call &quot;$([MSBuild]::NormalizePath('$(RepoRoot)src/mono/browser/emsdk', 'emsdk_env.cmd'))&quot; &amp;&amp; $(_BuildNativeBuildCommand)</_BuildNativeBuildCommand>
</PropertyGroup>
<!-- Run script that uses CMake to generate and build the native files. -->
<!-- Use IgnoreStandardErrorWarningFormat because Arcade sets WarnAsError and we want to avoid upgrading compiler warnings to errors in release branches -->
Expand Down
32 changes: 1 addition & 31 deletions src/native/libs/build-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ handle_arguments() {
__ShiftArgs=1
;;

usepthreads|-usepthreads)
__usePThreads=1
;;

staticliblink|-staticliblink)
__StaticLibLink=1
;;
Expand All @@ -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
Expand Down Expand Up @@ -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"}"
Expand Down
2 changes: 1 addition & 1 deletion src/native/minipal/descriptorlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/native/minipal/memorybarrierprocesswide.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
// The .NET Foundation licenses this file to you under the MIT license.

#ifndef HOST_WINDOWS
#include <assert.h>
#include <pthread.h>

#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include <minipal/memorybarrierprocesswide.h>

#ifndef HOST_WASM
#include <pthread.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <minipal/memorybarrierprocesswide.h>

#ifdef __APPLE__
#include <stdlib.h>
Expand Down Expand Up @@ -72,15 +75,16 @@ 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;

// Mutex to make the fallback path thread safe
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;

Expand Down
2 changes: 1 addition & 1 deletion src/native/minipal/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading