Skip to content

Commit 966570d

Browse files
committed
fix: address PR #344 review feedback
- Reuse extracted macOS binaries in OUT_DIR instead of re-downloading on every build-script rerun (previous regression would break offline/CI). - Switch build-script directives from `cargo::` back to `cargo:` for consistency with the rest of the build scripts. - Propagate I/O errors from `Artifact::ensure_in` instead of unwrapping in `SpyImpl::init_in`. - Inherit `target = "target"` for the fspy_preload cdylib artifact deps through the workspace so `cargo autoinherit` is idempotent.
1 parent 77bdc8d commit 966570d

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ bundled_artifact_build = { path = "crates/bundled_artifact_build" }
7575
flate2 = "1.0.35"
7676
fspy = { path = "crates/fspy" }
7777
fspy_detours_sys = { path = "crates/fspy_detours_sys" }
78-
fspy_preload_unix = { path = "crates/fspy_preload_unix", artifact = "cdylib" }
79-
fspy_preload_windows = { path = "crates/fspy_preload_windows", artifact = "cdylib" }
78+
fspy_preload_unix = { path = "crates/fspy_preload_unix", artifact = "cdylib", target = "target" }
79+
fspy_preload_windows = { path = "crates/fspy_preload_windows", artifact = "cdylib", target = "target" }
8080
fspy_seccomp_unotify = { path = "crates/fspy_seccomp_unotify" }
8181
fspy_shared = { path = "crates/fspy_shared" }
8282
fspy_shared_unix = { path = "crates/fspy_shared_unix" }

crates/bundled_artifact_build/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub const ENV_PREFIX: &str = "BUNDLED_ARTIFACT_";
88
/// Publish an artifact at `path` so `bundled_artifact`'s `artifact!($name)`
99
/// macro can embed it.
1010
///
11-
/// Emits three `cargo::…` directives:
11+
/// Emits three `cargo:…` directives:
1212
/// `rerun-if-changed={path}`,
1313
/// `rustc-env=BUNDLED_ARTIFACT_{name}_PATH={path}`, and
1414
/// `rustc-env=BUNDLED_ARTIFACT_{name}_HASH={hex}`. The runtime resolves these
@@ -27,11 +27,11 @@ pub fn register(name: &str, path: &Path) {
2727
{
2828
// Emit rerun-if-changed before reading so cargo still sees it even if
2929
// reading the file below panics.
30-
println!("cargo::rerun-if-changed={path_str}");
30+
println!("cargo:rerun-if-changed={path_str}");
3131
let bytes =
3232
fs::read(path).unwrap_or_else(|e| panic!("failed to read artifact at {path_str}: {e}"));
3333
let hash = format!("{:x}", xxhash_rust::xxh3::xxh3_128(&bytes));
34-
println!("cargo::rustc-env={ENV_PREFIX}{name}_PATH={path_str}");
35-
println!("cargo::rustc-env={ENV_PREFIX}{name}_HASH={hash}");
34+
println!("cargo:rustc-env={ENV_PREFIX}{name}_PATH={path_str}");
35+
println!("cargo:rustc-env={ENV_PREFIX}{name}_HASH={hash}");
3636
}
3737
}

crates/fspy/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ fspy_test_bin = { path = "../fspy_test_bin", artifact = "bin", target = "x86_64-
6363
anyhow = { workspace = true }
6464
bundled_artifact_build = { workspace = true }
6565
flate2 = { workspace = true }
66-
fspy_preload_unix = { path = "../fspy_preload_unix", artifact = "cdylib", target = "target" }
67-
fspy_preload_windows = { path = "../fspy_preload_windows", artifact = "cdylib", target = "target" }
66+
fspy_preload_unix = { workspace = true }
67+
fspy_preload_windows = { workspace = true }
6868
sha2 = { workspace = true }
6969
tar = { workspace = true }
7070

crates/fspy/build.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,20 @@ fn fetch_macos_binaries(out_dir: &Path) -> anyhow::Result<()> {
120120

121121
for BinaryDownload { name, url, path_in_targz, expected_sha256 } in downloads {
122122
let dest = out_dir.join(name);
123-
let tarball = download(url).context(format!("Failed to download {url}"))?;
124-
let actual_sha256 = sha256_hex(&tarball);
125-
assert_eq!(
126-
&actual_sha256, expected_sha256,
127-
"sha256 of {url} does not match — update expected value in MACOS_BINARY_DOWNLOADS",
128-
);
129-
let data = unpack_tar_gz(Cursor::new(tarball), path_in_targz)
130-
.context(format!("Failed to extract {path_in_targz} from {url}"))?;
131-
fs::write(&dest, &data).with_context(|| format!("writing {}", dest.display()))?;
123+
// Reuse the extracted binary if it's already in OUT_DIR; the sha256
124+
// of the tarball was verified on the initial download. This avoids
125+
// hitting the network on incremental build-script reruns.
126+
if !dest.exists() {
127+
let tarball = download(url).context(format!("Failed to download {url}"))?;
128+
let actual_sha256 = sha256_hex(&tarball);
129+
assert_eq!(
130+
&actual_sha256, expected_sha256,
131+
"sha256 of {url} does not match — update expected value in MACOS_BINARY_DOWNLOADS",
132+
);
133+
let data = unpack_tar_gz(Cursor::new(tarball), path_in_targz)
134+
.context(format!("Failed to extract {path_in_targz} from {url}"))?;
135+
fs::write(&dest, &data).with_context(|| format!("writing {}", dest.display()))?;
136+
}
132137
bundled_artifact_build::register(name, &dest);
133138
}
134139
Ok(())
@@ -142,7 +147,7 @@ fn register_preload_cdylib() -> anyhow::Result<()> {
142147
};
143148
// The cdylib path is content-addressed by cargo; when its content changes
144149
// the path changes. Track it so we re-publish the hash on update.
145-
println!("cargo::rerun-if-env-changed={env_name}");
150+
println!("cargo:rerun-if-env-changed={env_name}");
146151
let dylib_path = env::var_os(env_name).with_context(|| format!("{env_name} not set"))?;
147152
bundled_artifact_build::register("fspy_preload", Path::new(&dylib_path));
148153
Ok(())

crates/fspy/src/windows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct SpyImpl {
5151

5252
impl SpyImpl {
5353
pub fn init_in(path: &Path) -> io::Result<Self> {
54-
let dll_path = INTERPOSE_CDYLIB.ensure_in(path, ".dll", false).unwrap();
54+
let dll_path = INTERPOSE_CDYLIB.ensure_in(path, ".dll", false)?;
5555

5656
let wide_dll_path = dll_path.as_os_str().encode_wide().collect::<Vec<u16>>();
5757
let mut ansi_dll_path =

0 commit comments

Comments
 (0)