Skip to content

Commit 07ff833

Browse files
[NativeAOT-LLVM] Build on Linux (dotnet#2574)
* Enable linux builds * move NATIVEAOT_CI_WASM_BUILD_EMSDK_PATH to be inline with windows * just use pwsh for installing node. Delete the .cmd * normalize checked for llvm config * use powershell only for emscripten install * use pwsh inline with node * do not search system paths for LLVM * feedback tidy * do not use __ExtraCmakeArgs * Update src/coreclr/build-runtime.sh Co-authored-by: SingleAccretion <[email protected]> * Update src/coreclr/jit/CMakeLists.txt Co-authored-by: SingleAccretion <[email protected]> * Ensure Powershell on linux Remove wasm build options add cmake to path on windows Use more Powershell where possible Simplify New-Item use Feedback * feedback, move tool installations to correct place. --------- Co-authored-by: SingleAccretion <[email protected]>
1 parent e5a0829 commit 07ff833

File tree

16 files changed

+148
-80
lines changed

16 files changed

+148
-80
lines changed

docs/using-nativeaot/prerequisites.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The following pre-requisites need to be installed for building .NET projects wit
55
## Emscripten SDK
66

77
* Install and activate Emscripten. See [Install Emscripten](https://emscripten.org/docs/getting_started/downloads.html#installation-instructions-using-the-emsdk-recommended).
8-
* We strongly recommend using the same version that we test against. Look for it here: [install-emscripten.cmd](https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/eng/pipelines/runtimelab/install-emscripten.cmd).
8+
* We strongly recommend using the same version that we test against. Look for it here: [install-emscripten.ps1](https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/eng/pipelines/runtimelab/install-emscripten.ps1).
99
```
1010
./emsdk install <version>
1111
./emsdk activate <version>

docs/workflow/building/coreclr/nativeaot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The Native AOT toolchain can be currently built for Linux (x64/arm64), macOS (x6
2424
There are two kinds of binary artifacts produced by the build and needed for development: the runtime libraries and the cross-targeting compilers, ILC and RyuJit. They are built differently and separately.
2525

2626
For the runtime libraries:
27-
- Clone the [emsdk](https://github.com/emscripten-core/emsdk) repository and use the `emsdk.bat` script it comes with to [install](https://emscripten.org/docs/getting_started/downloads.html) (and optionally "activate", i. e. set the relevant environment variables permanently) the Emscripten SDK, which will be used by the native build as a sort of "virtualized" build environment. It is recommended to use the same Emscripten version that [the CI](https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/eng/pipelines/runtimelab/install-emscripten.cmd#L14-L18) uses.
27+
- Clone the [emsdk](https://github.com/emscripten-core/emsdk) repository and use the `emsdk.bat` script it comes with to [install](https://emscripten.org/docs/getting_started/downloads.html) (and optionally "activate", i. e. set the relevant environment variables permanently) the Emscripten SDK, which will be used by the native build as a sort of "virtualized" build environment. It is recommended to use the same Emscripten version that [the CI](https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/eng/pipelines/runtimelab/install-emscripten.ps1#L16-L20) uses.
2828
```
2929
git clone https://github.com/emscripten-core/emsdk
3030
cd emsdk

eng/pipelines/common/global-build-job.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,17 @@ jobs:
208208
209209
# Install Wasm dependencies: emscripten, LLVM, NodeJS
210210
- ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.archType, 'wasm')) }}:
211-
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-emscripten.cmd $(Build.SourcesDirectory)\wasm-tools
211+
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-emscripten.ps1 $(Build.SourcesDirectory)/wasm-tools
212212
displayName: Install/activate emscripten
213-
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-llvm.cmd $(Build.SourcesDirectory)\wasm-tools $(Build.SourcesDirectory) ${{ parameters.buildConfig }}
213+
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/set-cmake-path.cmd
214+
displayName: Set CMake path
215+
# Install Powershell on OSes that don't come with it by default
216+
- ${{ if ne(parameters.hostedOs, 'windows') }}:
217+
- script: $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-pwsh.sh $(Build.SourcesDirectory)/wasm-tools
218+
displayName: Install Powershell 7
219+
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-llvm.ps1 -CI -InstallDir $(Build.SourcesDirectory)\wasm-tools -Configs ${{ parameters.buildConfig }}
214220
displayName: Install/build LLVM
215-
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-nodejs.cmd $(Build.SourcesDirectory)\wasm-tools
221+
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-nodejs.ps1 $(Build.SourcesDirectory)\wasm-tools
216222
displayName: Install NodeJS
217223

218224
- ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.platform, 'wasi_wasm_win')) }}:
@@ -222,11 +228,6 @@ jobs:
222228
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-wasmer.cmd $(Build.SourcesDirectory)\wasm-tools
223229
displayName: Install wasmer
224230

225-
- ${{ if and(eq(parameters.osGroup, 'windows'), eq(parameters.archType, 'x64')) }}:
226-
# Install LLVM for the win-x64 build as it will build the clrjit for browser_wasm cross compilation
227-
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-llvm.cmd $(Build.SourcesDirectory)\wasm-tools $(Build.SourcesDirectory) ${{ parameters.buildConfig }}
228-
displayName: Install/build LLVM
229-
230231
- ${{ if or(eq(parameters.platform, 'browser_wasm_win'), and(eq(parameters.platform, 'wasi_wasm_win'), not(eq(parameters.runtimeFlavor, 'coreclr')))) }}:
231232
# Update machine certs
232233
- task: PowerShell@2

eng/pipelines/runtimelab.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ extends:
5959
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
6060
buildConfig: debug
6161
platforms:
62-
# - linux_x64
6362
- osx_x64
6463
- windows_x64
6564
- Browser_wasm_win
@@ -81,7 +80,6 @@ extends:
8180
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
8281
buildConfig: checked
8382
platforms:
84-
# - linux_x64
8583
- windows_x64
8684
jobParameters:
8785
timeoutInMinutes: 300
@@ -101,7 +99,7 @@ extends:
10199
helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml
102100
buildConfig: release
103101
platforms:
104-
# - linux_x64
102+
- linux_x64
105103
- osx_x64
106104
- windows_x64
107105
- Browser_wasm_win

eng/pipelines/runtimelab/install-emscripten.cmd

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
param(
2+
$InstallDir
3+
)
4+
5+
$ErrorActionPreference="Stop"
6+
7+
New-Item -ItemType Directory -Force -Path $InstallDir
8+
9+
Set-Location -Path $InstallDir
10+
11+
git clone https://github.com/emscripten-core/emsdk.git
12+
13+
Set-Location -Path emsdk
14+
15+
# Checkout a specific commit to avoid unexpected issues
16+
git checkout 37b85e9
17+
18+
./emsdk install 3.1.47
19+
20+
./emsdk activate 3.1.47
21+
22+
# Set a variable for later use (used in common/build.ps1)
23+
Write-Host "##vso[task.setvariable variable=NATIVEAOT_CI_WASM_BUILD_EMSDK_PATH]$PWD"

eng/pipelines/runtimelab/install-llvm.cmd

Lines changed: 0 additions & 22 deletions
This file was deleted.

eng/pipelines/runtimelab/install-llvm.ps1

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
[CmdletBinding(PositionalBinding=$false)]
22
param(
3-
[ValidateSet("Debug","Release")][string[]]$Configs = @("Debug","Release"),
3+
$InstallDir,
4+
[ValidateSet("Debug","Release","Checked")][string[]]$Configs = @("Debug","Release"),
45
[switch]$CI,
56
[switch]$NoClone,
67
[switch]$NoBuild
78
)
89

10+
911
$ErrorActionPreference="Stop"
1012

13+
New-Item -ItemType Directory -Path $InstallDir -Force
14+
Set-Location -Path $InstallDir
15+
16+
# Set IsWindows if the version of Powershell does not already have it.
17+
if (!(Test-Path variable:global:IsWindows))
18+
{
19+
$IsWindows = [Environment]::OSVersion.Platform -eq [PlatformID]::Win32NT
20+
}
21+
1122
if (!(gcm git -ErrorAction SilentlyContinue))
1223
{
1324
Write-Error "Unable to find 'git' in PATH"
@@ -31,27 +42,43 @@ elseif (!(Test-Path llvm-project))
3142
exit 1
3243
}
3344

34-
foreach ($Config in $Configs)
45+
# There is no [C/c]hecked LLVM config, so change to Debug
46+
foreach ($Config in $Configs | % { if ($_ -eq "Checked") { "Debug" } else { $_ } } | Select-Object -Unique)
3547
{
3648
pushd llvm-project
3749
$BuildDirName = "build-$($Config.ToLower())"
38-
mkdir $BuildDirName -Force
50+
New-Item -ItemType Directory $BuildDirName -Force
3951

4052
$BuildDirPath = "$pwd/$BuildDirName"
4153
$SourceDirName = "$pwd/llvm"
4254
popd
4355

44-
$CmakeConfigureCommandLine = "-G", "Visual Studio 17 2022", "-DLLVM_INCLUDE_BENCHMARKS=OFF", "-Thost=x64"
56+
if ($IsWindows)
57+
{
58+
$CmakeGenerator = "Visual Studio 17 2022"
59+
}
60+
else
61+
{
62+
$CmakeGenerator = "Unix Makefiles"
63+
}
64+
65+
$CmakeConfigureCommandLine = "-G", "$CmakeGenerator", "-DLLVM_INCLUDE_BENCHMARKS=OFF"
4566
$CmakeConfigureCommandLine += "-S", $SourceDirName, "-B", $BuildDirPath
4667
if ($Config -eq "Release")
4768
{
4869
$LlvmConfig = "Release"
49-
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded"
70+
if ($IsWindows)
71+
{
72+
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", "-Thost=x64"
73+
}
5074
}
5175
else
5276
{
5377
$LlvmConfig = "Debug"
54-
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug"
78+
if ($IsWindows)
79+
{
80+
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug", "-Thost=x64"
81+
}
5582
}
5683
$CmakeConfigureCommandLine += "-DCMAKE_BUILD_TYPE=$LlvmConfig"
5784

eng/pipelines/runtimelab/install-nodejs.cmd

Lines changed: 0 additions & 9 deletions
This file was deleted.

eng/pipelines/runtimelab/install-nodejs.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
$InstallPath = $Args[0]
22
$NodeJSVersion = "v20.2.0"
3-
$NodeJSInstallName = "node-$NodeJSVersion-win-x64"
4-
$NodeJSZipName = "$NodeJSInstallName.zip"
3+
4+
if (!(Test-Path variable:global:IsWindows))
5+
{
6+
$IsWindows = [Environment]::OSVersion.Platform -eq [PlatformID]::Win32NT
7+
}
8+
9+
if ($IsWIndows)
10+
{
11+
$NodeJSInstallName = "node-$NodeJSVersion-win-x64"
12+
$NodeJSZipName = "$NodeJSInstallName.zip"
13+
}
14+
else
15+
{
16+
$NodeJSInstallName = "node-$NodeJSVersion-linux-x64"
17+
$NodeJSZipName = "$NodeJSInstallName.tar.xz"
18+
}
519

620
if (!(Test-Path $InstallPath))
721
{
@@ -33,9 +47,17 @@ if ($RetryCount -le 0)
3347
exit 1
3448
}
3549

36-
Expand-Archive -LiteralPath "$InstallPath\$NodeJSInstallName.zip" -DestinationPath $InstallPath -Force
50+
if ($IsWindows)
51+
{
52+
Expand-Archive -LiteralPath "$InstallPath\$NodeJSZipName" -DestinationPath $InstallPath -Force
53+
$NodeJSExePath = "$InstallPath\$NodeJSInstallName\node.exe"
54+
}
55+
else
56+
{
57+
tar xJf $InstallPath/$NodeJSZipName -C $InstallPath
58+
$NodeJSExePath = "$InstallPath/$NodeJSInstallName/bin/node"
59+
}
3760

38-
$NodeJSExePath = "$InstallPath\$NodeJSInstallName\node.exe"
3961
if (!(Test-Path $NodeJSExePath))
4062
{
4163
Write-Error "Did not find NodeJS at: '$NodeJSExePath'"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
mkdir -p $1
4+
5+
cd $1
6+
7+
curl -L -o powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.3.12/powershell-7.3.12-linux-x64.tar.gz
8+
9+
# Create the target folder where powershell will be placed
10+
mkdir powershell7
11+
12+
# Expand powershell to the target folder
13+
tar zxf powershell.tar.gz -C powershell7
14+
15+
# Set execute permissions
16+
chmod +x powershell7/pwsh
17+
18+
echo setting PATH
19+
echo ##vso[task.setvariable variable=PATH]$PATH:$1/powershell7
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Save the current PATH because init-vs-env.cmd will add enough to the PATH that calling it twice
2+
# will exceed the command length limit.
3+
set OLD_PATH=%PATH%
4+
call "%RepoRoot%eng\native\init-vs-env.cmd" wasm || exit /b 1
5+
6+
call set CMakeDir=%%CMakePath:\cmake.exe=%%
7+
8+
echo CMakeDir is %CMakeDir%
9+
echo Setting PATH to %OLD_PATH%;%CMakeDir%
10+
echo ##vso[task.setvariable variable=PATH]%OLD_PATH%;%CMakeDir%

src/coreclr/build-runtime.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ if [[ -n "$__RequestedBuildComponents" ]]; then
171171
__CMakeTarget=" $__RequestedBuildComponents "
172172
__CMakeTarget="${__CMakeTarget// paltests / paltests_install }"
173173
fi
174+
175+
if [[ "$__CMakeTarget" == *"wasmjit"* ]]; then
176+
__CMakeArgs="$__CMakeArgs -DCLR_CMAKE_BUILD_LLVM_JIT=1"
177+
178+
if [[ "$__BuildType" == "Release" ]]; then
179+
if [[ -n $LLVM_CMAKE_CONFIG_RELEASE ]]; then
180+
LLVM_CMAKE_CONFIG="$LLVM_CMAKE_CONFIG_RELEASE"
181+
fi
182+
else
183+
if [[ -n $LLVM_CMAKE_CONFIG_DEBUG ]]; then
184+
LLVM_CMAKE_CONFIG="$LLVM_CMAKE_CONFIG_DEBUG"
185+
fi
186+
fi
187+
188+
if [[ -z "$LLVM_CMAKE_CONFIG" ]]; then
189+
echo The LLVM_CMAKE_CONFIG environment variable pointing to llvm-build-dir/lib/cmake/llvm must be set. 1>&2
190+
exit 1
191+
fi
192+
fi
193+
174194
if [[ -z "$__CMakeTarget" ]]; then
175195
__CMakeTarget="install"
176196
fi

src/coreclr/jit/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ function(create_standalone_jit)
9191
# We'll be linking against LLVM built without /guard:ehcont, so disable it.
9292
set_target_properties(${TARGETDETAILS_TARGET} PROPERTIES CLR_EH_CONTINUATION OFF)
9393

94-
find_package(LLVM REQUIRED CONFIG PATHS $ENV{LLVM_CMAKE_CONFIG})
94+
# Only look at "our" LLVM with LLVM_CMAKE_CONFIG.
95+
find_package(LLVM REQUIRED CONFIG PATHS $ENV{LLVM_CMAKE_CONFIG} NO_DEFAULT_PATH)
9596
target_include_directories(${TARGETDETAILS_TARGET} PRIVATE ${LLVM_INCLUDE_DIRS})
9697
separate_arguments(LLVM_DEFINITIONS)
9798
target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE ${LLVM_DEFINITIONS})

src/coreclr/nativeaot/Runtime/unix/UnixContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// WASM has no thread state contexts.
88
#ifndef HOST_WASM
99

10+
#include <ucontext.h>
11+
1012
// Convert Unix native context to PAL_LIMITED_CONTEXT
1113
void NativeContextToPalContext(const void* context, PAL_LIMITED_CONTEXT* palContext);
1214
// Redirect Unix native context to the PAL_LIMITED_CONTEXT and also set the first two argument registers

src/native/libs/build-native.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ __usePThreads=0
5959
source "$__RepoRootDir"/eng/native/build-commons.sh
6060

6161
# Set cross build
62+
EMSDK_PATH=$EMSDK
6263
if [[ "$__TargetOS" == browser ]]; then
6364
if [[ -z "$EMSDK_PATH" ]]; then
6465
if [[ -d "$__RepoRootDir"/src/mono/browser/emsdk/ ]]; then

0 commit comments

Comments
 (0)