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
+2 -1
View File
@@ -4,13 +4,14 @@ 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] = [
const C_FLAGS: [&str; 7] = [
"--target=riscv64",
"-march=rv64emac",
"-mabi=lp64e",
"-mcpu=generic-rv64",
"-nostdlib",
"-nodefaultlibs",
"-fuse-ld=lld",
];
/// Static CMAKE arguments for building the compiler-rt builtins.
+8 -74
View File
@@ -5,7 +5,6 @@ pub mod builtins;
pub mod ccache_variant;
pub mod llvm_path;
pub mod llvm_project;
pub mod lock;
pub mod platforms;
pub mod sanitizer;
pub mod target_env;
@@ -14,7 +13,6 @@ pub mod utils;
pub use self::build_type::BuildType;
pub use self::llvm_path::LLVMPath;
pub use self::lock::Lock;
pub use self::platforms::Platform;
use std::collections::HashSet;
@@ -23,87 +21,25 @@ use std::process::Command;
pub use target_env::TargetEnv;
pub use target_triple::TargetTriple;
/// Executes the LLVM repository cloning.
pub fn clone(lock: Lock, deep: bool, target_env: TargetEnv) -> anyhow::Result<()> {
/// Initializes the LLVM submodule if not already done.
pub fn init(init_emscripten: bool) -> anyhow::Result<()> {
utils::check_presence("git")?;
if target_env == TargetEnv::Emscripten {
if init_emscripten {
utils::install_emsdk()?;
}
let destination_path = PathBuf::from(LLVMPath::DIRECTORY_LLVM_SOURCE);
if destination_path.exists() {
log::warn!(
"LLVM repository directory {} already exists, falling back to checkout",
destination_path.display()
);
return checkout(lock, false);
}
let mut clone_args = vec!["clone", "--branch", lock.branch.as_str()];
if !deep {
clone_args.push("--depth");
clone_args.push("1");
if destination_path.join(".git").exists() {
log::info!("LLVM submodule already initialized");
return Ok(());
}
utils::command(
Command::new("git")
.args(clone_args)
.arg(lock.url.as_str())
.arg(destination_path.to_string_lossy().as_ref()),
"LLVM repository cloning",
Command::new("git").args(["submodule", "update", "--init", "--recursive"]),
"LLVM submodule initialization",
)?;
if let Some(r#ref) = lock.r#ref {
utils::command(
Command::new("git")
.args(["checkout", r#ref.as_str()])
.current_dir(destination_path.to_string_lossy().as_ref()),
"LLVM repository commit checking out",
)?;
}
Ok(())
}
/// Executes the checkout of the specified branch.
pub fn checkout(lock: Lock, force: bool) -> anyhow::Result<()> {
let destination_path = PathBuf::from(LLVMPath::DIRECTORY_LLVM_SOURCE);
utils::command(
Command::new("git")
.current_dir(destination_path.as_path())
.args(["fetch", "--all", "--tags"]),
"LLVM repository data fetching",
)?;
if force {
utils::command(
Command::new("git")
.current_dir(destination_path.as_path())
.args(["clean", "-d", "-x", "--force"]),
"LLVM repository cleaning",
)?;
}
utils::command(
Command::new("git")
.current_dir(destination_path.as_path())
.args(["checkout", "--force", lock.branch.as_str()]),
"LLVM repository data pulling",
)?;
if let Some(r#ref) = lock.r#ref {
let mut checkout_command = Command::new("git");
checkout_command.current_dir(destination_path.as_path());
checkout_command.arg("checkout");
if force {
checkout_command.arg("--force");
}
checkout_command.arg(r#ref);
utils::command(&mut checkout_command, "LLVM repository checking out")?;
}
Ok(())
}
@@ -332,8 +268,6 @@ pub fn clean() -> anyhow::Result<()> {
.expect("target_env parent directory is target-llvm"),
)?;
remove_if_exists(&PathBuf::from(LLVMPath::DIRECTORY_EMSDK_SOURCE))?;
remove_if_exists(&PathBuf::from(LLVMPath::DIRECTORY_LLVM_SOURCE))?;
remove_if_exists(&PathBuf::from(LLVMPath::DIRECTORY_LLVM_HOST_SOURCE))?;
Ok(())
}
-37
View File
@@ -1,37 +0,0 @@
//! The revive LLVM builder lock file.
use anyhow::Context;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use serde::Deserialize;
use serde::Serialize;
/// The default lock file location.
pub const LLVM_LOCK_DEFAULT_PATH: &str = "LLVM.lock";
/// The lock file data.
///
/// This file describes the exact reference of the LLVM framework.
#[derive(Debug, Deserialize, Serialize)]
pub struct Lock {
/// The LLVM repository URL.
pub url: String,
/// The LLVM repository branch.
pub branch: String,
/// The LLVM repository commit reference.
pub r#ref: Option<String>,
}
impl TryFrom<&PathBuf> for Lock {
type Error = anyhow::Error;
fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
let mut config_str = String::new();
let mut config_file =
File::open(path).with_context(|| format!("Error opening {path:?} file"))?;
config_file.read_to_string(&mut config_str)?;
Ok(toml::from_str(&config_str)?)
}
}
@@ -18,13 +18,6 @@ pub struct Arguments {
/// The revive LLVM builder arguments.
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
/// Clone the branch specified in `LLVM.lock`.
Clone {
/// Clone with full commits history.
#[arg(long)]
deep: bool,
},
/// Build the LLVM framework.
Build {
/// LLVM build type (`Debug`, `Release`, `RelWithDebInfo`, or `MinSizeRel`).
@@ -77,12 +70,8 @@ pub enum Subcommand {
enable_valgrind: bool,
},
/// Checkout the branch specified in `LLVM.lock`.
Checkout {
/// Remove all artifacts preventing the checkout (removes all local changes!).
#[arg(long)]
force: bool,
},
/// Install emsdk
Emsdk,
/// Clean the build artifacts.
Clean,
+4 -13
View File
@@ -3,7 +3,6 @@
pub(crate) mod arguments;
use std::collections::HashSet;
use std::path::PathBuf;
use std::str::FromStr;
use anyhow::Context;
@@ -29,13 +28,6 @@ fn main_inner() -> anyhow::Result<()> {
revive_llvm_builder::utils::directory_target_llvm(arguments.target_env);
match arguments.subcommand {
Subcommand::Clone { deep } => {
let lock = revive_llvm_builder::Lock::try_from(&PathBuf::from(
revive_llvm_builder::lock::LLVM_LOCK_DEFAULT_PATH,
))?;
revive_llvm_builder::clone(lock, deep, arguments.target_env)?;
}
Subcommand::Build {
build_type,
targets,
@@ -50,6 +42,8 @@ fn main_inner() -> anyhow::Result<()> {
sanitizer,
enable_valgrind,
} => {
revive_llvm_builder::init(false)?;
let mut targets = targets
.into_iter()
.map(|target| revive_llvm_builder::Platform::from_str(target.as_str()))
@@ -107,11 +101,8 @@ fn main_inner() -> anyhow::Result<()> {
)?;
}
Subcommand::Checkout { force } => {
let lock = revive_llvm_builder::Lock::try_from(&PathBuf::from(
revive_llvm_builder::lock::LLVM_LOCK_DEFAULT_PATH,
))?;
revive_llvm_builder::checkout(lock, force)?;
Subcommand::Emsdk => {
revive_llvm_builder::init(true)?;
}
Subcommand::Clean => {