Skip to content

Commit 620c907

Browse files
committed
Auto merge of rust-lang#140244 - Shourya742:2025-04-24-enzyme-distribution, r=<try>
Add enzyme distribution step This PR adds enzyme to bootstrap dist. r? `@ghost` try-job: dist-x86_64-linux
2 parents f97b3c6 + 11ddc6b commit 620c907

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

src/bootstrap/src/core/build_steps/dist.rs

+52
Original file line numberDiff line numberDiff line change
@@ -2599,3 +2599,55 @@ impl Step for Gcc {
25992599
tarball.generate()
26002600
}
26012601
}
2602+
2603+
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
2604+
pub struct Enzyme {
2605+
pub target: TargetSelection,
2606+
}
2607+
2608+
impl Step for Enzyme {
2609+
type Output = Option<GeneratedTarball>;
2610+
const DEFAULT: bool = false;
2611+
const ONLY_HOSTS: bool = true;
2612+
2613+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2614+
run.alias("enzyme")
2615+
}
2616+
2617+
fn make_run(run: RunConfig<'_>) {
2618+
run.builder.ensure(Enzyme { target: run.target });
2619+
}
2620+
2621+
fn run(self, builder: &Builder<'_>) -> Self::Output {
2622+
let mut tarball = Tarball::new(builder, "enzyme", &self.target.triple);
2623+
let enzyme_dir =
2624+
builder.ensure(super::llvm::Enzyme { target: self.target }).join("build/Enzyme");
2625+
2626+
tarball.set_overlay(OverlayKind::Enzyme);
2627+
tarball.is_preview(true);
2628+
2629+
if let Some(llvm_config) = builder.llvm_config(builder.config.build) {
2630+
let major = llvm::get_llvm_version_major(builder, &llvm_config);
2631+
let prefix = format!("libEnzyme-{major}");
2632+
let mut found = false;
2633+
2634+
for entry in std::fs::read_dir(&enzyme_dir)
2635+
.unwrap_or_else(|_| panic!("Failed to read {:?}", enzyme_dir))
2636+
{
2637+
let path = entry.unwrap().path();
2638+
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
2639+
if name.starts_with(&prefix) && is_dylib(&path) {
2640+
tarball.add_file(path, "", FileType::NativeLibrary);
2641+
found = true;
2642+
}
2643+
}
2644+
}
2645+
2646+
assert!(found, "Enzyme library starting with '{}' not found", prefix);
2647+
tarball.add_legal_and_readme_to("share/doc/enzyme");
2648+
return Some(tarball.generate());
2649+
}
2650+
2651+
None
2652+
}
2653+
}

src/bootstrap/src/core/build_steps/llvm.rs

+9
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,14 @@ impl Step for Enzyme {
903903
),
904904
)]
905905
fn run(self, builder: &Builder<'_>) -> PathBuf {
906+
// FIXME: This can be removed once we start shipping the CMake files needed by Enzyme
907+
// to build against a standalone LLVM binary.
908+
// For now, Enzyme must be built with the in-tree LLVM and shared LLVM (`llvm.link-shared = true`), not one downloaded from CI.
909+
if builder.config.llvm_from_ci || !builder.config.llvm_link_shared() {
910+
panic!(
911+
"Enzyme must be built with an in-tree LLVM and requires `llvm.link-shared = true`.Set `llvm.download-ci-llvm = false` and `llvm.link-shared = true` to build Enzyme."
912+
);
913+
}
906914
builder.require_submodule(
907915
"src/tools/enzyme",
908916
Some("The Enzyme sources are required for autodiff."),
@@ -970,6 +978,7 @@ impl Step for Enzyme {
970978
.env("LLVM_CONFIG_REAL", &llvm_config)
971979
.define("LLVM_ENABLE_ASSERTIONS", "ON")
972980
.define("ENZYME_EXTERNAL_SHARED_LIB", "ON")
981+
// Enzyme must be built against this exact LLVM build — mixing versions breaks compatibility.
973982
.define("LLVM_DIR", builder.llvm_out(target));
974983

975984
cfg.build();

src/bootstrap/src/core/builder/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ impl<'a> Builder<'a> {
10841084
dist::PlainSourceTarball,
10851085
dist::BuildManifest,
10861086
dist::ReproducibleArtifacts,
1087-
dist::Gcc
1087+
dist::Gcc,
1088+
dist::Enzyme
10881089
),
10891090
Kind::Install => describe!(
10901091
install::Docs,

src/bootstrap/src/utils/tarball.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub(crate) enum OverlayKind {
2626
RustAnalyzer,
2727
RustcCodegenCranelift,
2828
LlvmBitcodeLinker,
29+
Enzyme,
2930
}
3031

3132
impl OverlayKind {
@@ -72,6 +73,7 @@ impl OverlayKind {
7273
"LICENSE-MIT",
7374
"src/tools/llvm-bitcode-linker/README.md",
7475
],
76+
OverlayKind::Enzyme => &["src/tools/enzyme/Readme.md", "src/tools/enzyme/LICENSE"],
7577
}
7678
}
7779

@@ -94,6 +96,7 @@ impl OverlayKind {
9496
.version(builder, &builder.release_num("rust-analyzer/crates/rust-analyzer")),
9597
OverlayKind::RustcCodegenCranelift => builder.rust_version(),
9698
OverlayKind::LlvmBitcodeLinker => builder.rust_version(),
99+
OverlayKind::Enzyme => builder.rust_version(),
97100
}
98101
}
99102
}

src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ ENV SCRIPT python3 ../x.py build --set rust.debug=true opt-dist && \
103103
--include-default-paths \
104104
build-manifest bootstrap && \
105105
# Use GCC for building GCC, as it seems to behave badly when built with Clang
106-
CC=/rustroot/bin/cc CXX=/rustroot/bin/c++ python3 ../x.py dist gcc
106+
# Also build Enzyme only on the x64 Linux dist runner
107+
CC=/rustroot/bin/cc CXX=/rustroot/bin/c++ python3 ../x.py dist gcc && ../x.py dist enzyme
107108
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
108109

109110
# This is the only builder which will create source tarballs

0 commit comments

Comments
 (0)