From bba6c3241cb9f40aa0f7e28f0ce0d1081e3e10a7 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 11:25:58 -0700 Subject: [PATCH 1/3] workflow: update target --- .github/workflows/build_and_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 9e67935f..be2df596 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -30,8 +30,8 @@ jobs: rustup update cargo install wasm-tools rustup install nightly - rustup target add wasm32-wasi - rustup target add wasm32-wasi --toolchain nightly + rustup target add wasm32-wasip1 + rustup target add wasm32-wasip1 --toolchain nightly cargo install cargo-wasi #- name: Get latest release from foundry-rs/foundry # id: get-latest-foundry-release From a5926c396c5906cf2dc37da82cf41c99db104344 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 11:26:23 -0700 Subject: [PATCH 2/3] build: refactor up-to-date check into `is_up_to_date()` --- src/build/mod.rs | 60 ++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 84960fe8..8784fff6 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -493,6 +493,39 @@ fn get_file_modified_time(file_path: &Path) -> Result { Ok(metadata.modified()?) } +#[instrument(level = "trace", skip_all)] +fn is_up_to_date( + build_with_features_path: &Path, + features: &str, + package_dir: &Path, +) -> Result { + let old_features = fs::read_to_string(&build_with_features_path).ok(); + if old_features == Some(features.to_string()) + && package_dir.join("Cargo.lock").exists() + && package_dir.join("pkg").exists() + && package_dir.join("pkg").join("api.zip").exists() + && file_with_extension_exists(&package_dir.join("pkg"), "wasm") + { + let (source_time, build_time) = get_most_recent_modified_time( + package_dir, + &HashSet::from(["Cargo.lock", "api.zip"]), + &HashSet::from(["wasm"]), + &HashSet::from(["target"]), + )?; + if let Some(source_time) = source_time { + if let Some(build_time) = build_time { + if build_time.duration_since(source_time).is_ok() { + // build_time - source_time >= 0 + // -> current build is up-to-date: don't rebuild + info!("Build up-to-date."); + return Ok(true); + } + } + } + } + Ok(false) +} + #[instrument(level = "trace", skip_all)] async fn compile_javascript_wasm_process( process_dir: &Path, @@ -1331,31 +1364,8 @@ pub async fn execute( .with_suggestion(|| "Please re-run targeting a package.")); } let build_with_features_path = package_dir.join("target").join("build_with_features.txt"); - if !force { - let old_features = fs::read_to_string(&build_with_features_path).ok(); - if old_features == Some(features.to_string()) - && package_dir.join("Cargo.lock").exists() - && package_dir.join("pkg").exists() - && package_dir.join("pkg").join("api.zip").exists() - && file_with_extension_exists(&package_dir.join("pkg"), "wasm") - { - let (source_time, build_time) = get_most_recent_modified_time( - package_dir, - &HashSet::from(["Cargo.lock", "api.zip"]), - &HashSet::from(["wasm"]), - &HashSet::from(["target"]), - )?; - if let Some(source_time) = source_time { - if let Some(build_time) = build_time { - if build_time.duration_since(source_time).is_ok() { - // build_time - source_time >= 0 - // -> current build is up-to-date: don't rebuild - info!("Build up-to-date."); - return Ok(()); - } - } - } - } + if !force && is_up_to_date(&build_with_features_path, features, package_dir)? { + return Ok(()); } fs::create_dir_all(package_dir.join("target"))?; fs::write(&build_with_features_path, features)?; From 90ae3eabac9194ba3ebe10230bb991361ea1fa08 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 14:35:08 -0700 Subject: [PATCH 3/3] build: fix up-to-date detection wrt local deps --- src/build/mod.rs | 55 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 8784fff6..4b5dbaea 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -493,6 +493,14 @@ fn get_file_modified_time(file_path: &Path) -> Result { Ok(metadata.modified()?) } +#[instrument(level = "trace", skip_all)] +fn get_cargo_package_path(package: &cargo_metadata::Package) -> Result { + match package.manifest_path.parent().map(|p| p.as_std_path().to_path_buf()) { + Some(p) => Ok(p), + None => Err(eyre!("Cargo manifest path {} has no parent", package.manifest_path)), + } +} + #[instrument(level = "trace", skip_all)] fn is_up_to_date( build_with_features_path: &Path, @@ -506,26 +514,57 @@ fn is_up_to_date( && package_dir.join("pkg").join("api.zip").exists() && file_with_extension_exists(&package_dir.join("pkg"), "wasm") { - let (source_time, build_time) = get_most_recent_modified_time( + let (mut source_time, build_time) = get_most_recent_modified_time( package_dir, &HashSet::from(["Cargo.lock", "api.zip"]), &HashSet::from(["wasm"]), &HashSet::from(["target"]), )?; - if let Some(source_time) = source_time { - if let Some(build_time) = build_time { - if build_time.duration_since(source_time).is_ok() { - // build_time - source_time >= 0 - // -> current build is up-to-date: don't rebuild - info!("Build up-to-date."); - return Ok(true); + let Some(build_time) = build_time else { + return Ok(false); + }; + + // update source to most recent of package_dir + // or package_dir's local deps + let metadata = cargo_metadata::MetadataCommand::new() + .manifest_path(package_dir.join("Cargo.toml")) + .exec()?; + for package in metadata.packages.iter().filter(|p| p.source.is_none()) { + let dep_package_dir = get_cargo_package_path(&package)?; + let (dep_source_time, _) = get_most_recent_modified_time( + &dep_package_dir, + &HashSet::from(["Cargo.lock", "api.zip"]), + &HashSet::from(["wasm"]), + &HashSet::from(["target"]), + )?; + match source_time { + None => source_time = dep_source_time, + Some(ref st) => { + if let Some(ref dst) = dep_source_time { + if dst.duration_since(st.clone()).is_ok() { + // dep has more recent changes than source + // -> update source_time to dep_source_time + source_time = dep_source_time; + } + } } } } + + if let Some(source_time) = source_time { + if build_time.duration_since(source_time).is_ok() { + // build_time - source_time >= 0 + // -> current build is up-to-date: don't rebuild + info!("Build up-to-date."); + return Ok(true); + } + } } Ok(false) } + + #[instrument(level = "trace", skip_all)] async fn compile_javascript_wasm_process( process_dir: &Path,