From a727e2d1604187f2d4ac7f20f87f9ea580092c4e Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Tue, 5 Nov 2024 18:09:36 -0800 Subject: [PATCH] fix: make building of kernel errors file conditional on env variable --- .github/workflows/lint.yml | 15 +++++++++++++++ Makefile | 9 +++++---- miden-tx/build.rs | 10 ++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cd9130cee..87205c4b4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -71,3 +71,18 @@ jobs: override: true - name: check rust versions run: ./scripts/check-rust-version.sh + + kernel_errors: + name: kernel errors check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + - name: Rustup + run: rustup update --no-self-update + - uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/next' }} + - name: Rebuild kernel errors + run: BUILD_KERNEL_ERRORS=1 cargo check -p miden-tx + - name: Diff check + run: git diff --exit-code diff --git a/Makefile b/Makefile index c154c2c33..77df3b9de 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ help: WARNINGS=RUSTDOCFLAGS="-D warnings" DEBUG_ASSERTIONS=RUSTFLAGS="-C debug-assertions" ALL_FEATURES_BUT_ASYNC=--features concurrent,testing +BUILD_KERNEL_ERRORS=BUILD_KERNEL_ERRORS=1 # -- linting -------------------------------------------------------------------------------------- @@ -70,18 +71,18 @@ test: test-default test-prove ## Run all tests .PHONY: check check: ## Check all targets and features for errors without code generation - cargo check --all-targets $(ALL_FEATURES_BUT_ASYNC) + ${BUILD_KERNEL_ERRORS} cargo check --all-targets $(ALL_FEATURES_BUT_ASYNC) # --- building ------------------------------------------------------------------------------------ .PHONY: build build: ## By default we should build in release mode - cargo build --release + ${BUILD_KERNEL_ERRORS} cargo build --release .PHONY: build-no-std build-no-std: ## Build without the standard library - cargo build --no-default-features --target wasm32-unknown-unknown --workspace --lib + ${BUILD_KERNEL_ERRORS} cargo build --no-default-features --target wasm32-unknown-unknown --workspace --lib .PHONY: build-no-std-testing @@ -91,7 +92,7 @@ build-no-std-testing: ## Build without the standard library. Includes the `testi .PHONY: build-async build-async: ## Build with the `async` feature enabled (only libraries) - cargo build --lib --release --features async + ${BUILD_KERNEL_ERRORS} cargo build --lib --release --features async # --- benchmarking -------------------------------------------------------------------------------- diff --git a/miden-tx/build.rs b/miden-tx/build.rs index ca0e56b39..418479f8b 100644 --- a/miden-tx/build.rs +++ b/miden-tx/build.rs @@ -11,10 +11,20 @@ const ASM_DIR: &str = "../miden-lib/asm"; const KERNEL_ERRORS_FILE: &str = "src/errors/tx_kernel_errors.rs"; const MASM_FILE_EXTENSION: &str = "masm"; +/// Generates error mappings for transaction kernel errors. +/// +/// This is done only if BUILD_KERNEL_ERRORS environment variable is set to `1` to avoid running +/// the script on crates.io where MASM files from miden-lib are not available. fn main() -> Result<()> { // re-build when the MASM code changes println!("cargo:rerun-if-changed={ASM_DIR}"); println!("cargo:rerun-if-changed={KERNEL_ERRORS_FILE}"); + println!("cargo::rerun-if-env-changed=BUILD_KERNEL_ERRORS"); + + // Skip this build script in BUILD_KERNEL_ERRORS environment variable is not set to `1`. + if env::var("BUILD_KERNEL_ERRORS").unwrap_or("0".to_string()) == "0" { + return Ok(()); + } // Copies the MASM code to the build directory let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();