diff --git a/CMakeLists.txt b/CMakeLists.txt
index 494535cb4187c..0be966f98e101 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@
# The Taichi Programming Language
#*********************************************************************
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
project(taichi)
@@ -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)
diff --git a/build.ps1 b/build.ps1
index f45ec10c70f94..fdd90f4544b0c 100644
--- a/build.ps1
+++ b/build.ps1
@@ -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
@@ -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'"
}
@@ -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. " +
diff --git a/docs/lang/articles/contribution/dev_install.md b/docs/lang/articles/contribution/dev_install.md
index 106a6d7fc395a..ba85f89e2e04e 100644
--- a/docs/lang/articles/contribution/dev_install.md
+++ b/docs/lang/articles/contribution/dev_install.md
@@ -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'},
]}>
@@ -182,6 +182,7 @@ We provide pre-built, customized LLVM binaries. For now, Taichi supports LLVM 10
LLVM 10.0.0 for Windows MSVC 2019
+ LLVM 10.0.0 for Windows MSVC 2022
@@ -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 `/build/installed/lib/cmake/llvm`.