Skip to content

Commit

Permalink
Merge pull request #292 from serpent-os/boulder-sccache
Browse files Browse the repository at this point in the history
boulder: Add support for sccache
  • Loading branch information
ikeycode authored Aug 5, 2024
2 parents 0cbfc7c + db77a71 commit 1f16563
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions boulder/data/macros/arch/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ definitions:
- strip : "%(compiler_strip)"
- path : "%(compiler_path)"
- ccachedir : "%(compiler_cache)"
- sccachedir : "%(scompiler_cache)"
- pkgconfigpath : "%(libdir)/pkgconfig:/usr/share/pkgconfig"

actions :
Expand Down Expand Up @@ -85,6 +86,10 @@ actions :
PATH="%(path)"; export PATH
CCACHE_DIR="%(ccachedir)"; export CCACHE_DIR;
test -z "$CCACHE_DIR" && unset CCACHE_DIR;
RUSTC_WRAPPER="%(rustc_wrapper)"; export RUSTC_WRAPPER;
test -z "$RUSTC_WRAPPER" && unset RUSTC_WRAPPER;
SCCACHE_DIR="%(sccachedir)"; export SCCACHE_DIR;
test -z "$SCCACHE_DIR" && unset SCCACHE_DIR;
LANG="en_US.UTF-8"; export LANG
LC_ALL="en_US.UTF-8"; export LC_ALL
test -d "%(workdir)" || (echo "The work directory %(workdir) does not exist"; exit 1)
Expand Down
7 changes: 7 additions & 0 deletions boulder/src/build/job/phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl Phase {
parser.add_definition("workdir", work_dir.display());

parser.add_definition("compiler_cache", "/mason/ccache");
parser.add_definition("scompiler_cache", "/mason/sccache");

parser.add_definition("sourcedateepoch", recipe.build_time.timestamp());

Expand All @@ -158,6 +159,12 @@ impl Phase {
"/usr/bin:/bin"
};

if ccache {
parser.add_definition("rustc_wrapper", "/usr/bin/sccache");
} else {
parser.add_definition("rustc_wrapper", "");
}

/* Set the relevant compilers */
if matches!(recipe.parsed.options.toolchain, Toolchain::Llvm) {
parser.add_definition("compiler_c", "clang");
Expand Down
4 changes: 2 additions & 2 deletions boulder/src/build/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn packages(builder: &Builder) -> Vec<&str> {
}

if builder.ccache {
packages.push(CCACHE_PACKAGE);
packages.extend(CCACHE_PACKAGES);
}

packages.extend(builder.recipe.parsed.build.build_deps.iter().map(String::as_str));
Expand Down Expand Up @@ -185,7 +185,7 @@ const GNU32_PACKAGES: &[&str] = &["gcc-32bit-devel"];
const LLVM_PACKAGES: &[&str] = &["clang"];
const LLVM32_PACKAGES: &[&str] = &["clang-32bit", "libcxx-32bit-devel"];

const CCACHE_PACKAGE: &str = "binary(ccache)";
const CCACHE_PACKAGES: &[&str] = &["binary(ccache)", "binary(sccache)"];

#[derive(Debug, Error)]
pub enum Error {
Expand Down
2 changes: 2 additions & 0 deletions boulder/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ where
let artefacts = paths.artefacts();
let build = paths.build();
let compiler = paths.ccache();
let rustc_wrapper = paths.sccache();
let recipe = paths.recipe();

Container::new(rootfs)
Expand All @@ -32,6 +33,7 @@ where
.bind_rw(&artefacts.host, &artefacts.guest)
.bind_rw(&build.host, &build.guest)
.bind_rw(&compiler.host, &compiler.guest)
.bind_rw(&rustc_wrapper.host, &rustc_wrapper.guest)
.bind_ro(&recipe.host, &recipe.guest)
.run::<E>(f)?;

Expand Down
8 changes: 8 additions & 0 deletions boulder/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl Paths {
util::ensure_dir_exists(&job.artefacts().host)?;
util::ensure_dir_exists(&job.build().host)?;
util::ensure_dir_exists(&job.ccache().host)?;
util::ensure_dir_exists(&job.sccache().host)?;
util::ensure_dir_exists(&job.upstreams().host)?;

Ok(job)
Expand Down Expand Up @@ -83,6 +84,13 @@ impl Paths {
}
}

pub fn sccache(&self) -> Mapping {
Mapping {
host: self.host_root.join("sccache"),
guest: self.guest_root.join("sccache"),
}
}

pub fn upstreams(&self) -> Mapping {
Mapping {
host: self.host_root.join("upstreams"),
Expand Down

0 comments on commit 1f16563

Please sign in to comment.