diff options
| -rw-r--r-- | CONTRIBUTING.md | 11 | ||||
| -rw-r--r-- | examples/stacktrace-windows/common.cpp | 2 | ||||
| -rw-r--r-- | external/build-llvm.ps1 | 159 |
3 files changed, 172 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24641c5b4..7fca908cf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -93,6 +93,15 @@ Or you can build with the following command: C:\git\slang> cmake.exe --build --preset release ``` +On Windows ARM64, prebuilt binaries for LLVM isn't available. +Please build Slang without LLVM dependency by running: + +``` +cmake.exe --preset vs2022 -DSLANG_SLANG_LLVM_FLAVOR=DISABLE +``` + +during configuration step. + #### Linux Install CMake and Ninja. ``` @@ -136,6 +145,8 @@ Follow the instructions below if you wish to build `slang-llvm` locally. $ external/build-llvm.sh --source-dir build/slang-llvm_src --install-prefix build/slang-llvm_install ``` +> Note: On Windows you can use `external/build-llvm.ps1` in Powershell. + You need to use the following command to regenerate the Makefile: ``` $ cmake --preset default --fresh -DSLANG_SLANG_LLVM_FLAVOR=USE_SYSTEM_LLVM -DLLVM_DIR=build/slang-llvm_install/lib/cmake/llvm -DClang_DIR=build/slang-llvm_install/lib/cmake/clang diff --git a/examples/stacktrace-windows/common.cpp b/examples/stacktrace-windows/common.cpp index b07f78d0a..98fa8ad78 100644 --- a/examples/stacktrace-windows/common.cpp +++ b/examples/stacktrace-windows/common.cpp @@ -74,6 +74,8 @@ static bool printStack(FILE* file, HANDLE process, HANDLE thread, CONTEXT const& { #if defined(_M_AMD64) DWORD constexpr machineType = IMAGE_FILE_MACHINE_AMD64; +#elif defined(_M_ARM64) + DWORD constexpr machineType = IMAGE_FILE_MACHINE_ARM64; #else #error Unsupported machine type #endif diff --git a/external/build-llvm.ps1 b/external/build-llvm.ps1 new file mode 100644 index 000000000..b777d2173 --- /dev/null +++ b/external/build-llvm.ps1 @@ -0,0 +1,159 @@ +# PowerShell script to fetch, build, and install LLVM for Slang + +# Set script to fail on errors +$ErrorActionPreference = "Stop" + +function Show-Help { + Write-Host "Fetch, build and install LLVM for Slang + +Options: + --repo: The source git repo, default: $repo + --branch: The branch (or tag) to fetch, default: $branch + --source-dir: Unpack and build in this directory: default $source_dir + --config: The configuration to build, default $config + --install-prefix: Install under this prefix + --: Any following arguments will be passed to the CMake configuration command +" +} + +function Msg { + Write-Host "$args" -ForegroundColor Yellow +} + +function Fail { + Msg "$args" + exit 1 +} + +function New-TemporaryDirectory { + $tmp = [System.IO.Path]::GetTempPath() # Not $env:TEMP, see https://stackoverflow.com/a/946017 + $name = (New-Guid).ToString("N") + New-Item -ItemType Directory -Path (Join-Path $tmp $name) +} + +# Check if required programs are available +$requiredPrograms = "cmake", "git" +foreach ($prog in $requiredPrograms) { + if (-not (Get-Command $prog -ErrorAction SilentlyContinue)) { + Msg "This script needs $prog, but it isn't in PATH" + $missingBin = $true + } +} +if ($missingBin) { + exit 1 +} + +# Temp directory with cleanup on exit +$tempDir = New-TemporaryDirectory +$cleanup = { + if ($tempDir) { + Remove-Item -Recurse -Force $tempDir + } + exit $lastExitCode +} +$null = Register-EngineEvent PowerShell.Exiting -Action $cleanup + +# Default values +$repo = "https://github.com/llvm/llvm-project" +$branch = "llvmorg-13.0.1" +$sourceDir = $tempDir.FullName +$installPrefix = "" +$config = "Release" +$extraArguments = @() + +# Argument parsing +for ($i = 0; $i -lt $args.Length; $i++) { + switch ($args[$i]) { + "--help" { + Show-Help + exit + } + "--repo" { + $repo = $args[++$i] + } + "--branch" { + $branch = $args[++$i] + } + "--source-dir" { + $sourceDir = $args[++$i] + } + "--config" { + $config = $args[++$i] + } + "--install-prefix" { + $installPrefix = $args[++$i] + } + "--" { + $extraArguments = $args[$i + 1..$args.Length] + break + } + default { + Msg "Unknown parameter passed: $($args[$i])" + Show-Help + exit 1 + } + } +} + +if (-not $repo) { Fail "please set --repo" } +if (-not $branch) { Fail "please set --branch" } +if (-not $sourceDir) { Fail "please set --source-dir" } +if (-not $config) { Fail "please set --config" } +if (-not $installPrefix) { Fail "please set --install-prefix" } + +# Fetch LLVM from the repo +Msg "##########################################################" +Msg "# Fetching LLVM from $repo at $branch" +Msg "##########################################################" +# git clone --depth 1 --branch $branch $repo $sourceDir + +# Configure LLVM with CMake +Msg "##########################################################" +Msg "# Configuring LLVM in $sourceDir" +Msg "##########################################################" +$msvcRuntimeLib = "MultiThreaded" +if ($config -eq 'Debug') +{ + $msvcRuntimeLib = "MultiThreadedDebug" +} +$cmakeArgumentsForSlang = @( + "-DLLVM_BUILD_LLVM_C_DYLIB=0" + "-DLLVM_INCLUDE_BENCHMARKS=0" + "-DLLVM_INCLUDE_DOCS=0" + "-DLLVM_INCLUDE_EXAMPLES=0" + "-DLLVM_INCLUDE_TESTS=0" + "-DLLVM_ENABLE_TERMINFO=0" + "-DCLANG_BUILD_TOOLS=0" + "-DCLANG_ENABLE_STATIC_ANALYZER=0" + "-DCLANG_ENABLE_ARCMT=0" + "-DCLANG_INCLUDE_DOCS=0" + "-DCLANG_INCLUDE_TESTS=0" + "-DLLVM_ENABLE_PROJECTS=clang" + "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64" + "-DLLVM_BUILD_TOOLS=0" + "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>" + "-DLLVM_USE_CRT_RELEASE=MT" + "-DLLVM_USE_CRT_DEBUG=MTd" +) + +$buildDir = Join-Path $sourceDir "build" +New-Item -Path $buildDir -ItemType Directory -Force + +cmake -S $sourceDir\llvm -B $buildDir $cmakeArgumentsForSlang + $extraArguments + +# Build LLVM +Msg "##########################################################" +Msg "# Building LLVM in $buildDir" +Msg "##########################################################" +cmake --build $buildDir -j --config $config + +# Install LLVM +Msg "##########################################################" +Msg "# Installing LLVM to $installPrefix" +Msg "##########################################################" +cmake --install $buildDir --prefix $installPrefix --config $config + +Msg "##########################################################" +Msg "LLVM installed in $installPrefix" +Msg "Please add $installPrefix to CMAKE_PREFIX_PATH" +Msg "##########################################################" |
