revive llvm builder utility (#154)

Pre-eliminary support for LLVM releases and resolc binary releases by streamlining the build process for all supported hosts platforms.

- Introduce the revive-llvm-builder crate with the revive-llvm builder utilty.
- Do not rely on the LLVM dependency in $PATH to decouple the system LLVM installation from the LLVM host dependency.
- Fix the emscripten build by decoupling the host and native LLVM dependencies. Thus allowing a single LLVM emscripten release that can be used on any host platform.
- An example Dockerfile building an alpine container with a fully statically linked resolc ELF binary.
- Remove the Debian builder utilities and workflow.
This commit is contained in:
Cyrill Leutwiler
2025-01-13 15:58:27 +01:00
committed by GitHub
parent fde9edab10
commit 7f81f37e0c
65 changed files with 4847 additions and 557 deletions
+158
View File
@@ -0,0 +1,158 @@
pub mod common;
use std::process::Command;
use assert_cmd::prelude::*;
/// This test verifies that the LLVM repository can be successfully cloned, built, and cleaned.
#[test]
fn clone_build_and_clean() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("build")
.arg("--llvm-projects")
.arg("clang")
.arg("--llvm-projects")
.arg("lld")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("builtins")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clean")
.assert()
.success();
Ok(())
}
/// This test verifies that the LLVM repository can be successfully cloned, built, and cleaned
/// with 2-staged build using MUSL as sysroot.
#[test]
#[cfg(target_os = "linux")]
fn clone_build_and_clean_musl() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.arg("clone")
.current_dir(test_dir.path())
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.arg("--target-env")
.arg("musl")
.arg("build")
.arg("--llvm-projects")
.arg("clang")
.arg("--llvm-projects")
.arg("lld")
.current_dir(test_dir.path())
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("builtins")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clean")
.assert()
.success();
Ok(())
}
/// This test verifies that the LLVM repository can be successfully cloned and built in debug mode
/// with tests and coverage enabled.
#[test]
fn debug_build_with_tests_coverage() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("build")
.arg("--enable-coverage")
.arg("--enable-tests")
.arg("--build-type")
.arg("Debug")
.assert()
.success();
Ok(())
}
/// This test verifies that the LLVM repository can be successfully built with address sanitizer.
#[test]
fn build_with_sanitizers() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("build")
.arg("--sanitizer")
.arg("Address")
.assert()
.success();
Ok(())
}
/// Tests the clone, build, and clean process of the LLVM repository for the emscripten target.
#[test]
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn clone_build_and_clean_emscripten() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
let command = Command::cargo_bin(common::REVIVE_LLVM)?;
let program = command.get_program().to_string_lossy();
let emsdk_wrapped_build_command = format!(
"{program} --target-env emscripten clone && \
source {}emsdk_env.sh && \
{program} --target-env emscripten build --llvm-projects clang --llvm-projects lld",
revive_llvm_builder::LLVMPath::DIRECTORY_EMSDK_SOURCE,
);
Command::new("sh")
.arg("-c")
.arg(emsdk_wrapped_build_command)
.current_dir(test_dir.path())
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.arg("clean")
.current_dir(test_dir.path())
.assert()
.success();
Ok(())
}
+48
View File
@@ -0,0 +1,48 @@
pub mod common;
use std::process::Command;
use assert_cmd::prelude::*;
/// This test verifies that after cloning the LLVM repository, checking out a specific branch
/// or reference works as expected.
#[test]
fn checkout_after_clone() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("checkout")
.assert()
.success();
Ok(())
}
/// This test verifies that after cloning the LLVM repository, checking out a specific branch
/// or reference with the `--force` option works as expected.
#[test]
fn force_checkout() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("checkout")
.arg("--force")
.assert()
.success();
Ok(())
}
+36
View File
@@ -0,0 +1,36 @@
pub mod common;
use std::process::Command;
use assert_cmd::prelude::*;
/// This test verifies that the LLVM repository can be successfully cloned using a specific branch
/// and reference.
#[test]
fn clone() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Ok(())
}
/// This test verifies that the LLVM repository can be successfully cloned using a specific branch
/// and reference with --deep option.
#[test]
fn clone_deep() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::cargo_bin(common::REVIVE_LLVM)?
.current_dir(test_dir.path())
.arg("clone")
.arg("--deep")
.assert()
.success();
Ok(())
}
+36
View File
@@ -0,0 +1,36 @@
use assert_fs::fixture::FileWriteStr;
pub const REVIVE_LLVM: &str = "revive-llvm";
pub const REVIVE_LLVM_REPO_URL: &str = "https://github.com/llvm/llvm-project";
pub const REVIVE_LLVM_REPO_TEST_BRANCH: &str = "release/18.x";
pub struct TestDir {
_lockfile: assert_fs::NamedTempFile,
path: std::path::PathBuf,
}
/// Creates a temporary lock file for testing.
impl TestDir {
pub fn with_lockfile(reference: Option<String>) -> anyhow::Result<Self> {
let file =
assert_fs::NamedTempFile::new(revive_llvm_builder::lock::LLVM_LOCK_DEFAULT_PATH)?;
let lock = revive_llvm_builder::Lock {
url: REVIVE_LLVM_REPO_URL.to_string(),
branch: REVIVE_LLVM_REPO_TEST_BRANCH.to_string(),
r#ref: reference,
};
file.write_str(toml::to_string(&lock)?.as_str())?;
Ok(Self {
path: file
.parent()
.expect("lockfile parent dir always exists")
.into(),
_lockfile: file,
})
}
pub fn path(&self) -> &std::path::Path {
&self.path
}
}