Skip to content

Commit

Permalink
fix: [xtask] remove build-tools related code
Browse files Browse the repository at this point in the history
  • Loading branch information
qjerome committed Jul 12, 2024
1 parent dd3678c commit f013333
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 399 deletions.
9 changes: 2 additions & 7 deletions xtask/src/ebpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use std::{
use clap::Parser;
use json::JsonValue;

use crate::utils;

#[derive(Debug, Copy, Clone)]
pub enum BpfTarget {
BpfEl,
Expand Down Expand Up @@ -70,10 +68,6 @@ impl BuildOptions {

if let Some(linker) = &self.linker {
rustflags.push(format!("-C linker={linker}"));
} else if let Ok(linker) =
utils::find_first_in("./build-tools", "bpf-linker").and_then(|p| p.canonicalize())
{
rustflags.push(format!("-C linker={}", linker.to_string_lossy()));
}

// we add linker arguments
Expand Down Expand Up @@ -207,7 +201,8 @@ fn fix_path_in_json(root: &str, val: &mut JsonValue) {
}

pub fn check(dir: &str, opts: &mut BuildOptions) -> Result<(), anyhow::Error> {
let output = cargo("clippy", dir, opts)
// clippy does not seem to work, is that really important ?
let output = cargo("check", dir, opts)
// we must use build_rustflags so that we have same options
// for build and check commands. Thus making build/check faster
.env("RUSTFLAGS", opts.build_rustflags())
Expand Down
110 changes: 0 additions & 110 deletions xtask/src/git.rs

This file was deleted.

97 changes: 1 addition & 96 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
mod ebpf;
mod git;
mod tools;
mod user;
mod utils;

use std::fs;
use std::path::PathBuf;
use std::{fs, io::ErrorKind};

use anyhow::anyhow;
use clap::Parser;
Expand Down Expand Up @@ -38,14 +35,11 @@ enum Command {
Run(user::RunOptions),
/// Cargo check the full project (eBPF and userland)
Check(user::BuildOptions),
/// Builds tools needed to compile the projects
BuildTools(tools::Options),
/// Run cargo release on the full project (includes eBPF code)
Release(ReleaseOptions),
}

static EBPF_DIR: &str = "kunai-ebpf";
static BUILD_TOOLS: &str = "build-tools";

fn main() -> Result<(), anyhow::Error> {
let opts = Options::parse();
Expand Down Expand Up @@ -85,95 +79,6 @@ fn main() -> Result<(), anyhow::Error> {
// checking ebpf code
ebpf::check(EBPF_DIR, &mut bpf_build_opt.build_args(bpf_check_args))?;
}
BuildTools(opts) => {
// checking we have the tools we need
utils::check_tools(vec!["git", "cmake", "ninja", "clang", "clang++", "lld"])?;

let pwd = std::env::current_dir().unwrap();
let bt_root = pwd.join(BUILD_TOOLS);

// specific branch we need to build linker
// this is Aya's rustc LLVM fork, it is used to integrate very
// specific LLVM patches faster than LLVM project
let llvm_repo = "https://github.com/aya-rs/llvm-project";
let llvm_branch = "rustc/17.0-2023-09-19";
let branch_dir = llvm_branch.replace('/', "_");
let llvm_dir = bt_root.join("llvm-project").join(&branch_dir);
let llvm_install = bt_root.join("llvm-install").join(&branch_dir);

// bpf-linker related variables
let linker_dir = bt_root.join("bpf-linker");

// handling specific linker commit
let linker_commit = {
// if bpf_linker_commit == last we fetch last commit
if opts.bpf_linker_commit.as_str() == "last" {
git::last_commit_id(&opts.bpf_linker_repo, &opts.bpf_linker_branch)?
} else {
opts.bpf_linker_commit.clone()
}
};

if opts.action_cache_key {
print!(
"build-tools-{}-{linker_commit}",
git::last_commit_id(llvm_repo, llvm_branch)?,
);
return Ok(());
}

// used to test LLVM installation
let llvm_config = llvm_install.join("bin").join("llvm-config");
if !llvm_config.is_file() || opts.force_llvm_build {
println!("Synchronizing repo:{llvm_repo} branch:{llvm_branch}");
git::sync(llvm_branch, llvm_repo, &llvm_dir, 1)?;

println!("Building LLVM");
let llvm_builder = tools::LLVMBuilder::new(&llvm_dir, &llvm_install);
llvm_builder.build()?;
}

// we free up all LLVM build artifacts
if opts.free_space {
println!("Removing LLVM build artifacts");
let res = std::fs::remove_dir_all(llvm_dir);
// if error is different from NotFound we return an error
if res.as_ref().is_err_and(|e| e.kind() != ErrorKind::NotFound) {
return Err(res.err().unwrap().into());
}
}

if opts.update {
let res = std::fs::remove_dir_all(&linker_dir);
// if error is different from NotFound we return an error
if res.as_ref().is_err_and(|e| e.kind() != ErrorKind::NotFound) {
return Err(res.err().unwrap().into());
}
}

if linker_dir.is_dir() {
println!("Resetting linker directory");
// we hacked Cargo.toml so we don't want this to block our git command
git::reset(&opts.bpf_linker_repo, &linker_dir)?;
}

println!(
"Synchronizing repo:{} branch:{}",
&opts.bpf_linker_repo, &opts.bpf_linker_branch
);
// we should rarely need more than 10 commits back
git::sync(
&opts.bpf_linker_branch,
&opts.bpf_linker_repo,
&linker_dir,
10,
)?;

println!("Checking out to commit: {linker_commit}");
git::checkout(&linker_dir, linker_commit)?;

tools::build_linker(&llvm_install, linker_dir, &opts)?;
}

Release(o) => {
// we process workspace first as eBPF code is using it
Expand Down
Loading

0 comments on commit f013333

Please sign in to comment.