Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build] Support Visual Studio 2022 #4987

Merged
merged 1 commit into from
May 16, 2022
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
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# The Taichi Programming Language
#*********************************************************************

cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.15)

project(taichi)

Expand Down Expand Up @@ -70,6 +70,19 @@ if (USE_MOLD)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=mold")
endif()

if (WIN32)
# For `Debug` configs MSVC links to a debuggable runtime by default which has
# symbol conflicts with the prebuilt LLVM in `Release`. We shoule be providing
# prebuilt LLVMs for both `Debug` and `Release` but LLVM 10 cannot be built by
# MSVC in `Debug` config because MSVC would try to fill uninitialize memory
# with `0xCC` but it too breaks `LLVMTableGen` which is depended on by almost
# every component in LLVM.
#
# FIXME: (penguinliong) This is fixed in later releases of LLVM so maybe
# someday we can distribute `Debug` libraries, if it's ever needed.
SET(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
endif()

# No support of Python for Android build
if (NOT ANDROID)
include(cmake/PythonNumpyPybind11.cmake)
Expand Down
54 changes: 48 additions & 6 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ param(
[string] $BuildType = "Release",
[string] $LlvmDir = "",
[string] $ClangDir = "",
[string] $VisualStudioVersion = "",
# Install python package in user-space.
[switch] $UserSpace = $false,
# Clean up compilation intermediates instead of building Taichi. Note that
Expand Down Expand Up @@ -45,12 +46,53 @@ function DownloadArchiveAndExpand($Uri, $ArchiveName) {



# Identify Visual Studio version.
if (-not $VisualStudioVersion) {
$VisualStudioVersion = (Get-CimInstance MSFT_VSInstance).Version.Split('.')[0]
Write-Host "Identified Visual Studio version from installation."
}
switch ($VisualStudioVersion) {
"2019" { $VisualStudioVersion = "16" }
"2022" { $VisualStudioVersion = "17" }
}
switch ($VisualStudioVersion) {
"16" {
Write-Host "Using MSVC from Visual Studio 2019."
$PrebuiltLlvmUri = "https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/taichi-llvm-10.0.0-msvc2019.zip"
$LlvmArchiveName = "taichi-llvm-10.0.0-msvc2019"
}
"17" {
Write-Host "Using MSVC from Visual Studio 2022."
$PrebuiltLlvmUri = "https://github.com/taichi-dev/taichi_assets/releases/download/llvm10_msvc2022/taichi-llvm-10.0.0-msvc2022.zip"
$LlvmArchiveName = "taichi-llvm-10.0.0-msvc2022"
}
default {
Write-Error "Unsupported Visual Studio Version"
}
}

# Select build type, by default it's `Release`.
switch ($BuildType) {
"Debug" { $env:DEBUG = 1; }
"Release" {}
"RelWithDebInfo" { $env:RELWITHDEBINFO = 1; }
"MinSizeRel" { $env:MINSIZEREL = 1; }
"Debug" {
$env:DEBUG = 1;
$env:RELWITHDEBINFO = 0;
$env:MINSIZEREL = 0;
}
"Release" {
$env:DEBUG = 0;
$env:RELWITHDEBINFO = 0;
$env:MINSIZEREL = 0;
}
"RelWithDebInfo" {
$env:DEBUG = 0;
$env:RELWITHDEBINFO = 1;
$env:MINSIZEREL = 0;
}
"MinSizeRel" {
$env:DEBUG = 0;
$env:RELWITHDEBINFO = 0;
$env:MINSIZEREL = 1;
}
Default {
Write-Error "Unknown build type '$BuildType'"
}
Expand All @@ -63,8 +105,8 @@ if ($env:LLVM_DIR) {
$LlvmDir = $env:LLVM_DIR;
}
if (-not $LlvmDir) {
DownloadArchiveAndExpand -Uri "https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/taichi-llvm-10.0.0-msvc2019.zip" -ArchiveName "taichi-llvm"
$LlvmDir = "$TempDir/taichi-llvm"
DownloadArchiveAndExpand -Uri $PrebuiltLlvmUri -ArchiveName $LlvmArchiveName
$LlvmDir = "$TempDir/$LlvmArchiveName"
}
if (-not $LlvmDir -or -not (Test-Path $LlvmDir)) {
throw "LLVM cannot be found in local environment and the script failed to download a prebuilt archive. " +
Expand Down
8 changes: 5 additions & 3 deletions docs/lang/articles/contribution/dev_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ We provide pre-built, customized LLVM binaries. For now, Taichi supports LLVM 10
{label: 'LLVM 10.0.0 for Linux', value: 'llvm_linux'},
{label: 'LLVM 10.0.0 for macOS (without M1 chip)', value: 'llvm_macos_sans_m1'},
{label: 'LLVM 10.0.0 for macOS (with M1 chip)', value: 'llvm_macos_m1'},
{label: 'LLVM 10.0.0 for Windows MSVC 2019', value: 'llvm_windows'},
{label: 'LLVM 10.0.0 for Windows', value: 'llvm_windows'},
]}>

<TabItem value="llvm_linux">
Expand All @@ -182,6 +182,7 @@ We provide pre-built, customized LLVM binaries. For now, Taichi supports LLVM 10
</TabItem>
<TabItem value="llvm_windows">
<a href="https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/taichi-llvm-10.0.0-msvc2019.zip">LLVM 10.0.0 for Windows MSVC 2019</a>
<a href="https://github.com/taichi-dev/taichi_assets/releases/download/llvm10_msvc2022/taichi-llvm-10.0.0-msvc2022.zip">LLVM 10.0.0 for Windows MSVC 2022</a>
</TabItem>
</Tabs>

Expand Down Expand Up @@ -269,12 +270,13 @@ llvm-config --version # You should get 10.0.0

# LLVM 10.0.0 + MSVC 2019

cmake .. -G "Visual Studio 16 2019" -A x64 -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" -DLLVM_ENABLE_ASSERTIONS=ON -Thost=x64 -DLLVM_BUILD_TESTS:BOOL=OFF -DCMAKE_INSTALL_PREFIX=installed
cmake .. -G "Visual Studio 16 2019" -A x64 -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" -DLLVM_ENABLE_ASSERTIONS=ON -Thost=x64 -DLLVM_BUILD_TESTS:BOOL=OFF -DCMAKE_INSTALL_PREFIX=installed -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DCMAKE_CXX_STANDARD=17
cmake --build . --target=INSTALL --config=Release
```

1. Use Visual Studio 2017+ to build **LLVM.sln**.
2. Ensure that you use the **Release** configuration. After building the `INSTALL` project (under folde **CMakePredefinedTargets** in the Solution Explorer window).
3. If you use MSVC 2019, ensure that you use **C++17** for the `INSTALL` project.
3. If you use MSVC 2019+, ensure that you use **C++17** for the `INSTALL` project.
4. When the build completes, add an environment variable `LLVM_DIR` with value `<PATH_TO_BUILD>/build/installed/lib/cmake/llvm`.

</TabItem>
Expand Down