add LLVM 18.x as a git submodule (#399)

This changeset is based on https://github.com/paritytech/revive/pull/346
This commit is contained in:
kvpanch
2025-11-18 16:10:15 -05:00
committed by GitHub
parent a1090cfa5a
commit e78f3cc419
18 changed files with 89 additions and 310 deletions
+24 -49
View File
@@ -4,16 +4,10 @@ use std::process::Command;
use assert_cmd::{cargo, prelude::*};
/// This test verifies that the LLVM repository can be successfully cloned, built, and cleaned.
/// This test verifies that the LLVM repository can be successfully built and cleaned.
#[test]
fn clone_build_and_clean() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
fn build_and_clean() -> anyhow::Result<()> {
let test_dir = common::TestDir::new()?;
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
@@ -40,18 +34,12 @@ fn clone_build_and_clean() -> anyhow::Result<()> {
Ok(())
}
/// This test verifies that the LLVM repository can be successfully cloned, built, and cleaned
/// This test verifies that the LLVM repository can be successfully 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::new(cargo::cargo_bin!("revive-llvm"))
.arg("clone")
.current_dir(test_dir.path())
.assert()
.success();
fn build_and_clean_musl() -> anyhow::Result<()> {
let test_dir = common::TestDir::new()?;
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
@@ -84,18 +72,12 @@ fn clone_build_and_clean_musl() -> anyhow::Result<()> {
Ok(())
}
/// This test verifies that the LLVM repository can be successfully cloned and built in debug mode
/// This test verifies that the LLVM repository can be successfully built in debug mode
/// with tests and coverage enabled.
#[test]
#[cfg(target_os = "linux")]
fn debug_build_with_tests_coverage() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
let test_dir = common::TestDir::new()?;
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
@@ -118,13 +100,7 @@ fn debug_build_with_tests_coverage() -> anyhow::Result<()> {
#[test]
#[cfg(target_os = "linux")]
fn build_with_sanitizers() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
let test_dir = common::TestDir::new()?;
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
@@ -141,27 +117,28 @@ fn build_with_sanitizers() -> anyhow::Result<()> {
Ok(())
}
/// Tests the clone, build, and clean process of the LLVM repository for the emscripten target.
/// Tests the build and clean process of the LLVM repository for the emscripten target.
#[test]
#[cfg(target_os = "linux")]
fn clone_build_and_clean_emscripten() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?;
fn build_and_clean_emscripten() -> anyhow::Result<()> {
let test_dir = common::TestDir::new()?;
let command = Command::new(cargo::cargo_bin!("revive-llvm"));
let program = command.get_program().to_string_lossy();
let path = test_dir.path();
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("clone")
.current_dir(path)
.arg("build")
.arg("--llvm-projects")
.arg("clang")
.arg("--llvm-projects")
.arg("lld")
.assert()
.success();
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("build")
.arg("--llvm-projects")
.arg("lld")
.arg("--llvm-projects")
.arg("clang")
.current_dir(path)
.arg("emsdk")
.assert()
.success();
@@ -170,22 +147,20 @@ fn clone_build_and_clean_emscripten() -> anyhow::Result<()> {
// `cd {} && . ./emsdk_env.sh && cd ..` helps the script to locate `emsdk.py`
// @see https://github.com/emscripten-core/emsdk/blob/9dbdc4b3437750b85d16931c7c801bb71a782122/emsdk_env.sh#L61-L69
let emsdk_wrapped_build_command = format!(
"{program} --target-env emscripten clone && \
cd {} && . ./emsdk_env.sh && cd .. && \
"cd {} && . ./emsdk_env.sh && cd .. && \
{program} --target-env emscripten build --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())
.current_dir(path)
.assert()
.success();
Command::new(cargo::cargo_bin!("revive-llvm"))
.arg("clean")
.current_dir(test_dir.path())
.current_dir(path)
.assert()
.success();
-48
View File
@@ -1,48 +0,0 @@
pub mod common;
use std::process::Command;
use assert_cmd::{cargo, 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::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Command::new(cargo::cargo_bin!("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::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("clone")
.assert()
.success();
Command::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("checkout")
.arg("--force")
.assert()
.success();
Ok(())
}
-36
View File
@@ -1,36 +0,0 @@
pub mod common;
use std::process::Command;
use assert_cmd::{cargo, 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::new(cargo::cargo_bin!("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::new(cargo::cargo_bin!("revive-llvm"))
.current_dir(test_dir.path())
.arg("clone")
.arg("--deep")
.assert()
.success();
Ok(())
}
+38 -19
View File
@@ -1,32 +1,51 @@
use assert_fs::fixture::FileWriteStr;
use assert_fs::TempDir;
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,
_tempdir: TempDir,
path: std::path::PathBuf,
}
/// Creates a temporary lock file for testing.
/// Creates a temporary directory for testing with submodule setup.
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())?;
pub fn new() -> anyhow::Result<Self> {
let tempdir = TempDir::new()?;
let tmppath = tempdir.path();
// Initialize a git repo and add the LLVM submodule
std::process::Command::new("git")
.args(["init"])
.current_dir(tmppath)
.output()?;
std::process::Command::new("git")
.args([
"submodule",
"add",
"-b",
"release/18.x",
"https://github.com/llvm/llvm-project.git",
"llvm",
])
.current_dir(tmppath)
.output()?;
std::process::Command::new("git")
.args([
"submodule",
"update",
"--init",
"--recursive",
"--force",
"--depth 1",
])
.current_dir(tmppath)
.output()?;
Ok(Self {
path: file
.parent()
.expect("lockfile parent dir always exists")
.into(),
_lockfile: file,
path: tmppath.to_path_buf(),
_tempdir: tempdir,
})
}