Skip to content

Commit

Permalink
Enable linux builds
Browse files Browse the repository at this point in the history
  • Loading branch information
yowl committed May 4, 2024
1 parent 21cc98a commit 68c98bc
Show file tree
Hide file tree
Showing 12 changed files with 2,875 additions and 22 deletions.
3 changes: 3 additions & 0 deletions eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ fi

if [[ "$host_arch" == "wasm" ]]; then
if [[ "$target_os" == "browser" ]]; then
if [[ -n "$NATIVEAOT_CI_WASM_BUILD_EMSDK_PATH" ]]; then
source $NATIVEAOT_CI_WASM_BUILD_EMSDK_PATH/emsdk_env.sh
fi
cmake_command="emcmake $cmake_command"
elif [[ "$target_os" == "wasi" ]]; then
true
Expand Down
14 changes: 12 additions & 2 deletions eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,25 @@ jobs:
df -h
displayName: Disk Usage before Build
# Install Wasm dependencies: emscripten, LLVM, NodeJS
- ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.archType, 'wasm')) }}:
# Install Wasm dependencies on Windows: emscripten, LLVM, NodeJS
- ${{ if and(eq(parameters.hostedOs, 'windows'), 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 }}
displayName: Install/build LLVM
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-nodejs.cmd $(Build.SourcesDirectory)\wasm-tools
displayName: Install NodeJS

# Install Wasm dependencies on Linux: emscripten, LLVM, NodeJS.
- ${{ if and(eq(parameters.hostedOs, 'linux'), and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.archType, 'wasm'))) }}:
- script: $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-emscripten.sh $(Build.SourcesDirectory)/wasm-tools
displayName: Install/activate emscripten
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-llvm.ps1 -Configs ${{ parameters.buildConfig }} -CI
workingDirectory: $(Build.SourcesDirectory)/wasm-tools
displayName: Install/build LLVM
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-nodejs.ps1 $(Build.SourcesDirectory)/wasm-tools
displayName: Install NodeJS

- ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), eq(parameters.platform, 'wasi_wasm_win')) }}:
# Install Wasi Wasm dependencies: wasi-sdk, wasmer
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-wasi-sdk.cmd $(Build.SourcesDirectory)\wasm-tools
Expand Down
6 changes: 3 additions & 3 deletions eng/pipelines/runtimelab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extends:
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
buildConfig: debug
platforms:
# - linux_x64
- linux_x64
- osx_x64
- windows_x64
- Browser_wasm_win
Expand All @@ -81,7 +81,7 @@ extends:
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
buildConfig: checked
platforms:
# - linux_x64
- linux_x64
- windows_x64
jobParameters:
timeoutInMinutes: 300
Expand All @@ -101,7 +101,7 @@ extends:
helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml
buildConfig: release
platforms:
# - linux_x64
- linux_x64
- osx_x64
- windows_x64
- Browser_wasm_win
Expand Down
16 changes: 16 additions & 0 deletions eng/pipelines/runtimelab/install-emscripten.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

mkdir "$1" 2>/dev/null
cd "$1"

git clone https://github.com/emscripten-core/emsdk.git

cd emsdk
# Checkout a known good version to avoid a random break when emscripten changes the top of tree.
git checkout 37b85e9

python emsdk.py install 3.1.47 || exit 1
./emsdk activate 3.1.47 || exit 1

# We key off of this variable in the common/build.ps1 script.
echo "##vso[task.setvariable variable=NATIVEAOT_CI_WASM_BUILD_EMSDK_PATH]$PWD"
36 changes: 32 additions & 4 deletions eng/pipelines/runtimelab/install-llvm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ param(
[switch]$NoBuild
)

# Set IsWindows if the version of Powershell does not already have it.
if (!(Test-Path variable:global:IsWindows))
{
$IsWindows=[environment]::OSVersion.Platform -eq [PlatformID]::Win32NT
}

$ErrorActionPreference="Stop"

if (!(gcm git -ErrorAction SilentlyContinue))
Expand Down Expand Up @@ -35,23 +41,45 @@ foreach ($Config in $Configs)
{
pushd llvm-project
$BuildDirName = "build-$($Config.ToLower())"
mkdir $BuildDirName -Force
if ($IsWindows)
{
mkdir $BuildDirName -Force
}
else
{
mkdir $BuildDirName --parents
}

$BuildDirPath = "$pwd/$BuildDirName"
$SourceDirName = "$pwd/llvm"
popd

$CmakeConfigureCommandLine = "-G", "Visual Studio 17 2022", "-DLLVM_INCLUDE_BENCHMARKS=OFF", "-Thost=x64"
if ($IsWindows)
{
$generator="Visual Studio 17 2022"
}
else
{
$generator="Unix Makefiles"
}

$CmakeConfigureCommandLine = "-G", "$generator", "-DLLVM_INCLUDE_BENCHMARKS=OFF"
$CmakeConfigureCommandLine += "-S", $SourceDirName, "-B", $BuildDirPath
if ($Config -eq "Release")
{
$LlvmConfig = "Release"
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded"
if ($IsWindows)
{
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", "-Thost=x64"
}
}
else
{
$LlvmConfig = "Debug"
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug"
if ($IsWindows)
{
$CmakeConfigureCommandLine += "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug", "-Thost=x64"
}
}
$CmakeConfigureCommandLine += "-DCMAKE_BUILD_TYPE=$LlvmConfig"

Expand Down
30 changes: 26 additions & 4 deletions eng/pipelines/runtimelab/install-nodejs.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
$InstallPath = $Args[0]
$NodeJSVersion = "v20.2.0"
$NodeJSInstallName = "node-$NodeJSVersion-win-x64"
$NodeJSZipName = "$NodeJSInstallName.zip"

if (!(Test-Path variable:global:IsWindows))
{
$IsWindows=[environment]::OSVersion.Platform -eq [PlatformID]::Win32NT
}

if ($IsWIndows)
{
$NodeJSInstallName = "node-$NodeJSVersion-win-x64"
$NodeJSZipName = "$NodeJSInstallName.zip"
}
else
{
$NodeJSInstallName = "node-$NodeJSVersion-linux-x64"
$NodeJSZipName = "$NodeJSInstallName.tar.xz"
}

if (!(Test-Path $InstallPath))
{
Expand Down Expand Up @@ -33,9 +47,17 @@ if ($RetryCount -le 0)
exit 1
}

Expand-Archive -LiteralPath "$InstallPath\$NodeJSInstallName.zip" -DestinationPath $InstallPath -Force
if ($IsWindows)
{
Expand-Archive -LiteralPath "$InstallPath\$NodeJSZipName" -DestinationPath $InstallPath -Force
$NodeJSExePath = "$InstallPath\$NodeJSInstallName\node.exe"
}
else
{
tar xJf $InstallPath/$NodeJSZipName -C $InstallPath
$NodeJSExePath = "$InstallPath/$NodeJSInstallName/bin/node"
}

$NodeJSExePath = "$InstallPath\$NodeJSInstallName\node.exe"
if (!(Test-Path $NodeJSExePath))
{
Write-Error "Did not find NodeJS at: '$NodeJSExePath'"
Expand Down
22 changes: 21 additions & 1 deletion src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ if [[ -n "$__RequestedBuildComponents" ]]; then
__CMakeTarget=" $__RequestedBuildComponents "
__CMakeTarget="${__CMakeTarget// paltests / paltests_install }"
fi

if [[ "$__CMakeTarget" == *"wasmjit"* ]]; then
__ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_LLVM_JIT=1"

if [[ "$__BuildType" == "Release" ]]; then
if [[ -n $LLVM_CMAKE_CONFIG_RELEASE ]]; then
LLVM_CMAKE_CONFIG="$LLVM_CMAKE_CONFIG_RELEASE"
fi
else
if [[ -n $LLVM_CMAKE_CONFIG_DEBUG ]]; then
LLVM_CMAKE_CONFIG="$LLVM_CMAKE_CONFIG_DEBUG"
fi
fi

if [[ -z "$LLVM_CMAKE_CONFIG" ]]; then
echo The LLVM_CMAKE_CONFIG environment variable pointing to llvm-build-dir/lib/cmake/llvm must be set. 1>&2
exit 1
fi
fi

if [[ -z "$__CMakeTarget" ]]; then
__CMakeTarget="install"
fi
Expand All @@ -185,7 +205,7 @@ fi

eval "$__RepoRootDir/eng/native/version/copy_version_files.sh"

build_native "$__HostOS" "$__HostArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component"
build_native "$__HostOS" "$__HostArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs $__ExtraCmakeArgs" "CoreCLR component"

# Build complete

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ function(create_standalone_jit)
# We'll be linking against LLVM built without /guard:ehcont, so disable it.
set_target_properties(${TARGETDETAILS_TARGET} PROPERTIES CLR_EH_CONTINUATION OFF)

find_package(LLVM REQUIRED CONFIG PATHS $ENV{LLVM_CMAKE_CONFIG})
# Prefer the version specified in LLVM_CMAKE_CONFIG over the "system" installed version
find_package(LLVM REQUIRED CONFIG PATHS $ENV{LLVM_CMAKE_CONFIG} NO_DEFAULT_PATH)
find_package(LLVM REQUIRED CONFIG)
target_include_directories(${TARGETDETAILS_TARGET} PRIVATE ${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS)
target_compile_definitions(${TARGETDETAILS_TARGET} PRIVATE ${LLVM_DEFINITIONS})
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/UnixContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// WASM has no thread state contexts.
#ifndef HOST_WASM

#include <ucontext.h>

// Convert Unix native context to PAL_LIMITED_CONTEXT
void NativeContextToPalContext(const void* context, PAL_LIMITED_CONTEXT* palContext);
// Redirect Unix native context to the PAL_LIMITED_CONTEXT and also set the first two argument registers
Expand Down
Loading

0 comments on commit 68c98bc

Please sign in to comment.