Skip to content

Commit 8f14a91

Browse files
authored
fix: fspy on intel mac (#54)
# fix fspy on intel mac This PR adds: - A test for shebang script execution in fspy to ensure proper tracking of file accesses - Support for macOS x86_64 in CI workflows - Updates the Oils for Unix binary URLs and checksums to version 0.37.0 - Updates uutils/coreutils to version 0.4.0 - Fixes scandir symbol linking on macOS x86_64 architecture
1 parent 6761f92 commit 8f14a91

File tree

6 files changed

+89
-26
lines changed

6 files changed

+89
-26
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
target: x86_64-pc-windows-msvc
3838
- os: namespace-profile-mac-default
3939
target: aarch64-apple-darwin
40+
- os: namespace-profile-mac-default
41+
target: x86_64-apple-darwin
4042
runs-on: ${{ matrix.os }}
4143
steps:
4244
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -49,17 +51,27 @@ jobs:
4951
save-cache: ${{ github.ref_name == 'main' }}
5052
cache-key: test
5153

54+
- run: rustup target add ${{ matrix.target }}
55+
5256
- run: rustup target add x86_64-unknown-linux-musl
5357
if: ${{ matrix.os == 'ubuntu-latest' }}
5458

5559
- run: pip install cargo-zigbuild
5660
if: ${{ matrix.os == 'ubuntu-latest' }}
5761

58-
- run: cargo check --all-targets --all-features
62+
- run: cargo check --all-targets --all-features --target ${{ matrix.target }}
5963
env:
6064
RUSTFLAGS: '-D warnings --cfg tokio_unstable' # also update .cargo/config.toml
6165

62-
- run: cargo test
66+
# fspy contains tests for Node.js fs accesses.
67+
# use x86_64 node for x86_64-apple-darwin target.
68+
- uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
69+
with:
70+
node-version-file: .node-version
71+
architecture: x64
72+
if: ${{ matrix.target == 'x86_64-apple-darwin' }}
73+
74+
- run: cargo test --target ${{ matrix.target }}
6375
if: ${{ matrix.os != 'ubuntu-latest' }}
6476

6577
- run: cargo-zigbuild test --target x86_64-unknown-linux-gnu.2.17

crates/fspy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ouroboros = { workspace = true }
1919
rand = { workspace = true }
2020
tempfile = { workspace = true }
2121
thiserror = { workspace = true }
22-
tokio = { workspace = true, features = ["net", "process", "io-util", "sync"] }
22+
tokio = { workspace = true, features = ["net", "process", "io-util", "sync", "rt"] }
2323
which = { workspace = true, features = ["tracing"] }
2424
xxhash-rust = { workspace = true }
2525

crates/fspy/build.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,29 @@ const MACOS_BINARY_DOWNLOADS: &[(&str, &[(&str, &str, u128)])] = &[
5555
"aarch64",
5656
&[
5757
(
58-
"https://github.com/branchseer/oils-for-unix-binaries/releases/download/0.29.0-manual/oils-for-unix-0.29.0-aarch64-apple-darwin.tar.gz",
58+
"https://github.com/branchseer/oils-for-unix-build/releases/download/oils-for-unix-0.37.0/oils-for-unix-0.37.0-darwin-arm64.tar.gz",
5959
"oils-for-unix",
60-
149_945_237_112_824_769_531_360_595_981_178_091_193,
60+
282073174065923237490435663309538399576,
6161
),
6262
(
63-
"https://github.com/uutils/coreutils/releases/download/0.1.0/coreutils-0.1.0-aarch64-apple-darwin.tar.gz",
64-
"coreutils-0.1.0-aarch64-apple-darwin/coreutils",
65-
255_656_813_290_649_147_736_009_964_224_176_006_890,
63+
"https://github.com/uutils/coreutils/releases/download/0.4.0/coreutils-0.4.0-aarch64-apple-darwin.tar.gz",
64+
"coreutils-0.4.0-aarch64-apple-darwin/coreutils",
65+
35998406686137668997937014088186935383,
6666
),
6767
],
6868
),
6969
(
7070
"x86_64",
7171
&[
7272
(
73-
"https://github.com/branchseer/oils-for-unix-binaries/releases/download/0.29.0-manual/oils-for-unix-0.29.0-x86_64-apple-darwin.tar.gz",
73+
"https://github.com/branchseer/oils-for-unix-build/releases/download/oils-for-unix-0.37.0/oils-for-unix-0.37.0-darwin-x86_64.tar.gz",
7474
"oils-for-unix",
75-
286_203_014_616_009_968_685_843_701_528_129_413_859,
75+
142673558272427867831039361796426010330,
7676
),
7777
(
78-
"https://github.com/uutils/coreutils/releases/download/0.1.0/coreutils-0.1.0-x86_64-apple-darwin.tar.gz",
79-
"coreutils-0.1.0-x86_64-apple-darwin/coreutils",
80-
75_344_743_234_387_926_348_628_744_659_874_018_387,
78+
"https://github.com/uutils/coreutils/releases/download/0.4.0/coreutils-0.4.0-x86_64-apple-darwin.tar.gz",
79+
"coreutils-0.4.0-x86_64-apple-darwin/coreutils",
80+
120898281113671104995723556995187526689,
8181
),
8282
],
8383
),
@@ -87,6 +87,7 @@ fn fetch_macos_binaries() -> anyhow::Result<()> {
8787
if env::var("CARGO_CFG_TARGET_OS").unwrap() != "macos" {
8888
return Ok(());
8989
}
90+
9091
let out_dir = current_dir().unwrap().join(Path::new(&std::env::var_os("OUT_DIR").unwrap()));
9192

9293
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();

crates/fspy/tests/shebang.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#![cfg(unix)]
2+
3+
mod test_utils;
4+
5+
use std::{
6+
os::unix::fs::PermissionsExt,
7+
path::Path,
8+
process::{Command, Stdio},
9+
};
10+
11+
use fspy::AccessMode;
12+
use test_log::test;
13+
use test_utils::assert_contains;
14+
use tokio::fs;
15+
16+
#[test(tokio::test)]
17+
async fn spawn_sh_shebang() -> anyhow::Result<()> {
18+
let tmp_dir = tempfile::TempDir::new()?;
19+
20+
let shebang_script_path = tmp_dir.path().join("fspy_test_shebang_script.sh");
21+
let shebang_script_path = shebang_script_path.into_os_string().into_string().unwrap();
22+
23+
fs::write(&shebang_script_path, "#!/bin/sh\ncat hello\n").await?;
24+
25+
let mut perms = fs::metadata(&shebang_script_path).await?.permissions();
26+
perms.set_mode(0o755);
27+
fs::set_permissions(&shebang_script_path, perms).await?;
28+
29+
let accesses = track_child!(shebang_script_path.clone(), |shebang_script_path: String| {
30+
let _ignored = Command::new(&shebang_script_path)
31+
.current_dir("/")
32+
.stdin(Stdio::null())
33+
.stdout(Stdio::piped())
34+
.stderr(Stdio::piped())
35+
.status()
36+
.expect("Failed to execute shebang script");
37+
})
38+
.await?;
39+
40+
assert_contains(&accesses, Path::new(&shebang_script_path), AccessMode::READ);
41+
assert_contains(&accesses, Path::new("/hello"), AccessMode::READ);
42+
43+
Ok(())
44+
}

crates/fspy_preload_unix/src/libc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
pub use libc::*;
22

33
unsafe extern "C" {
4+
// On macOS x86_64, directory functions use $INODE64 symbol suffix for 64-bit inode support.
5+
// On arm64, 64-bit inodes are the only option so no suffix is needed.
6+
// https://github.com/apple-open-source-mirror/Libc/blob/5e566be7a7047360adfb35ffc44c6a019a854bea/include/dirent.h#L198
7+
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), link_name = "scandir$INODE64")]
48
pub unsafe fn scandir(
59
dirname: *const c_char,
610
namelist: *mut c_void,
@@ -9,6 +13,7 @@ unsafe extern "C" {
913
) -> c_int;
1014

1115
#[cfg(target_os = "macos")]
16+
#[cfg_attr(target_arch = "x86_64", link_name = "scandir_b$INODE64")]
1217
pub unsafe fn scandir_b(
1318
dirname: *const c_char,
1419
namelist: *mut c_void,

crates/fspy_shared_unix/src/spawn/macos.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@ pub fn handle_exec(
7575
}
7676

7777
pub static COREUTILS_FUNCTIONS: Set<&'static [u8]> = phf_set! {
78-
b"[", b"arch", b"b2sum", b"b3sum", b"base32", b"base64", b"basename", b"basenc",
79-
b"cat", b"chgrp", b"chmod", b"chown", b"chroot", b"cksum", b"comm", b"cp", b"csplit",
80-
b"cut", b"date", b"dd", b"df", b"dir", b"dircolors", b"dirname", b"du", b"echo", b"env",
81-
b"expand", b"expr", b"factor", b"false", b"fmt", b"fold", b"groups", b"hashsum", b"head",
82-
b"hostid", b"hostname", b"id", b"install", b"join", b"kill", b"link", b"ln", b"logname",
83-
b"ls", b"md5sum", b"mkdir", b"mkfifo", b"mknod", b"mktemp", b"more", b"mv", b"nice", b"nl",
84-
b"nohup", b"nproc", b"numfmt", b"od", b"paste", b"pathchk", b"pinky", b"pr", b"printenv",
85-
b"printf", b"ptx", b"pwd", b"readlink", b"realpath", b"rm", b"rmdir", b"seq", b"sha1sum",
86-
b"sha224sum", b"sha256sum", b"sha3-224sum", b"sha3-256sum", b"sha3-384sum", b"sha3-512sum",
87-
b"sha384sum", b"sha3sum", b"sha512sum", b"shake128sum", b"shake256sum", b"shred", b"shuf",
88-
b"sleep", b"sort", b"split", b"stat", b"stdbuf", b"stty", b"sum", b"sync", b"tac", b"tail",
89-
b"tee", b"test", b"timeout", b"touch", b"tr", b"true", b"truncate", b"tsort", b"tty", b"uname",
90-
b"unexpand", b"uniq", b"unlink", b"uptime", b"users", b"vdir", b"wc", b"who", b"whoami", b"yes",
78+
b"[", b"arch", b"b2sum", b"base32", b"base64", b"basename", b"basenc", b"cat",
79+
b"chgrp", b"chmod", b"chown", b"chroot", b"cksum", b"comm", b"cp", b"csplit",
80+
b"cut", b"date", b"dd", b"df", b"dir", b"dircolors", b"dirname", b"du", b"echo",
81+
b"env", b"expand", b"expr", b"factor", b"false", b"fmt", b"fold", b"groups",
82+
b"hashsum", b"head", b"hostid", b"hostname", b"id", b"install", b"join", b"kill",
83+
b"link", b"ln", b"logname", b"ls", b"md5sum", b"mkdir", b"mkfifo", b"mknod",
84+
b"mktemp", b"more", b"mv", b"nice", b"nl", b"nohup", b"nproc", b"numfmt", b"od",
85+
b"paste", b"pathchk", b"pinky", b"pr", b"printenv", b"printf", b"ptx", b"pwd",
86+
b"readlink", b"realpath", b"rm", b"rmdir", b"seq", b"sha1sum", b"sha224sum",
87+
b"sha256sum", b"sha384sum", b"sha512sum", b"shred", b"shuf", b"sleep", b"sort",
88+
b"split", b"stat", b"stdbuf", b"stty", b"sum", b"sync", b"tac", b"tail", b"tee",
89+
b"test", b"timeout", b"touch", b"tr", b"true", b"truncate", b"tsort", b"tty",
90+
b"uname", b"unexpand", b"uniq", b"unlink", b"uptime", b"users", b"vdir", b"wc",
91+
b"who", b"whoami", b"yes"
9192
};

0 commit comments

Comments
 (0)