diff --git a/.github/workflows/release-llvm.yml b/.github/workflows/release-llvm.yml index 3a5b9d0..4d44531 100644 --- a/.github/workflows/release-llvm.yml +++ b/.github/workflows/release-llvm.yml @@ -73,6 +73,7 @@ jobs: contents: write # for uploading assets to release steps: - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 with: # without this it will override our rust flags @@ -101,6 +102,13 @@ jobs: run: | choco install ninja + # Provides MSVC toolchain (ml64, headers, libs) used by clang-cl when building LLVM. + - name: Set Up MSVC Developer Environment + if: ${{ matrix.host == 'windows' }} + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + - name: Install LLVM Builder run: | cargo install --locked --force --path crates/llvm-builder diff --git a/.github/workflows/test-llvm-builder.yml b/.github/workflows/test-llvm-builder.yml index 9f118c7..6f6bdbf 100644 --- a/.github/workflows/test-llvm-builder.yml +++ b/.github/workflows/test-llvm-builder.yml @@ -40,6 +40,18 @@ jobs: run: | brew install ninja + - name: Install Dependencies + if: matrix.runner == 'windows-2022' + run: | + choco install ninja + + # Provides MSVC toolchain (ml64, headers, libs) used by clang-cl when building LLVM. + - name: Set Up MSVC Developer Environment + if: matrix.runner == 'windows-2022' + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + - name: Test run: make test-llvm-builder env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 6776f51..780d25e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This is a development pre-release. - Updated `inkwell` to `0.8.0` - Updated `polkavm-*` to `0.31.0` - Updated `EMSDK` to `5.0.0` +- Switched building LLVM for Windows from Visual Studio to MSVC-compatible Clang (clang-cl) and Ninja. [#497](https://github.com/paritytech/revive/pull/497) ## v1.0.0 diff --git a/crates/llvm-builder/src/platforms/x86_64_windows_msvc.rs b/crates/llvm-builder/src/platforms/x86_64_windows_msvc.rs index 7902acb..b96ac33 100644 --- a/crates/llvm-builder/src/platforms/x86_64_windows_msvc.rs +++ b/crates/llvm-builder/src/platforms/x86_64_windows_msvc.rs @@ -1,4 +1,8 @@ -//! The revive LLVM amd64 `windows-gnu` builder. +//! The revive LLVM amd64 `windows-msvc` builder. +//! +//! Uses `clang-cl` and `lld-link` (Clang's MSVC-compatible drivers) +//! to match the Clang toolchain used on our Linux and MacOS variants, +//! while keeping the MSVC ABI and C++ runtime. use std::collections::HashSet; use std::process::Command; @@ -27,6 +31,9 @@ pub fn build( sanitizer: Option, ) -> anyhow::Result<()> { crate::utils::check_presence("cmake")?; + crate::utils::check_presence("clang-cl")?; + crate::utils::check_presence("lld-link")?; + crate::utils::check_presence("ninja")?; let llvm_module_llvm = LLVMPath::llvm_module_llvm().and_then(crate::utils::path_windows_to_unix)?; @@ -43,12 +50,16 @@ pub fn build( "-B", llvm_build_final.to_string_lossy().as_ref(), "-G", - "Visual Studio 17 2022", + "Ninja", format!( "-DCMAKE_INSTALL_PREFIX='{}'", llvm_target_final.to_string_lossy().as_ref(), ) .as_str(), + format!("-DCMAKE_BUILD_TYPE='{build_type}'").as_str(), + "-DCMAKE_C_COMPILER='clang-cl'", + "-DCMAKE_CXX_COMPILER='clang-cl'", + "-DLLVM_USE_LINKER='lld-link'", format!( "-DLLVM_TARGETS_TO_BUILD='{}'", targets @@ -99,17 +110,7 @@ pub fn build( "LLVM building cmake", )?; - crate::utils::command( - Command::new("cmake").args([ - "--build", - llvm_build_final.to_string_lossy().as_ref(), - "--target", - "install", - "--config", - build_type.to_string().as_str(), - ]), - "Building with msbuild", - )?; + crate::utils::ninja(llvm_build_final.as_ref())?; Ok(()) }