Skip to content

Commit

Permalink
boulder-data: Support mold linker
Browse files Browse the repository at this point in the history
Mold is often noticeably faster than LLD (and much faster than BFD) and is already used by numerous packages for that reason. Make it more ergonomic to use by adding a top-level `mold` key which adds it as a builddep and sets environmental flags appropriately to use it.

Tested with both the gnu and LLVM toolchains.

Signed-off-by: Reilly Brogan <[email protected]>
  • Loading branch information
ReillyBrogan committed Jan 14, 2025
1 parent ffe8a27 commit ec2ef81
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
22 changes: 17 additions & 5 deletions boulder/src/build/job/phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ impl Phase {
parser.add_definition("compiler_objcxxcpp", "clang++ -E");
parser.add_definition("compiler_d", "ldc2");
parser.add_definition("compiler_ar", "llvm-ar");
parser.add_definition("compiler_ld", "ld.lld");
parser.add_definition("compiler_objcopy", "llvm-objcopy");
parser.add_definition("compiler_nm", "llvm-nm");
parser.add_definition("compiler_ranlib", "llvm-ranlib");
Expand All @@ -194,14 +193,21 @@ impl Phase {
parser.add_definition("compiler_objcxxcpp", "g++ -E");
parser.add_definition("compiler_d", "ldc2"); // FIXME: GDC
parser.add_definition("compiler_ar", "gcc-ar");
parser.add_definition("compiler_ld", "ld.bfd");
parser.add_definition("compiler_objcopy", "objcopy");
parser.add_definition("compiler_nm", "gcc-nm");
parser.add_definition("compiler_ranlib", "gcc-ranlib");
parser.add_definition("compiler_strip", "strip");
parser.add_definition("compiler_path", path);
}

if recipe.parsed.mold {
parser.add_definition("compiler_ld", "ld.mold");
} else if matches!(recipe.parsed.options.toolchain, Toolchain::Llvm) {
parser.add_definition("compiler_ld", "ld.lld");
} else {
parser.add_definition("compiler_ld", "ld.bfd");
}

/* Allow packagers to do stage specific actions in a pgo build */
if matches!(pgo_stage, Some(pgo::Stage::One)) {
parser.add_definition("pgo_stage", "ONE");
Expand Down Expand Up @@ -346,12 +352,12 @@ fn add_tuning(
let toolchain = recipe.parsed.options.toolchain;
let flags = tuning.build()?;

let cflags = fmt_flags(
let mut cflags = fmt_flags(
flags
.iter()
.filter_map(|flag| flag.get(tuning::CompilerFlag::C, toolchain)),
);
let cxxflags = fmt_flags(
let mut cxxflags = fmt_flags(
flags
.iter()
.filter_map(|flag| flag.get(tuning::CompilerFlag::Cxx, toolchain)),
Expand All @@ -366,12 +372,18 @@ fn add_tuning(
.iter()
.filter_map(|flag| flag.get(tuning::CompilerFlag::D, toolchain)),
);
let rustflags = fmt_flags(
let mut rustflags = fmt_flags(
flags
.iter()
.filter_map(|flag| flag.get(tuning::CompilerFlag::Rust, toolchain)),
);

if recipe.parsed.mold {
cflags.push_str(" -fuse-ld=mold");
cxxflags.push_str(" -fuse-ld=mold");
rustflags.push_str(" -Clink-arg=-fuse-ld=mold");
}

parser.add_definition("cflags", cflags);
parser.add_definition("cxxflags", cxxflags);
parser.add_definition("ldflags", ldflags);
Expand Down
6 changes: 6 additions & 0 deletions boulder/src/build/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ fn packages(builder: &Builder) -> Vec<&str> {
}
}

if builder.recipe.parsed.mold {
packages.extend(MOLD_PACKAGES);
}

if builder.ccache {
packages.extend(CCACHE_PACKAGES);
}
Expand Down Expand Up @@ -203,6 +207,8 @@ const GNU32_PACKAGES: &[&str] = &["gcc-32bit", "g++-32bit"];
const LLVM_PACKAGES: &[&str] = &["clang"];
const LLVM32_PACKAGES: &[&str] = &["clang-32bit", "libcxx-32bit-devel"];

const MOLD_PACKAGES: &[&str] = &["binary(mold)"];

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

#[derive(Debug, Error)]
Expand Down
2 changes: 2 additions & 0 deletions crates/stone_recipe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct Recipe {
pub tuning: Vec<KeyValue<Tuning>>,
#[serde(default, deserialize_with = "stringy_bool")]
pub emul32: bool,
#[serde(default, deserialize_with = "stringy_bool")]
pub mold: bool,
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit ec2ef81

Please sign in to comment.