Skip to content

Commit

Permalink
fix: make building of kernel errors file conditional on env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Nov 6, 2024
1 parent d4e1182 commit a727e2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------------------------------------------------

Expand Down Expand Up @@ -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
Expand All @@ -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 --------------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions miden-tx/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a727e2d

Please sign in to comment.