Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/release-llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ jobs:
run: |
cargo install --locked --force --path crates/llvm-builder

- name: Clone LLVM
run: |
revive-llvm --target-env ${{ matrix.builder-arg }} clone

- name: Build LLVM
if: ${{ matrix.target != 'wasm32-unknown-emscripten' }}
run: |
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-llvm-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ on:
branches: ["main"]
types: [opened, synchronize]
paths:
- 'LLVM.lock'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should run when the .gitmodules has changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file no longer exists. The way it suppose to work in future is we update new llvm file with new commit to pull from LLVM

- 'crates/llvm-builder/**'
- '.github/workflows/test-llvm-builder.yml'
paths-ignore:
- "**.md"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -25,6 +22,8 @@ jobs:
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# without this it will override our rust flags
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ target-llvm
/*.yul
/*.ll
/*.s
/llvm*
/llvm-*
# Allow llvm submodule directory
!/llvm
node_modules
artifacts
tmp
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "llvm"]
path = llvm
url = https://github.com/llvm/llvm-project.git
branch = release/18.x
42 changes: 5 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions LLVM.lock

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ install-llvm-builder:
cargo install --force --locked --path crates/llvm-builder

install-llvm: install-llvm-builder
revive-llvm clone
git submodule update --init --recursive --depth 1
revive-llvm build --llvm-projects lld --llvm-projects clang

install-revive-runner:
Expand Down
2 changes: 0 additions & 2 deletions crates/llvm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ doctest = false
[dependencies]
clap = { workspace = true, features = ["help", "std", "derive"] }
anyhow = { workspace = true }
serde = { workspace = true, features = [ "derive" ] }
toml = { workspace = true }
num_cpus = { workspace = true }
fs_extra = { workspace = true }
path-slash = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/llvm-builder/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
84 changes: 7 additions & 77 deletions crates/llvm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -23,87 +21,21 @@ 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_submodule() -> anyhow::Result<()> {
utils::check_presence("git")?;

if target_env == TargetEnv::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");
}

utils::command(
Command::new("git")
.args(clone_args)
.arg(lock.url.as_str())
.arg(destination_path.to_string_lossy().as_ref()),
"LLVM repository cloning",
)?;

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",
)?;
if destination_path.join(".git").exists() {
log::info!("LLVM submodule already initialized");
return Ok(());
}

utils::command(
Command::new("git")
.current_dir(destination_path.as_path())
.args(["checkout", "--force", lock.branch.as_str()]),
"LLVM repository data pulling",
Command::new("git").args(["submodule", "update", "--init", "--recursive"]),
"LLVM submodule initialization",
)?;

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(())
}

Expand Down Expand Up @@ -332,8 +264,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(())
}
14 changes: 0 additions & 14 deletions crates/llvm-builder/src/revive_llvm/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down Expand Up @@ -77,13 +70,6 @@ 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,
},

/// Clean the build artifacts.
Clean,

Expand Down
21 changes: 6 additions & 15 deletions crates/llvm-builder/src/revive_llvm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pub(crate) mod arguments;

use std::collections::HashSet;
use std::path::PathBuf;
use std::str::FromStr;

use anyhow::Context;
Expand All @@ -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,
Expand All @@ -50,6 +42,12 @@ fn main_inner() -> anyhow::Result<()> {
sanitizer,
enable_valgrind,
} => {
if arguments.target_env == revive_llvm_builder::TargetEnv::Emscripten {
revive_llvm_builder::utils::install_emsdk()?;
}

revive_llvm_builder::init_submodule()?;

let mut targets = targets
.into_iter()
.map(|target| revive_llvm_builder::Platform::from_str(target.as_str()))
Expand Down Expand Up @@ -107,13 +105,6 @@ 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::Clean => {
revive_llvm_builder::clean()
.with_context(|| "Unable to remove target LLVM directory")?;
Expand Down
Loading
Loading