Build LLVM for Windows (#248)

This PR changes the CI build scripts to also build LLVM for windows.
**It doesn't build `revive` itself for windows**. This will come in a
follow up. But once we have a LLVM binary release the turn around time
will be much quicker for experimenting with the revive windows build.

I manually uploaded the release those changes produce
[here](https://github.com/paritytech/revive-alex-workflowtest/releases/tag/llvm-18.1.8-revive.22f3ceb).
This enables this PR's CI to find the proper release. This is necessary
because I am also making changes to the folder structure and artifact
naming that the other CI jobs are depending on.

Releases generated from this branch can be inspected here:
https://github.com/paritytech/revive-alex-workflowtest/releases/tag/v0.1.0-dev.12

Summary of changes:
- Change `llvm-builder` to use MSVC toolchain on windows
- Fix `llvm-builder` to work with `.exe` files
- Unify the llvm release jobs into a single one. This removed a lot of
copy pasted code and also speeds up the build by giving each their own
runner.
- Use the LLVM target triple to name the binary releases instead of an
ad-hoc naming convention
- Remove the nested folder hierarchy inside the llvm release. Its just
now a single folder `llvm-<target>` that contains the toolchain.
- Give jobs and workflows consistent names
- Replace all runners bei their `*-latest` counterpart
- Only use `parity-large` to build llvm now. All other jobs use github
runners
This commit is contained in:
Alexander Theißen
2025-02-28 15:06:03 +01:00
committed by GitHub
parent 93788e72e9
commit 2fb8beee62
16 changed files with 340 additions and 446 deletions
+41 -9
View File
@@ -1,5 +1,8 @@
//! Utilities for compiling the LLVM compiler-rt builtins.
use crate::utils::path_windows_to_unix as to_unix;
use std::{env::consts::EXE_EXTENSION, process::Command};
/// Static CFLAGS variable passed to the compiler building the compiler-rt builtins.
const C_FLAGS: [&str; 6] = [
"--target=riscv64",
@@ -44,24 +47,31 @@ fn cmake_dynamic_args(
let mut clang_path = llvm_target_host.to_path_buf();
clang_path.push("bin/clang");
clang_path.set_extension(EXE_EXTENSION);
let mut clangxx_path = llvm_target_host.to_path_buf();
clangxx_path.push("bin/clang++");
clangxx_path.set_extension(EXE_EXTENSION);
let mut llvm_config_path = llvm_target_host.to_path_buf();
llvm_config_path.push("bin/llvm-config");
llvm_config_path.set_extension(EXE_EXTENSION);
let mut ar_path = llvm_target_host.to_path_buf();
ar_path.push("bin/llvm-ar");
ar_path.set_extension(EXE_EXTENSION);
let mut nm_path = llvm_target_host.to_path_buf();
nm_path.push("bin/llvm-nm");
nm_path.set_extension(EXE_EXTENSION);
let mut ranlib_path = llvm_target_host.to_path_buf();
ranlib_path.push("bin/llvm-ranlib");
ranlib_path.set_extension(EXE_EXTENSION);
let mut linker_path = llvm_target_host.to_path_buf();
linker_path.push("bin/ld.lld");
linker_path.set_extension(EXE_EXTENSION);
Ok([
format!(
@@ -76,12 +86,18 @@ fn cmake_dynamic_args(
format!("-DCMAKE_C_FLAGS='{}'", C_FLAGS.join(" ")),
format!("-DCMAKE_ASM_FLAGS='{}'", C_FLAGS.join(" ")),
format!("-DCMAKE_CXX_FLAGS='{}'", C_FLAGS.join(" ")),
format!("-DCMAKE_C_COMPILER='{}'", clang_path.to_string_lossy()),
format!("-DCMAKE_ASM_COMPILER='{}'", clang_path.to_string_lossy()),
format!("-DCMAKE_CXX_COMPILER='{}'", clangxx_path.to_string_lossy()),
format!("-DCMAKE_AR='{}'", ar_path.to_string_lossy()),
format!("-DCMAKE_NM='{}'", nm_path.to_string_lossy()),
format!("-DCMAKE_RANLIB='{}'", ranlib_path.to_string_lossy()),
format!(
"-DCMAKE_C_COMPILER='{}'",
to_unix(clang_path.clone())?.display()
),
format!("-DCMAKE_ASM_COMPILER='{}'", to_unix(clang_path)?.display()),
format!(
"-DCMAKE_CXX_COMPILER='{}'",
to_unix(clangxx_path)?.display()
),
format!("-DCMAKE_AR='{}'", to_unix(ar_path)?.display()),
format!("-DCMAKE_NM='{}'", to_unix(nm_path)?.display()),
format!("-DCMAKE_RANLIB='{}'", to_unix(ranlib_path)?.display()),
format!(
"-DLLVM_CONFIG_PATH='{}'",
llvm_config_path.to_string_lossy()
@@ -101,7 +117,13 @@ pub fn build(
log::info!("building compiler-rt for rv64emac");
crate::utils::check_presence("cmake")?;
crate::utils::check_presence("ninja")?;
let generator = if cfg!(target_os = "windows") {
"Visual Studio 17 2022"
} else {
crate::utils::check_presence("ninja")?;
"Ninja"
};
let llvm_module_compiler_rt = crate::LLVMPath::llvm_module_compiler_rt()?;
let llvm_compiler_rt_build = crate::LLVMPath::llvm_build_compiler_rt()?;
@@ -114,7 +136,7 @@ pub fn build(
"-B",
llvm_compiler_rt_build.to_string_lossy().as_ref(),
"-G",
"Ninja",
generator,
])
.args(CMAKE_STATIC_ARGS)
.args(cmake_dynamic_args(build_type, target_env)?)
@@ -131,7 +153,17 @@ pub fn build(
"LLVM compiler-rt building cmake",
)?;
crate::utils::ninja(&llvm_compiler_rt_build)?;
crate::utils::command(
Command::new("cmake").args([
"--build",
llvm_compiler_rt_build.to_string_lossy().as_ref(),
"--target",
"install",
"--config",
build_type.to_string().as_str(),
]),
"Building",
)?;
Ok(())
}
+1 -1
View File
@@ -214,7 +214,7 @@ pub fn build(
sanitizer,
)?;
} else if cfg!(target_os = "windows") {
platforms::x86_64_windows_gnu::build(
platforms::x86_64_windows_msvc::build(
build_type,
targets,
llvm_projects,
+1 -1
View File
@@ -8,7 +8,7 @@ pub mod wasm32_emscripten;
pub mod x86_64_linux_gnu;
pub mod x86_64_linux_musl;
pub mod x86_64_macos;
pub mod x86_64_windows_gnu;
pub mod x86_64_windows_msvc;
use std::str::FromStr;
+3 -1
View File
@@ -8,7 +8,7 @@ use std::path::Path;
use std::process::Command;
/// The build options shared by all platforms.
pub const SHARED_BUILD_OPTS: [&str; 19] = [
pub const SHARED_BUILD_OPTS: [&str; 21] = [
"-DPACKAGE_VENDOR='Parity Technologies'",
"-DCMAKE_BUILD_WITH_INSTALL_RPATH=1",
"-DLLVM_BUILD_DOCS='Off'",
@@ -28,6 +28,8 @@ pub const SHARED_BUILD_OPTS: [&str; 19] = [
"-DCMAKE_EXPORT_COMPILE_COMMANDS='On'",
"-DPython3_FIND_REGISTRY='LAST'", // Use Python version from $PATH, not from registry
"-DBUG_REPORT_URL='https://github.com/paritytech/contract-issues/issues/'",
"-DCLANG_ENABLE_ARCMT='Off'",
"-DCLANG_ENABLE_STATIC_ANALYZER='Off'",
];
/// The build options shared by all platforms except MUSL.
@@ -1,7 +1,6 @@
//! The revive LLVM amd64 `windows-gnu` builder.
use std::collections::HashSet;
use std::path::PathBuf;
use std::process::Command;
use crate::build_type::BuildType;
@@ -28,10 +27,6 @@ pub fn build(
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
crate::utils::check_presence("cmake")?;
crate::utils::check_presence("clang")?;
crate::utils::check_presence("clang++")?;
crate::utils::check_presence("lld")?;
crate::utils::check_presence("ninja")?;
let llvm_module_llvm =
LLVMPath::llvm_module_llvm().and_then(crate::utils::path_windows_to_unix)?;
@@ -48,15 +43,12 @@ pub fn build(
"-B",
llvm_build_final.to_string_lossy().as_ref(),
"-G",
"Ninja",
"Visual Studio 17 2022",
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'",
"-DCMAKE_CXX_COMPILER='clang++'",
format!(
"-DLLVM_TARGETS_TO_BUILD='{}'",
targets
@@ -75,7 +67,7 @@ pub fn build(
.join(";")
)
.as_str(),
"-DLLVM_USE_LINKER='lld'",
"-DLLVM_BUILD_LLVM_C_DYLIB=Off",
])
.args(crate::platforms::shared::shared_build_opts_default_target(
default_target,
@@ -107,20 +99,16 @@ pub fn build(
"LLVM building cmake",
)?;
crate::utils::ninja(llvm_build_final.as_ref())?;
let libstdcpp_source_path = match std::env::var("LIBSTDCPP_SOURCE_PATH") {
Ok(libstdcpp_source_path) => PathBuf::from(libstdcpp_source_path),
Err(error) => anyhow::bail!(
"The `LIBSTDCPP_SOURCE_PATH` must be set to the path to the libstdc++.a static library: {}", error
),
};
let mut libstdcpp_destination_path = llvm_target_final;
libstdcpp_destination_path.push("./lib/libstdc++.a");
fs_extra::file::copy(
crate::utils::path_windows_to_unix(libstdcpp_source_path)?,
crate::utils::path_windows_to_unix(libstdcpp_destination_path)?,
&fs_extra::file::CopyOptions::default(),
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",
)?;
Ok(())
+3 -5
View File
@@ -7,6 +7,7 @@ use std::process::Command;
use std::process::Stdio;
use std::time::Duration;
use anyhow::Context;
use path_slash::PathBufExt;
/// The LLVM host repository URL.
@@ -131,11 +132,8 @@ pub fn path_windows_to_unix<P: AsRef<Path> + PathBufExt>(path: P) -> anyhow::Res
/// Checks if the tool exists in the system.
pub fn check_presence(name: &str) -> anyhow::Result<()> {
let description = &format!("checking the `{name}` executable");
log::info!("{description}");
command(Command::new("which").arg(name), description)
.map_err(|_| anyhow::anyhow!("Tool `{}` is missing. Please install", name))
which::which(name).with_context(|| format!("Tool `{name}` is missing. Please install"))?;
Ok(())
}
/// Identify XCode version using `pkgutil`.