diff --git a/.github/workflows/enzyme-ci.yml b/.github/workflows/enzyme-ci.yml index edc48879479e8..c233b049e1d6d 100644 --- a/.github/workflows/enzyme-ci.yml +++ b/.github/workflows/enzyme-ci.yml @@ -21,18 +21,44 @@ jobs: timeout-minutes: 600 steps: - - name: checkout the source code - uses: actions/checkout@v3 + - name: Checkout Rust source + uses: actions/checkout@v4 with: fetch-depth: 2 - - name: build + - uses: dtolnay/rust-toolchain@nightly + - name: Get LLVM commit hash + id: llvm-commit + run: echo "HEAD=$(git -C src/llvm-project rev-parse HEAD)" >> $GITHUB_OUTPUT + - name: Cache LLVM + id: cache-llvm + uses: actions/cache@v4 + with: + path: build/build/x86_64-unknown-linux-gnu/llvm + key: ${{ matrix.os }}-llvm-${{ steps.llvm-commit.outputs.HEAD }} + - name: Get Enzyme commit hash + id: enzyme-commit + run: echo "HEAD=$(git -C src/tools/enzyme rev-parse HEAD)" >> $GITHUB_OUTPUT + - name: Cache Enzyme + id: cache-enzyme + uses: actions/cache@v4 + with: + path: build/build/x86_64-unknown-linux-gnu/enzyme + key: ${{ matrix.os }}-enzyme-${{ steps.enzyme-commit.outputs.HEAD }} + - name: Build run: | - mkdir build + mkdir -p build cd build + rm -f config.toml ../configure --enable-llvm-link-shared --enable-llvm-plugins --enable-llvm-enzyme --release-channel=nightly --enable-llvm-assertions --enable-lld --enable-option-checking --enable-ninja --disable-docs ../x.py build --stage 1 library/std library/proc_macro library/test tools/rustdoc - rustup toolchain link enzyme `pwd`/build/`rustup target list --installed`/stage1 - rustup toolchain install nightly # enables -Z unstable-options - - name: test + rustup toolchain link enzyme build/host/stage1 + - name: checkout Enzyme/rustbook + uses: actions/checkout@v4 + with: + repository: EnzymeAD/rustbook + ref: main + path: rustbook + - name: test Enzyme/rustbook + working-directory: rustbook run: | - cargo +enzyme test --examples + cargo +enzyme test --workspace diff --git a/README.md b/README.md index 425ed87f3718c..594c69d0453be 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Afterwards you can build rustc using: Afterwards rustc toolchain link will allow you to use it through cargo: ``` -rustup toolchain link enzyme `pwd`/build/`rustup target list --installed`/stage1 +rustup toolchain link enzyme build/host/stage1 rustup toolchain install nightly # enables -Z unstable-options ``` diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 4e18806493e3e..6736b985ebeba 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -844,13 +844,34 @@ impl Step for Enzyme { let LlvmResult { llvm_config, llvm_cmake_dir } = builder.ensure(Llvm { target }); + static STAMP_HASH_MEMO: OnceLock = OnceLock::new(); + let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| { + generate_smart_stamp_hash( + &builder.config.src.join("src/tools/enzyme"), + &builder.enzyme_info.sha().unwrap_or_default(), + ) + }); + let out_dir = builder.enzyme_out(target); - let done_stamp = out_dir.join("enzyme-finished-building"); - if done_stamp.exists() { + let stamp = out_dir.join("enzyme-finished-building"); + let stamp = HashStamp::new(stamp, Some(smart_stamp_hash)); + + if stamp.is_done() { + if stamp.hash.is_none() { + builder.info( + "Could not determine the Enzyme submodule commit hash. \ + Assuming that an Enzyme rebuild is not necessary.", + ); + builder.info(&format!( + "To force Enzyme to rebuild, remove the file `{}`", + stamp.path.display() + )); + } return out_dir; } builder.info(&format!("Building Enzyme for {}", target)); + t!(stamp.remove()); let _time = helpers::timeit(&builder); t!(fs::create_dir_all(&out_dir)); @@ -878,7 +899,8 @@ impl Step for Enzyme { cfg.build(); - t!(File::create(&done_stamp)); + t!(stamp.write()); + out_dir } } diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 5038c888bca53..a733e55c8f9d6 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -168,6 +168,7 @@ pub struct Build { clippy_info: GitInfo, miri_info: GitInfo, rustfmt_info: GitInfo, + enzyme_info: GitInfo, in_tree_llvm_info: GitInfo, local_rebuild: bool, fail_fast: bool, @@ -331,6 +332,7 @@ impl Build { let clippy_info = GitInfo::new(omit_git_hash, &src.join("src/tools/clippy")); let miri_info = GitInfo::new(omit_git_hash, &src.join("src/tools/miri")); let rustfmt_info = GitInfo::new(omit_git_hash, &src.join("src/tools/rustfmt")); + let enzyme_info = GitInfo::new(omit_git_hash, &src.join("src/tools/enzyme")); // we always try to use git for LLVM builds let in_tree_llvm_info = GitInfo::new(false, &src.join("src/llvm-project")); @@ -413,6 +415,7 @@ impl Build { clippy_info, miri_info, rustfmt_info, + enzyme_info, in_tree_llvm_info, cc: RefCell::new(HashMap::new()), cxx: RefCell::new(HashMap::new()),