Skip to content

feat(build-script,proc-macro,cli): wire Linux/NixOS NativeSetting in scripts.rs and replace ambient rustc with blaze-fact-shim - #2884

Open
mteacher360 wants to merge 16 commits into
mainfrom
feat/tier2-linux-native-setting-and-fact-shim
Open

mteacher360 wants to merge 16 commits into
mainfrom
feat/tier2-linux-native-setting-and-fact-shim

Conversation

@mteacher360

Copy link
Copy Markdown
Collaborator

Summary

Implements Tier-2 PR 2, unblocking native build-script execution on Linux/NixOS and eliminating the Rule 1 (no-rustc) / Rule 75 (nothing-ambient) host rustc violation in native_script.rs:

1. Replace ambient host rustc with blaze-fact-shim (rustc + cargo)

  • Deleted pinned_rustc_paths() in crates/blaze-proc-macro/src/native_script.rs (no longer spawns host rustc or mounts host rustup sysroots into the sandbox).
  • Extended blaze_build_script::fact_shim::PROGRAMS to ["cargo", "pkg-config", "pkgconf", "rustc", "sw_vers"] and added Fact::RustcVersion { verbose } / Fact::CargoVersion in crates/blaze-build-script/src/facts.rs (and recognized "rustc" / "cargo" in blaze_proc_macro::fact_pins::fact_now_pinned).
  • blaze-fact-shim answers rustc -V / --version / -vV / --version --verbose from probe::version (deriving the Rust host triple from the pins) and cargo -V / --version / version from probe::cargo_version, refusing try-compiles (--crate-type, -, .rs), --print, and unknown subcommands with exit 127 naming them.
  • native_script.rs sets RUSTC=<facts.bin>/rustc and CARGO=<facts.bin>/cargo when facts is present.

2. Wire Linux/NixOS NativeSetting, clang.cfg + CCC_OVERRIDE_OPTIONS, and NativeSysrootId

  • Extracted shared Linux Clang config helpers (LinuxClangLink, linux_sysroot_prefix, format_linux_clang_cfg, linux_clang_override_options) into blaze_build_script::toolchain (Rule 30: reused by both native_c_tasks.rs and native_unit.rs/toolchain::c_env with zero duplication).
  • Updated toolchain::c_env so Sysroot::LinuxHost omits macOS-only -isysroot, SDKROOT, and MACOSX_DEPLOYMENT_TARGET, keeps CFLAGS/CXXFLAGS host-path-free, and sets CCC_OVERRIDE_OPTIONS when linux_clang_cfg is staged.
  • Extended NativeSetting<'s> with sysroot, sdk_version, sdk_extra, sdk_lib, sdk_dynamic_linker, and Copy + Send + Sync sdk_rpaths: Rpaths<'s>, propagated by OwnedNativeSetting::setting and NativeRun::setting.
  • Updated native_unit.rs::native_outputs to key Linux runs by native.sdk_version (full NixOS split header/lib/rpath/dynamic-linker content digest) and stage <work>/cfg/<run_key>/clang.cfg (plus <cfg_dir>/ld.lld symlink when <shelf>/bin/ld.lld is absent).
  • Mounted sdk_extra, sdk_lib, sdk_rpaths, dynamic-linker parent dir, and staged clang.cfg dir read-only in native_script.rs Landlock reads (deduplicated).
  • Wired resolve_linux_host_sysroot + resolve_linux_sysroot + command_native_setting_with_link across sdk.rs, fetch.rs, engine_check.rs, and scripts.rs, adding platform-neutral NativeSysrootId (Macos(SdkId) | LinuxHost([u8; 32])) hashed into bumped SOURCE_DOMAIN = "blaze-cli script unit source 2".

Verification

  • cargo test -p blaze-build-script -- --test-threads=4: 166 passed, 0 failed
  • cargo test -p blaze-proc-macro --lib -- native_setting native_unit native_facts native_c_tasks spawn_route --test-threads=4: 26 passed, 0 failed
  • cargo test -p blaze-cli --bin blaze -- sdk:: native_runner_c:: --test-threads=4: 17 passed, 0 failed (1 ignored)
  • cargo test -p blaze-cli --bin blaze -- scripts::tests:: host_tool_facts_tests:: --test-threads=4: 14 passed, 0 failed
  • cargo check -p blaze-cli --bin blaze-fact-shim and cargo check -p blaze-cli --bin blaze --no-default-features: PASS
  • domains: PASS (514 hash domains)
  • rustcsites: PASS (0 new)
  • Ratchets (stops, casts, clones, allocs, ambient, ambient sansio-check) vs origin/main: 0 net new (net negative across clones, allocs, ambient, sansio-check)
  • git merge-tree --write-tree origin/main HEAD: clean

…scripts.rs and replace ambient rustc with blaze-fact-shim
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T06:07:18.537983Z b6560d7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24aaf8e70d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +487 to +488
let sdk_digest = if is_fhs_single {
blaze_sha256::digest(&settings)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Hash all FHS headers that affect native scripts

On standard Linux hosts this reduces the native-script source identity to /usr/include/features.h, although newly enabled native scripts can compile against any permitted /usr/include header and bindgen reads are not represented by the later depfile digest. A kernel-header or other system-header update that leaves features.h unchanged therefore reuses the previous Script record and can return stale generated bindings or C artifacts; the FHS identity must cover every granted header input rather than this single marker.

AGENTS.md reference: AGENTS.md:L59-L59

Useful? React with 👍 / 👎.

Comment thread crates/blaze-cli/src/sdk.rs Outdated
Comment on lines +958 to +960
let keyed = blaze_proc_macro::native_setting::resolve_linux_sysroot(sysroot.dir, link, alloc)
.map_err(|err| held(frame, format_args!("{err}")))?;
Ok(Some(ResolvedLinuxHost { sysroot, id: keyed.sdk_digest }))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reuse the keyed Linux sysroot resolution

This computes and retains only the digest, but scripts.rs::open_shared subsequently calls command_native_setting_with_link, which invokes resolve_linux_sysroot again. On NixOS that recursively hashes the complete header, libc, linker, and rpath trees twice for one command; moreover, if a mutable FHS sysroot changes between the calls, the planned Script source key describes the first snapshot while execution uses the second. Pass the already verified resolution into the native setting instead of discarding and recomputing it.

AGENTS.md reference: AGENTS.md:L61-L61

Useful? React with 👍 / 👎.

Comment on lines +607 to +611
let loader_name = dyn_linker.as_str().rsplit('/').next().unwrap_or("");
sha.update(b"dyn\0");
sha.update(&u64::try_from(loader_name.len()).unwrap_or(u64::MAX).to_le_bytes());
sha.update(loader_name.as_bytes());
hash_regular(&mut sha, dyn_linker.as_str())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Normalize Nix linker paths before keying outputs

The Nix sysroot identity deliberately hashes only library contents and the dynamic linker's basename, but format_linux_clang_cfg passes the absolute sdk_lib, rpath, and dynamic-linker paths to lld. Those strings are embedded in linked outputs as RPATH and PT_INTERP, so two content-identical Nix store roots produce the same sdk_digest while producing different output bytes, allowing a cached native-script result from one environment to be reused in the other. Stage these inputs at stable spellings or otherwise remove the host paths from outputs rather than omitting semantic inputs from the key.

AGENTS.md reference: AGENTS.md:L121-L123

Useful? React with 👍 / 👎.

Comment thread crates/blaze-cli/src/scripts.rs Outdated
Ok(sdk) => blaze_proc_macro::native_setting::command_native_setting(home, sdk.folder(), NATIVE_WORK, host, alloc)
.map_err(|error| said(frame, format_args!("the native runner's setting (D112): {error}"))),
},
Ok(blaze_build_script::toolchain::Sysroot::LinuxHost) => match env.linux_sysroot {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Grant Linux tools required by native cmake scripts

This enables native scripts on Linux, but blaze_build_script::native::TOOLCHAIN_CLASS explicitly places scripts whose closure contains cmake on this runner while the Linux host-tool rows in pins/clang.json:143-147 have empty names. Consequently native_script::run_script puts neither cmake nor its helpers on PATH or the executable allowlist, so every cmake-based build script selected by this branch fails immediately instead of building. Add keyed Linux tool grants or avoid selecting the native runner until those tools are available.

AGENTS.md reference: AGENTS.md:L57-L57

Useful? React with 👍 / 👎.

put("CFLAGS", flags.clone_in(alloc));
put("CXX", clangxx);
put("CXXFLAGS", flags);
put("LIBCLANG_PATH", text(&[c.shelf.dir, "/lib"]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require libclang in the Linux shelf

On Linux this directs clang-sys to the shelf, but SHELF_MEMBERS_LINUX accepts a shelf containing only the compiler binaries, LLVM utilities, and builtin headers, without requiring lib/libclang.so as the macOS member set does. Because closures containing bindgen or clang-sys are forced onto the native runner, such an accepted shelf then fails every affected build script when the library is loaded from this directory; include the Linux libclang shared object in the required shelf contents before selecting this runner.

AGENTS.md reference: AGENTS.md:L57-L57

Useful? React with 👍 / 👎.

…inux native scripts

- Hash all FHS headers under <sdk>/include in resolve_linux_sysroot (remove features.h-only shortcut) so system-header updates invalidate native Script records (Rule 21).
- Retain the complete canonicalized & keyed Linux sysroot in sdk::ResolvedLinuxHost and reuse it via command_native_setting_from_resolved_linux in scripts.rs::open_shared (eliminating double hashing and TOCTOU drift).
- Gate Nix -Wl,-rpath / -Wl,--dynamic-linker flags in format_linux_clang_cfg behind embed_runtime_paths (only enabled for runs_out_dir probes), include sdk_dynamic_linker in native_c_tasks host-path checks, and add streaming chunk-boundary HostPath rejection in native_script::store_out_dir_checked so cached Linux outputs never embed host store paths (Rule 25).
- Require lib/libclang.so in SHELF_MEMBERS_LINUX so incomplete Linux shelves are rejected up front before bindgen/clang-sys runs.
- Avoid selecting Runner::Native in placed_for_host / placed_in_store when required host tools (cmake, sha3-asm's perl) are not granted in pins/clang.json for the host, and fail loudly with NativeUnitError::MissingHostTool if forced native.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e539d1d90

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +71 to +75
if native::closure_has_crate(graph, script, "cmake", alloc) && !tools.iter().any(|tool| tool.name == "cmake") {
return Some("cmake");
}
if toolchain::NATIVE_EVERY_MODE.binary_search(&pkg).is_ok() && tools.is_empty() {
return Some("perl");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Grant all required Linux native tools

Although the new guard handles cmake and sha3-asm, Linux still selects the native runner for tikv-jemalloc-sys: its cc dependency makes the build/run placement native, but it matches neither condition here, while the Linux host_tools rows are empty and this script starts sh, make, nm, and other tools listed in the macOS pin table. The resulting Linux build therefore reaches the sandbox without those executables and fails; add the required keyed Linux grants or make placement account for every package's needed_by tools rather than these two special cases.

AGENTS.md reference: AGENTS.md:L57-L57

Useful? React with 👍 / 👎.

Comment on lines +582 to +583
let sdk_inc = text(&[sdk.as_str(), "/include"], alloc);
hash_dir(&mut sha, sdk_inc.as_str(), b"sdk\0", &mut ignored_loader)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include granted FHS libraries in the sysroot identity

On a standard FHS host, the native sandbox grants the entire /usr sysroot and Clang links with --sysroot=/, so a native script can consume /usr/lib through the linker or read other /usr files directly. This identity hashes only /usr/include; because sdk_lib is None on that path, a libc or other system-library update that leaves headers unchanged preserves the Script key and can reuse stale linked artifacts. Hash every granted/linker input or narrow the sandbox grant to the content represented by this digest.

AGENTS.md reference: AGENTS.md:L59-L59

Useful? React with 👍 / 👎.

| ["--verbose", "-V"]
| ["--version", "-v"]
| ["-v", "--version"] => Some(true),
_ => None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve native rustc probe support

When the D175 zero-Wasm path selects a native build script because the store has script.bin but no module.wasm, scripts using autocfg or an explicit rustc try-compile invoke RUSTC with source and --crate-type arguments. The new shim routes every non-version invocation through this catch-all and exits 127, whereas the previous native runner executed the pinned compiler and the Wasm runner has dedicated probe handling, so otherwise valid crates now fail solely because they were placed native. Route these invocations through the existing keyed probe machinery or prevent such scripts from taking the native-only placement.

AGENTS.md reference: AGENTS.md:L57-L57

Useful? React with 👍 / 👎.

…nux native scripts

- Drive missing_native_host_tool directly from pins/clang.json host_tools needed_by rows via host_tools::missing_for_target (Rule 30), so every package requiring ungranted host tools on Linux (including tikv-jemalloc-sys, sha3-asm, and cmake) stays off the unready native runner.
- Narrow Linux Landlock read grants to exact hashed directories (<sdk>/include, <sdk_extra>/include, sdk_lib, sdk_rpaths, and external sdk_dynamic_linker file) so sandbox read grants match resolve_linux_sysroot's sdk_digest 1:1 with no unhashed FHS /usr or /usr/lib access (Rule 21).
- Preserve native rustc try-compile probe support (autocfg / pinned probes) without host rustc (Rule 1, Rule 30): serialize the command's keyed probe table into <facts>/probes (hashed into KeyInputs::answers via Table::id()) and dispatch rustc try-compiles in blaze-fact-shim through probe_ask::classify + probe_ask::answer.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6692666494

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

snippet_stdin.as_slice()
}
Snippet::File(path) => {
snippet_buf = match read_file(Path::new(path)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound file-backed rustc probe snippets

When a native build script invokes the shimmed RUSTC with a source file under OUT_DIR or the package, this branch reads the entire untrusted file with std::fs::read, bypassing the 4 MiB limit applied to stdin probes. A dependency can therefore write a very large probe file and force the shim to allocate it whole, potentially exhausting memory or hitting the 16 GiB process ceiling and failing the build; use the bounded reader for file inputs as well.

AGENTS.md reference: AGENTS.md:L64-L69

Useful? React with 👍 / 👎.

Comment on lines +353 to +354
if expected_len > MAX_SDK_FILE_BYTES {
return Err(io::Error::from(io::ErrorKind::InvalidData));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow large libraries while hashing the sysroot

On Linux, a Nix environment whose NIX_LDFLAGS contains an rpath with any regular file larger than 64 MiB now fails sysroot resolution here, because every file in every rpath is passed through hash_regular even when that library is unrelated to the build script. Large shared libraries such as LLVM can exceed this threshold, so merely having one in an ambient rpath prevents projects containing any scoped build script or proc macro from building; keep streaming these files but do not reject them based on this per-file size cap.

AGENTS.md reference: AGENTS.md:L55-L60

Useful? React with 👍 / 👎.

Comment on lines 1062 to 1063
if runs_out_dir && Path::new("/usr/bin/cmp").is_file() {
out.push("/usr/bin/cmp");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include opportunistic helpers in the native run key

For a native script whose host-tool grant enables runs_out_dir, this adds /usr/bin/cmp to the executable allowlist whenever it exists, but the run key digests only programs returned by HostTool::programs_in, and cmp is absent from the pin table. A configure script can therefore make its generated outputs depend on this ambient binary while a replacement or appearance/disappearance of cmp leaves the Script key unchanged and permits stale output reuse; grant it through a keyed host-tool row instead.

AGENTS.md reference: AGENTS.md:L55-L60

Useful? React with 👍 / 👎.

…es, streaming large libs, remove unkeyed cmp)

- Enforce the same 4 MiB bounded reader on file-backed rustc probe snippets (Snippet::File) as stdin probes in native_facts::shim_main.
- Keep the 64 MiB cap on buffered SDK marker reads (read_bounded) while allowing O(1)-memory streaming hash_regular to hash large (>64 MiB) regular shared libraries in ambient Nix rpaths cleanly.
- Remove the unkeyed opportunistic /usr/bin/cmp grant in native_script.rs so every granted host executable is keyed through HostTool::programs_in.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f97544ae11

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +193 to +199
Verdict::Accepted(_) => Reply {
code: 0,
stdout: String::new_in(alloc),
stderr: String::new_in(alloc),
answered: true,
subject: probe_subject,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Materialize outputs for accepted rustc probes

When a native build script invokes RUSTC with an accepted snippet and then consumes an artifact requested through -o, --out-dir, or --emit, this branch reports success but creates no output at all; the pinned compiler would create that artifact, so the script subsequently fails or makes a wrong capability decision. The new keyed path is fresh evidence beyond the earlier refusal issue: either materialize the requested artifacts or refuse invocations that are not proven to inspect only the exit status.

AGENTS.md reference: AGENTS.md:L57-L57

Useful? React with 👍 / 👎.

Comment thread crates/blaze-cli/src/scripts.rs Outdated
Comment on lines +209 to +211
if let Ok(sdk) = env.sdk {
return Some(NativeSysrootId::Macos(sdk.identity()));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Select the sysroot identity by host platform

On a Linux host where SDKROOT points to a valid macOS SDK, the command resolves both env.sdk and env.linux_sysroot, but this early return keys native Script tasks with the macOS SDK while open_shared selects Sysroot::LinuxHost and executes against the Linux sysroot. Linux header or libc changes can therefore leave the task key unchanged and reuse stale outputs; choose the identity according to host_sysroot(crate::graph::TRIPLE) rather than whichever optional value happens to be present first.

AGENTS.md reference: AGENTS.md:L59-L59

Useful? React with 👍 / 👎.

…fact-producing probes, host-keyed sysroot id)

- Restrict fact_shim::ask_rustc_probe to exit-status-only compiler-capability probes (--crate-type=lib|rlib, --emit within {dep-info,llvm-ir,metadata}, no -o <path>/-o - other than /dev/null, no --emit=<kind>=<path>, no --test); refuse artifact-requesting compiles with exit 127 instead of returning exit 0 without creating output files.
- Select NativeSysrootId in scripts::sdk_identity strictly by host_sysroot(crate::graph::TRIPLE) (matching open_shared) so a Linux host with SDKROOT set never keys native Script tasks by a macOS SDK.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6b6d78071

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +91 to +92
if matches!(base, Runner::Native { .. }) && cl.no_wasm.is_none() && missing_native_host_tool(graph, script, host, alloc).is_some() {
return Runner::Wasm;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep tool-dependent scripts off the Wasm runner

On Linux, where the host_tools rows are empty, this silently changes sha3-asm, tikv-jemalloc-sys, and build/run scripts whose closure contains cmake from native to Wasm. cl.no_wasm only describes whether the dependency closure compiles for WASI; it does not mean the script can execute its required perl, shell/make, or cmake process there, and these packages were deliberately placed native to perform those operations. The fresh fallback at this location therefore replaces the earlier native-sandbox failure with a Wasm spawn failure rather than making these builds work; report the missing host tool or provide a keyed native grant instead.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

Comment on lines +238 to +239
if c.sysroot_kind == Sysroot::LinuxHost {
blaze_own::format_in!(alloc, "{}/include", c.sysroot)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Grant resolved targets of sysroot symlinks

On FHS Linux hosts, granting only /usr/include prevents Landlock from following header-directory symlinks whose resolved targets are outside that tree. For example, /usr/include/clang/<version>/include commonly resolves under /usr/lib/llvm-<version>/lib/clang/...; resolve_linux_sysroot follows and hashes such directory symlinks, but only the special Nix sdk_extra root is added to sysroot_extra_reads. A native build script that includes a header through one of these ordinary FHS symlinks is therefore denied despite the header being part of the keyed sysroot, so collect and grant every external resolved target encountered during hashing.

AGENTS.md reference: AGENTS.md:L57-L58

Useful? React with 👍 / 👎.

push_cfg_quoted(&mut cfg, map.as_str());
}

if let Some(lib_dir) = link.lib_dir {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Configure a linker for FHS Linux

On an ordinary FHS Linux host, ResolvedLinuxHost.lib_dir is None, so this guard also suppresses -fuse-ld even though the shelf provides lld rather than a default ld and the native runner's PATH contains no system tool directories. The sandbox additionally grants only /usr/include, not the host linker or library directories, so any native script that uses $CC to link an executable or shared object fails even though compile-only and archive-producing scripts work. Configure and grant the pinned linker plus keyed FHS library inputs instead of limiting the linking configuration to split Nix libc.

AGENTS.md reference: AGENTS.md:L113-L116

Useful? React with 👍 / 👎.

…no Wasm fallback, symlink targets, FHS linker & libc)

- Remove silent Runner::Native -> Runner::Wasm fallback when a required host tool is missing (Rule 3): keep tool-dependent scripts (sha3-asm, tikv-jemalloc-sys, cmake) on Runner::Native and fail loudly at the start of native_outputs with NativeUnitError::MissingHostTool.
- Collect every external resolved file/directory symlink target encountered during resolve_linux_sysroot into sdk_extra_reads and grant them read-only under Landlock for exact 1:1 parity with sdk_digest.
- Always configure -fuse-ld=<shelf ld.lld> on Sysroot::LinuxHost (both NixOS and FHS), discover and stream-hash standard FHS libc/CRT files + dynamic linker into sdk_digest, and grant those exact hashed files to Landlock.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d8fcc84ac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".


/// Standard FHS C runtime / glibc linker files hashed and granted individually on FHS hosts (where
/// `/usr/lib/<multiarch>` also holds gigabytes of unrelated distribution libraries). Sorted.
const FHS_LIBC_FILES: &[&str] = &[

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include the C++ runtime in the FHS sysroot

On standard FHS Linux hosts, native build scripts that use the provided CXX to link C++ code cannot succeed: this allowlist hashes and grants only glibc/CRT files, while the Linux shelf contains neither libstdc++ nor libc++. Consequently clang++ cannot read its default C++ runtime library under /usr/lib/gcc/..., so common cc::Build::cpp(true) dependencies fail at link time. Discover, key, and grant the host C++ runtime and its library directory alongside libc.

AGENTS.md reference: AGENTS.md:L113-L116

Useful? React with 👍 / 👎.

];

const FHS_LOADERS: &[&str] = &["ld-linux-aarch64.so.1", "ld-linux-x86-64.so.2"];
const FHS_LIB_SUBDIRS: &[&str] = &["lib/aarch64-linux-gnu", "lib/x86_64-linux-gnu", "lib64", "lib"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Select the FHS library directory for the host architecture

On an x86-64 host with the ARM64 cross-libc package installed, this fixed ordering discovers /usr/lib/aarch64-linux-gnu first and later assigns it as sdk_lib, causing Clang to receive the ARM directory through -B and -L and potentially the ARM loader as well. Native x86 scripts then link against incompatible startup objects even though the correct x86 directory is present. Filter the candidates using the host triple instead of preferring ARM unconditionally.

AGENTS.md reference: AGENTS.md:L113-L116

Useful? React with 👍 / 👎.

Comment thread crates/blaze-cli/src/scripts.rs Outdated
Ok(sdk) => blaze_proc_macro::native_setting::command_native_setting(home, sdk.folder(), NATIVE_WORK, host, alloc)
.map_err(|error| said(frame, format_args!("the native runner's setting (D112): {error}"))),
},
Ok(blaze_build_script::toolchain::Sysroot::LinuxHost) => match env.linux_sysroot {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Build native script modules for Linux hosts

When this branch enables the native setting on Linux, every script placed on that runner later looks up a script.bin record whose target is the Linux host triple, but the repository's only script.bin producer in scripts/src/bin/proc_macro_modules/build_scripts.rs still hardcodes HOST and the artifact path to aarch64-apple-darwin. A normal Linux installation therefore cannot produce the module that native_outputs requires and all Linux-native scripts fail with NoModule before reaching the sandbox. Extend the module builder to emit binaries for the current Linux host before selecting this runner.

AGENTS.md reference: AGENTS.md:L113-L116

Useful? React with 👍 / 👎.

Comment on lines +687 to +688
if cfg_path.as_str().bytes().any(|b| b.is_ascii_whitespace()) {
return Err(OwnString::from_str_in("native script clang config path contains whitespace", alloc));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Support whitespace in Linux native work paths

When the Blaze home path contains whitespace, cfg_dir inherits it and this unconditional check rejects every Linux native build script before Clang starts. Rust and Cargo otherwise support such checkout and home paths, so installations such as /home/Build User/.blaze regress solely because the config path is passed through CCC_OVERRIDE_OPTIONS. Stage the config at a safely quoted or whitespace-free internal spelling instead of refusing the user's path.

AGENTS.md reference: AGENTS.md:L113-L116

Useful? React with 👍 / 👎.

…whitespace cfg staging, and Linux native script builder (Codex Round 7)
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 30dddc61f1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +894 to +895
for arg in ["--ro-bind", "/", "/", "--dev", "/dev", "--proc", "/proc", "--unshare-net", "--die-with-parent"] {
out.push(arg.into());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict the Linux module-builder sandbox's read view

When the bootstrap builder runs on Linux, Cargo executes dependency build scripts and proc macros inside this bwrap instance, but --ro-bind / / gives that untrusted code read access to the entire host, including unrelated checkouts and files under $HOME; it can then encode those bytes into writable build outputs and persisted modules. Unlike the scoped macOS profile above, this is not a documented opt-out, so construct the sandbox root from only the vendor, source, toolchain, shelf, and keyed sysroot grants.

AGENTS.md reference: AGENTS.md:L129-L131

Useful? React with 👍 / 👎.

Comment on lines +156 to +158
let marker = self.sdk.join(blaze_build_script::toolchain::LINUX_HOST_SYSROOT_MARKER);
let marker_bytes = std::fs::read(&marker).map_err(io(&marker))?;
Ok(format!("target {HOST}\nlinker clang {digest}\nsdk features {}\n", sha256(&marker_bytes)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Key native modules with the complete Linux sysroot identity

On Linux/NixOS this identity hashes only include/features.h, even though the configuration below embeds lib_dir, dynamic_linker, and rpaths into the linked script.bin and the compilation can consume all granted headers and runtime libraries. Two sysroots with the same marker—or a runtime/header update that leaves it unchanged—therefore produce the same module key but different bytes, causing Failure::Conflict during rebuilding and leaving existing consumers addressed to the stale record; include the content identity of every sysroot input used by the native module build.

AGENTS.md reference: AGENTS.md:L121-L123

Useful? React with 👍 / 👎.

Comment on lines +894 to +895
for arg in ["--ro-bind", "/", "/", "--dev", "/dev", "--proc", "/proc", "--unshare-net", "--die-with-parent"] {
out.push(arg.into());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict the Linux module-builder sandbox's read view

On Linux, when bootstrap builds native module, Cargo executes dependencies' build scripts and proc macros inside bwrap, but --ro-bind / / gives that untrusted code read access to the entire host, including unrelated checkouts and files under $HOME; it can then encode those bytes into writable build outputs and persisted modules. Unlike the scoped macOS profile above, this is not a documented opt-out, so construct the sandbox root from only the vendor, source, toolchain, shelf, and keyed sysroot grants.

AGENTS.md reference: AGENTS.md:L129-L131

Useful? React with 👍 / 👎.

Comment on lines +941 to +942
"RUSTC" => shim_rustc.as_deref().unwrap_or(value.as_str()),
"CARGO" => shim_cargo.as_deref().unwrap_or(value.as_str()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Route cargo metadata through the native probe machinery

When a native-placed build script uses cargo_metadata or cbindgen, Cargo normally supplies CARGO so it can run cargo metadata; replacing that variable with this shim makes the invocation exit 127 because the shim accepts only Cargo version queries. The repository's metadata_ask_tests.rs records cbindgen's real cargo metadata --all-features --format-version 1 --manifest-path ... invocation, so affected pinned-nightly-compatible scripts now fail solely on the native runner; route this command through the typed metadata answerer instead of the version-only shim.

AGENTS.md reference: AGENTS.md:L113-L117

Useful? React with 👍 / 👎.

…him, key complete Linux sysroot, and scope Linux bwrap sandbox (Codex Round 8)
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79e76ced40

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +727 to +729
package_dir: package_dir.as_str(),
workspace_root: meta_ws,
target_dir: out_dir.as_str(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep metadata answers independent of checkout paths

The metadata digest used in KeyInputs::answers is generated above with guest spellings, but the staged answer is regenerated here with the real package_dir, workspace root, and out_dir. Thus identical sources in two checkout locations receive the same Script key while cargo metadata returns different manifest_path, workspace_root, and target_directory strings; any build script that persists one of those fields can produce conflicting or stale cached output. Stage the answer using stable sandbox spellings, or include every returned path in the key.

AGENTS.md reference: AGENTS.md:L121-L123

Useful? React with 👍 / 👎.

}
}
}
let mut stdout = String::from_str_in(if ask.no_deps { meta.no_deps_json } else { meta.full_json }, alloc);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply accepted cargo metadata feature selection

When a native build script requests cargo metadata --all-features, --features, or --no-default-features, the classifier records those flags but this branch returns the same snapshot selected only by --no-deps. If the outer build did not already enable the requested optional features, the response is built from the wrong unit graph and can omit dependencies or declarations that tools such as cbindgen need, producing incomplete generated bindings or failing an otherwise valid build. Either construct the snapshot for the requested feature selection or refuse feature flags that are not represented.

AGENTS.md reference: AGENTS.md:L57-L57

Useful? React with 👍 / 👎.

let link = LinuxTreeLink {
let link = LinuxClangLink {
lib_dir: setting.sdk_lib.map(|l| l.host),
gcc_lib_dir: None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass the discovered GCC runtime to process trees

Although the direct native-script path now carries sdk_gcc_lib, the separate deferred C process-tree setup drops that field and hardcodes gcc_lib_dir: None here. On a standard FHS Linux host, a process tree that invokes the provided CXX to link C++ code therefore receives neither --gcc-install-dir/-B/-L nor a read grant for /usr/lib/gcc/<triple>/<version>, so Clang cannot access crtbegin*, libgcc, or libstdc++ and the build fails. Thread the resolved GCC directory through CTasksSetting and its read roots.

AGENTS.md reference: AGENTS.md:L113-L116

Useful? React with 👍 / 👎.

- Synced with latest origin/main (dedup-1127 #2896, #2898, and pinned_rustc_paths removal),
  migrating remaining hex() calls to blaze_hex::encode_in and preserving D230 written_root
  support plus Linux NativeSetting / blaze-fact-shim changes.
- Fix Round 8 P1 #1 (native_unit.rs): pre-resolve Tree::Dir (pkg_real, ws_real) and render
  cargo metadata JSON once with target_dir '/target' before KeyInputs::answers; hash the exact
  returned metadata JSON bytes + feature selection into metadata_digest (1:1 key/output parity),
  and leave Tree::Mem metadata snapshots None (refused loudly if queried).
- Fix Round 8 P1 #2 (fact_shim.rs, native_facts.rs, native_unit.rs): upgrade METADATA_HEAD to
  v2 carrying enabled_features and all_features_enabled; enforce --all-features,
  --no-default-features, and --features against the build's resolved feature set (exit 127 on
  mismatch) with positive and negative unit tests.
- Fix Round 8 P1 #3 (native_c_tasks.rs, native_runner_c.rs): add sdk_gcc_lib to CTasksSetting,
  mount/grant it in ShelfTree read_roots and run pairs, and forward gcc_lib_dir into
  LinuxClangLink for Linux process trees.
- Fix origin/main test compilation fallout in blaze-proc-macro (probe_clang.rs, tests.rs,
  native_jobs.rs, native_fact_shim.rs, native_dep_tree.rs) and blaze-cli/src/scripts.rs.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db36f0ff82

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +710 to +711
package_dir: pkg_real.as_str(),
workspace_root: ws_real.as_str(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep checkout paths out of the script key

When the same workspace is checked out under a different absolute directory, pkg_real and ws_real are serialized into the metadata JSON and its digest is folded into KeyInputs::answers, so source-identical builds receive different content-addressed Script keys and cannot share local or remote cache records. The newly added digest avoids the earlier stale-answer collision but makes host paths key inputs; serialize stable sandbox spellings instead.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +412 to +413
// Collect distinct packages in deterministic order: focal package only when `no_deps`, else
// every package reachable from `focal_pkg`'s units in `spec.graph`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return every workspace member for --no-deps

When a build script in a multi-package workspace runs cargo metadata --no-deps, this deliberately includes only the focal package. I checked cargo metadata --help, which defines --no-deps as outputting all workspace members while excluding dependencies; generators that inspect sibling members therefore receive an incomplete workspace and can omit their sources or outputs.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

out.push(',');
}
let is_focal = rep.package == focal_pkg;
let pkg_base = if is_focal { spec.package_dir } else { "/deps" };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stage dependency sources at metadata paths

When a metadata consumer such as cbindgen enables dependency parsing, every non-focal package is reported under /deps/<name>-<version>, but native_outputs stages only the workspace/package and links output trees and never creates or grants these source directories. The consumer consequently cannot open the returned manifest_path or src_path, causing otherwise valid dependency-aware generators to fail; mount the keyed dependency sources at the advertised paths or omit/refuse unsupported dependency metadata.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1204 to +1205
"--proc".into(),
"/proc".into(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Unshare the PID namespace before mounting procfs

On Linux hosts without a restrictive hidepid policy, this mounts a fresh procfs while leaving the builder in the host PID namespace because the bwrap arguments never include --unshare-pid. Untrusted dependency build scripts and proc macros run by this Cargo invocation can therefore inspect same-UID host processes through /proc/<pid> (including environ, open descriptors, and root paths), bypassing the otherwise scoped read mounts and potentially capturing secrets in persisted module outputs; create a PID namespace before mounting /proc.

AGENTS.md reference: AGENTS.md:L132-L134

Useful? React with 👍 / 👎.

Comment on lines +830 to +831
if let Some(gcc_lib) = self.setting.sdk_gcc_lib {
push_unique(&mut out, gcc_lib.host, gcc_lib.digest);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Grant only keyed GCC runtime files

On an FHS Linux host with a deferred C/C++ process tree, this grants the entire /usr/lib/gcc/<triple>/<version> directory as a tree identified by the sysroot digest, while resolve_linux_sysroot hashes only the filenames in FHS_GCC_FILES. A compiler or linker command can therefore consume an unlisted library such as libgomp.a, and changing that file leaves the process-tree key unchanged and permits stale artifact reuse; mount only the individually hashed runtime files or hash the complete granted directory.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

…(Round 9)

- scripts/proc_macro_modules/build_scripts.rs (P1): add --unshare-pid before --proc /proc
  in build_linux_bwrap_args so confined scripts cannot inspect host processes via /proc/<pid>.
- blaze-proc-macro/native_setting.rs (P1): hash the entire granted FHS GCC runtime directory
  via hash_dir (and grant the directory 1:1) so any file such as libgomp.a is keyed into
  sdk_digest and matches Landlock / ShelfTree /sdk-gcc grants 1:1.
- blaze-proc-macro/native_unit.rs (P2): hash canonical checkout-independent /workspace paths
  into metadata_digest (KeyInputs::answers) while serving runtime paths, keeping Script keys
  invariant across checkout locations.
- blaze-build-script/metadata_ask.rs + fact_shim.rs + native_unit.rs (P1 x2): remove synthetic
  /deps/<name>-<version> paths and refuse loudly (exit 127) for multi-member workspaces
  (where sibling members are not materialized) and for full-deps queries with unstaged
  non-focal dependencies; add unit tests for all five fixes.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 5 Codex Round 8 findings:

  1. Added --unshare-pid before --proc /proc in Linux bwrap sandbox args (scripts/src/bin/proc_macro_modules/build_scripts.rs).
  2. Hashed the full granted FHS GCC runtime directory via hash_dir so Landlock and ShelfTree /sdk-gcc grants match sdk_digest 1:1 (crates/blaze-proc-macro/src/native_setting.rs).
  3. Keyed metadata_digest using canonical checkout-independent /workspace paths so identical checkouts at different host paths produce the exact same Script key (crates/blaze-proc-macro/src/native_unit.rs).
  4. & 5. Removed synthetic /deps/<name>-<version> paths and refused loudly (exit 127) for multi-member workspaces and unstaged non-focal dependencies (metadata_ask.rs, fact_shim.rs, native_unit.rs).

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80e79fce8c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +699 to +700
package_dir: pkg_real,
workspace_root: ws_real,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Serve metadata through stable sandbox paths

For identical checkouts at different host paths, the key is now derived from canonical /workspace paths, but this runtime snapshot still serializes pkg_real and ws_real. A build script that persists manifest_path, workspace_root, or src_path therefore produces different bytes under the same Script key, allowing a stale record or immutable-record conflict. The fresh evidence beyond the earlier path-key finding is this new split between canonical key JSON and real-path runtime JSON; expose the checkout at stable sandbox paths and serve those same paths.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Some(r) => push_json_str(&mut out, r),
None => out.push_str("null"),
}
out.push_str(",\"optional\":false,\"uses_default_features\":true,\"features\":[],\"target\":null,\"registry\":null,\"path\":null}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve manifest dependency properties in metadata

When a single-member package asks for cargo metadata --no-deps, Cargo still returns that workspace member's dependency declarations; I checked cargo metadata --help, which says the flag limits output to workspace members rather than removing their declarations. This formatter instead hardcodes every resolved dependency as non-optional, default-feature-enabled, featureless, and unconditional (and omits disabled optional dependencies because it walks only unit-graph edges), so consumers can generate incorrect cfgs or bindings for manifests using optional features, default-features = false, or target-specific dependencies. Populate these fields from the manifest or refuse the query.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1168 to +1170
for rp in &rpaths {
if rp.is_dir() {
push_grant(rp);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bind only resolved ELF libraries, not whole RPATHs

On Linux, whenever Cargo, rustc, Clang, or lld contains a DT_RPATH/DT_RUNPATH, this grants the entire directory recursively even though only individual DT_NEEDED files are required. Dependency build scripts and proc macros can consequently read unrelated files from toolchain or Nix library directories and encode them into persisted modules, while those extra bytes are not covered by the module identity. Fresh evidence after the earlier root-bind fix is this newly introduced directory-level RPATH grant; resolve and bind only the required library files.

AGENTS.md reference: AGENTS.md:L132-L134

Useful? React with 👍 / 👎.

Comment on lines +668 to +669
} else {
ws.clone()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the staged Clang config read-only

On the normal Linux path where the generated workspace contains no whitespace, this places clang.cfg (and sometimes the ld.lld symlink) inside ws, which is subsequently mounted read-write for the whole Cargo process tree. Dependency build scripts and proc macros inherit CCC_OVERRIDE_OPTIONS with this exact path, so one can overwrite the config before the focal build script is linked, inject compiler/linker flags, and change the persisted script.bin while its identity still describes the trusted generated configuration. Stage this configuration outside writable mounts or bind it read-only.

AGENTS.md reference: AGENTS.md:L132-L134

Useful? React with 👍 / 👎.

…(Round 10)

- blaze-build-script/fact_shim.rs, metadata_ask.rs, blaze-proc-macro/{native_facts,native_unit}.rs
  (P1 x2): remove partial cargo metadata JSON synthesis and staging; keep cargo metadata
  intercepted by blaze-fact-shim returning an honest exit-127 refusal until a dedicated PR
  materializes full Cargo manifest properties and sandbox-remapped paths.
- scripts/proc_macro_modules/build_scripts.rs (P1): resolve transitive DT_NEEDED ELF libraries
  individually (following symlink chains) instead of --ro-bind'ing whole DT_RPATH/DT_RUNPATH
  directories, with ELF64 unit test verifying unrelated sibling files in DT_RUNPATH are not bound.
- scripts/proc_macro_modules/build_scripts.rs (P1): always stage Linux clang.cfg (and any
  ld.lld symlink) in a dedicated read-only directory outside writable ws (mounted --ro-bind
  in bwrap and cleaned up on drop), with unit test verifying cfg_dir is outside ws and --ro-bind.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 4 Codex Round 9 findings:

  1. & 2. Removed partial cargo metadata JSON synthesis and staging (metadata_ask.rs restored to origin/main, fact_shim.rs, native_facts.rs, native_unit.rs); blaze-fact-shim still intercepts cargo metadata (never falling through to host cargo) and returns an honest exit 127 refusal.
  2. Updated Linux bwrap ELF runtime resolution (scripts/src/bin/proc_macro_modules/build_scripts.rs) to bind only individually resolved transitive DT_NEEDED shared library files (plus symlink targets and PT_INTERP), never whole DT_RPATH/DT_RUNPATH directories, with an ELF64 unit test.
  3. Always stage Linux clang.cfg (and optional ld.lld symlink) in a dedicated read-only directory strictly outside writable ws (linux_clang_cfg_ro_dir), mounted --ro-bind in bwrap and cleaned up on drop, with unit test coverage.

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9b4772d09

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +1218 to +1222
for sys_file in ["/etc/ld.so.cache", "/etc/ssl/openssl.cnf"] {
let p = Path::new(sys_file);
if p.is_file() {
push_file_grant(p);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Key or remove ambient system configuration grants

In the Linux module-builder bwrap path, this unconditionally exposes /etc/ld.so.cache and /etc/ssl/openssl.cnf to every dependency build script and proc macro, even though neither file is part of Native::identity. Those programs can read the files directly—or have their behavior affected by them—so a host configuration change can produce different persisted script.bin bytes under the same module key. Remove these grants or hash the exact files into the identity before mounting them.

AGENTS.md reference: AGENTS.md:L132-L134

Useful? React with 👍 / 👎.

Comment on lines +1143 to +1147
const FHS_DIRS: &[&str] = &[
"/lib/aarch64-linux-gnu",
"/usr/lib/aarch64-linux-gnu",
"/lib/x86_64-linux-gnu",
"/usr/lib/x86_64-linux-gnu",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve ELF dependencies for the host architecture

On an x86-64 Linux host with ARM64 cross-libc installed, this new runtime resolver searches the ARM directories first and can select /lib/aarch64-linux-gnu/libc.so.6 for an x86-64 Cargo, rustc, or Clang executable. It then mounts only that incompatible file while the required x86-64 library remains absent, so the module builder fails before Cargo starts. Select the FHS search directories from HOST, as the sysroot resolver already does.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment thread crates/blaze-cli/src/engine_check.rs Outdated
Comment on lines +4843 to +4846
if blaze_proc_macro::native_setting::host_sysroot(crate::graph::TRIPLE)
== Ok(blaze_build_script::toolchain::Sysroot::LinuxHost)
{
env.linux_sysroot = lazy.resolve_linux_sysroot_with_id(env.heap.alloc());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Defer Linux sysroot hashing until a native unit is selected

On Linux, any scoped proc macro or build script reaches this call, including workspaces whose scripts and proc macros all use the Wasm runner. resolve_linux_sysroot_with_id recursively hashes /usr/include, the selected GCC runtime directory, and the other sysroot inputs, and its OnceCell lasts only for this command, so ordinary edit checks of proc-macro-heavy projects repeat that full host-tree scan even though no native key consumes it. Determine whether the plan contains a native runner first and resolve the Linux identity only then.

AGENTS.md reference: AGENTS.md:L79-L80

Useful? React with 👍 / 👎.

Comment on lines +1083 to +1087
0 => break,
1 => needed_offs.push(val),
5 => strtab_va = Some(val),
15 | 29 => rpath_offs.push(val),
_ => {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not inherit DT_RUNPATH into indirect dependencies

For an ELF executable with DT_RUNPATH=/tool/lib whose libA.so depends on libB.so, this parser merges DT_RUNPATH with DT_RPATH, and the traversal passes that directory to libA as an inherited search path. The dynamic loader does not inherit an executable's DT_RUNPATH for indirect dependencies, so the collector can mount /tool/lib/libB.so while omitting the system libB.so the loader actually requests, causing Cargo or the compiler to fail at startup inside bwrap. Track the two tags separately and inherit only DT_RPATH according to ELF loader semantics.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

- blaze-cli/{names.rs,engine_check.rs} (P1): defer Linux host sysroot hashing
  (resolve_linux_sysroot_with_id) until at least one scoped build script is placed on
  RanAs::Native (Names::has_native_script + should_resolve_linux_sysroot), avoiding recursive
  /usr/include + GCC runtime hashing on pure-Wasm workspaces.
- scripts/proc_macro_modules/build_scripts.rs (P1): remove unkeyed /etc/ld.so.cache and
  /etc/ssl/openssl.cnf binds from Linux bwrap ELF runtime grants.
- scripts/proc_macro_modules/build_scripts.rs (P2): filter FHS ELF library search directories
  strictly by host architecture (elf_fhs_search_dirs(HOST)) instead of probing aarch64 before
  x86_64 unconditionally.
- scripts/proc_macro_modules/build_scripts.rs (P1): parse DT_RPATH (15) and DT_RUNPATH (29)
  separately and follow ELF ld.so semantics (DT_RUNPATH applies only to direct DT_NEEDED and
  is never inherited by transitive dependencies; legacy DT_RPATH is inherited only when
  DT_RUNPATH is absent), with real ELF64 unit tests.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 4 Codex Round 10 findings:

  1. Deferred Linux host sysroot hashing (resolve_linux_sysroot_with_id) in crates/blaze-cli/src/engine_check.rs until at least one scoped build script is placed on RanAs::Native (Names::has_native_script + should_resolve_linux_sysroot), so pure-Wasm workspaces skip recursive /usr/include + GCC runtime hashing.
  2. Removed unkeyed /etc/ld.so.cache and /etc/ssl/openssl.cnf binds from Linux bwrap ELF runtime grants (scripts/src/bin/proc_macro_modules/build_scripts.rs).
  3. Filtered FHS ELF library search directories by host architecture (elf_fhs_search_dirs(HOST)) with unit tests for both x86_64-unknown-linux-gnu and aarch64-unknown-linux-gnu.
  4. Separated DT_RPATH (15) and DT_RUNPATH (29) in parse_elf64_deps / collect_elf_runtime_reads_with_dirs so DT_RUNPATH applies only to direct DT_NEEDED entries and is never inherited by transitive dependencies (while legacy DT_RPATH without DT_RUNPATH is inherited), verified with real ELF64 unit tests.

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd35798b86

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +5152 to +5156
if should_resolve_linux_sysroot(
crate::graph::TRIPLE,
world.has_native_script(|at| scoped.as_ref().is_none_or(|s| s.allows(at))),
) {
env.linux_sysroot = lazy.resolve_linux_sysroot_with_id(env.heap.alloc());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Defer construction of the native setting too

In a Linux workspace whose scoped scripts are all RanAs::Wasm, this leaves env.linux_sysroot as Ok(None), but the first script job still calls Scripts::open_shared; its Linux Ok(None) branch in scripts.rs:689-697 invokes command_native_setting_with_link, which resolves and recursively hashes /usr/include and the GCC runtime anyway. Thus the reported pure-Wasm optimization only moves the scan later in the same check; make shared setup skip native-setting construction unless the selected plan contains a native script.

AGENTS.md reference: AGENTS.md:L79-L80

Useful? React with 👍 / 👎.

Comment on lines +1129 to +1132
for entry in raw.split(':').filter(|e| !e.is_empty()) {
let expanded = entry.replace("$ORIGIN", origin).replace("${ORIGIN}", origin);
if expanded.starts_with('/') {
dst.push(PathBuf::from(expanded));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Expand every ELF dynamic string token

When a tool has an RPATH/RUNPATH such as $ORIGIN/../$LIB or one containing $PLATFORM, this leaves the token literal, so the resolver fails to grant a direct DT_NEEDED library and Cargo, rustc, or Clang cannot start inside the empty-root bwrap sandbox. glibc recognizes all three dynamic string tokens—ORIGIN, PLATFORM, and LIB—in these paths (glibc dl-load.c); expand them using the host architecture rather than supporting only $ORIGIN.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1319 to +1320
for rt in collect_elf_runtime_reads(spec.executables) {
push_ro(&rt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Key the resolved ELF runtime closure

When any builder executable depends on an ambient library outside the explicitly hashed sysroot set—for example a system libz, libssl, or libLLVM—this loop mounts that file into the sandbox, but Native::identity includes only the toolchain/Clang identity and ResolvedLinuxSysroot digest. A dependency build script can read the granted file directly, and the compiler can consume it, so updating it can produce different script.bin bytes under the same module key, yielding stale reuse or Failure::Conflict; digest every collected runtime file into the identity before computing key.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +1289 to +1293
"--unshare-pid".into(),
"--proc".into(),
"/proc".into(),
"--tmpfs".into(),
"/tmp".into(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Give the sandbox a fixed UTS identity

When a dependency build script or proc macro calls gethostname/uname, this sandbox still exposes the host's UTS identity because it unshares PID and network namespaces but never UTS; the program can embed that machine-specific value into the persisted module while the module key remains host-independent. Bubblewrap provides --unshare-uts and a fixed --hostname specifically for this namespace (official option list); use both so builds on different hosts cannot generate different bytes for one key.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +1211 to +1212
if visited.len() >= MAX_FILES {
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refuse an oversized ELF closure instead of truncating it

When the runtime traversal reaches 256 distinct (library, inherited_rpaths) states—possible when Cargo, rustc, Clang, and lld carry different inherited RPATH vectors—this silently stops with entries still queued and returns a partial grant list. The subsequent empty-root bwrap invocation then omits required DT_NEEDED files and fails in the dynamic loader even though all libraries exist on the host; return an explicit bounded-closure error instead of treating the truncated result as complete.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

- blaze-cli/{scripts.rs,scripts_tests.rs} (P1): extract linux_native_setting_for_env so
  Scripts::open_shared skips command_native_setting_with_link when env.linux_sysroot is
  Ok(None) (no native build script planned), avoiding /usr/include + GCC runtime hashing on
  pure-Wasm workspaces; add unit test.
- scripts/proc_macro_modules/build_scripts.rs (P1): add --unshare-uts --hostname blaze to
  build_linux_bwrap_args for deterministic UTS hostname inside Linux bwrap sandboxes.
- scripts/proc_macro_modules/build_scripts.rs (P1): expand all glibc ELF dynamic string
  tokens (/, /, /) in expand_elf_dst for both
  search paths and slash-containing DT_NEEDED entries, with unit tests for x86_64 and aarch64.
- scripts/proc_macro_modules/build_scripts.rs (P1): compute SHA-256 content digest over all
  resolved ELF runtime closure files (elf_runtime_closure_digest) and fold it into
  Native::identity before keying (reusing the exact closure in bwrap), with unit test.
- scripts/proc_macro_modules/build_scripts.rs (P2): raise ELF runtime traversal cap to 2048
  states and return Err loudly if exceeded instead of silently truncating, with unit test.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 5 Codex Round 11 findings:

  1. Deferred Linux native-setting construction in crates/blaze-cli/src/scripts.rs (linux_native_setting_for_env): when env.linux_sysroot is Ok(None) (no native build script planned), Scripts::open_shared returns a typed deferral error instead of calling command_native_setting_with_link on /usr, with unit test in scripts_tests.rs.
  2. Added --unshare-uts --hostname blaze to build_linux_bwrap_args (scripts/src/bin/proc_macro_modules/build_scripts.rs) for a fixed UTS hostname across hosts.
  3. Expanded all three glibc ELF dynamic string tokens ($ORIGIN/${ORIGIN}, $LIB/${LIB}, $PLATFORM/${PLATFORM}) in expand_elf_dst for both x86_64 and aarch64 hosts, with unit tests.
  4. Hashed the resolved ELF runtime library closure (elf_runtime_closure_digest) and folded it into Native::identity before computing the module key (reusing the exact same closure in bwrap), with unit test verifying editing a DT_NEEDED .so moves the identity.
  5. Raised the ELF closure traversal cap to 2048 states and returned Err loudly if exceeded instead of truncating silently, with unit test coverage.

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a9b81d0f9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +1067 to +1070
if host.starts_with("aarch64-") {
("aarch64", &["lib/aarch64-linux-gnu", "lib64", "lib"])
} else if host.starts_with("x86_64-") {
("x86_64", &["lib/x86_64-linux-gnu", "lib64", "lib"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve $LIB to the loader's configured value

When an x86-64 non-Debian host has both an application-local lib/x86_64-linux-gnu directory and the actual $LIB directory, this ordering can select and grant the former even though glibc expands $LIB to only one configured value (normally lib64, as documented by ld.so(8)). The empty-root sandbox then omits the library at the path the loader actually checks, so an otherwise runnable Cargo/Clang executable fails to start; determine the active loader's single expansion rather than treating distro alternatives as fallback search paths.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1352 to +1355
if let Some(lib_path) = found {
push_file_grant(&lib_path);
queue.push((lib_path, next_inherited.clone()));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Refuse unresolved DT_NEEDED entries

When a builder executable resolves a dependency through a custom ld.so.conf/ld.so.cache directory rather than its RPATH or the hardcoded FHS directories, found is None and this silently returns a partial closure. The executable runs normally on the host but fails in the empty-root bwrap sandbox because the required library is omitted; resolve and key the configured loader search path, or return a typed error naming the unresolved soname before invoking bwrap.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1226 to +1227
if cand.to_string_lossy().bytes().any(|b| b.is_ascii_whitespace()) {
PathBuf::from(format!("/tmp/blaze-pm-cfg-{}-{short}", std::process::id()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Create the fallback config directory securely

When the Blaze work path contains whitespace, this predictable PID-and-key name is placed in the shared /tmp namespace; the caller removes it and then uses create_dir_all, so another local user can race by creating a world-writable directory at that name. They can then replace clang.cfg before bwrap binds it read-only, injecting compiler flags into a module whose key still describes the trusted configuration; use an atomically created mode-0700 directory in a trusted per-user location.

AGENTS.md reference: AGENTS.md:L135-L138

Useful? React with 👍 / 👎.

Comment on lines +1376 to +1378
let path_bytes = path.as_os_str().as_encoded_bytes();
sha.update(&u64::try_from(path_bytes.len()).unwrap_or(u64::MAX).to_le_bytes());
sha.update(path_bytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove host paths from the ELF closure key

When the same pinned toolchain and identical runtime libraries are installed beneath different Blaze homes or checkout prefixes, hashing each canonical absolute path gives the builds different module keys despite identical inputs and outputs, preventing local or remote cache sharing across machines. Normalize files to stable sandbox roles (while hashing their contents) instead of folding machine-specific paths into Native::identity.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +179 to +182
if let Some(out) = compile.out
&& out != "/dev/null"
{
return Some("`-o <path>` requests a named output artifact the fact shim does not materialize");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Refuse rustc probes that specify an output directory

When a probe whose snippet is accepted by the keyed table supplies --out-dir, the classifier accepts and discards that option, while this check only rejects -o and per-emit paths. The shim can therefore exit successfully without creating the requested .rmeta, .ll, or dependency file, and the build script fails later or takes a wrong success branch; track and reject --out-dir just like the other artifact destinations.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1397 to +1398
"--dev".into(),
"/dev".into(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Block ambient randomness in module builds

When a dependency build script or proc macro reads randomness, this sandbox can produce different persisted script.bin bytes under the same source/toolchain/sysroot key: bubblewrap's --dev implementation explicitly binds both random and urandom, and no seccomp policy here blocks getrandom either. Supply a deterministic keyed source or refuse these reads instead of exposing host entropy to code whose output is content-addressed.

AGENTS.md reference: AGENTS.md:L72-L72

Useful? React with 👍 / 👎.

Comment on lines +1407 to +1408
"--unshare-net".into(),
"--die-with-parent".into(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Unshare the IPC namespace

When another same-UID host process owns a SysV shared-memory segment, semaphore, or message queue, dependency build scripts and proc macros can access that host IPC because this namespace setup unshares PID, UTS, and network but not IPC. That bypasses the scoped filesystem sandbox and can expose private bytes or let ambient IPC affect persisted module output; add bubblewrap's documented --unshare-ipc option.

AGENTS.md reference: AGENTS.md:L132-L134

Useful? React with 👍 / 👎.

…wrap bootstrapper (Round 13)

- blaze-build-script/{probe_ask.rs,fact_shim.rs} (P1): record Compile::out_dir in
  probe_ask::classify and refuse rustc try-compile probes that specify --out-dir
  (--out-dir <dir> or --out-dir=<dir>) with exit 127 in compile_output_refusal so probes
  expecting materialized output files never receive an empty exit-0 answer; add unit tests.
- scripts/: revert scripts/src/bin/proc_macro_modules/build_scripts.rs, scripts/Cargo.toml,
  and Cargo.lock back to origin/main (0 diff in scripts/). Tier-2 native build scripts will
  be self-compiled directly via blaze-export in the follow-up PR without the legacy
  Cargo+bwrap bootstrapper.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all Codex Round 12 findings:

  1. Runtime (): Recorded Compile::out_dir in probe_ask::classify and refused rustc probes specifying --out-dir (--out-dir <dir> or --out-dir=<dir>) with exit 127 in compile_output_refusal, with unit tests covering both forms.
  2. Scope cleanup (): Reverted scripts/src/bin/proc_macro_modules/build_scripts.rs, scripts/Cargo.toml, and Cargo.lock back to origin/main (0 diff in scripts/). Linux proc_macro_modules Cargo+bwrap bootstrapping is intentionally dropped from this PR because Tier-2 native build scripts will be self-compiled directly via blaze-export in the follow-up PR (zero cargo/bwrap).

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1da239cb53

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +430 to +433
let rel = blaze_own::format_in!(alloc, "blaze-clang-cfg-{fifo_leaf}-{short_key}");
let base = OwnString::from_str_in("/tmp", alloc);
work_guard.push_external_dir(OwnString::from_str_in(base.as_str(), alloc), OwnString::from_str_in(rel.as_str(), alloc));
(base, rel)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Create fallback config directories securely

When the Blaze work path contains whitespace, this derives a predictable name from the visible jobserver FIFO and run key, then fresh_folder performs a non-atomic exists/remove/create sequence in shared /tmp. Another local user can race a directory or symlink into that path and alter clang.cfg or the staged ld.lld before the hermetic launch, changing persisted outputs under the trusted key. Fresh evidence beyond the prior reverted module-builder finding is that the new native build-script path—and the analogous ShelfTree path—reintroduces the same shared-/tmp scheme; use an atomically created mode-0700 directory in a trusted per-user location.

AGENTS.md reference: AGENTS.md:L135-L138

Useful? React with 👍 / 👎.

Comment on lines +846 to +848
if let Some(primary) = fhs_dirs.first() {
sdk_lib = Some(String::from_str_in(primary.as_str(), alloc));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Grant only hashed FHS library files

On FHS Linux with a deferred C process tree, assigning the whole primary multiarch directory to sdk_lib makes native_runner_c::built_for expose it as a Laid root and ShelfTree::read_roots grant the entire directory, while the digest below hashes only FHS_LIBC_FILES and loader names. The process tree can therefore read or link an unlisted library such as libz.so, and changing it does not move the process-tree key, permitting stale artifacts. Fresh evidence beyond the earlier GCC-directory finding is this newly auto-discovered FHS sdk_lib; grant the individually hashed files or hash every granted directory entry.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +758 to +761
put("BINDGEN_EXTRA_CLANG_ARGS", text(&["--sysroot=", sysroot_prefix, " -resource-dir ", resource_dir.as_str()]));
put("CC", clang);
if let Some(cfg_path) = c.linux_clang_cfg {
put("CCC_OVERRIDE_OPTIONS", linux_clang_override_options(cfg_path, alloc));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use stable paths in the Linux C environment

On Linux, these variables expose absolute sysroot, shelf, and staged-config paths to native build-script code, while the runner key contains only their content identities. A script that copies CC, BINDGEN_EXTRA_CLANG_ARGS, or CCC_OVERRIDE_OPTIONS into a generated file or cargo:rustc-env directive therefore produces different record bytes when identical toolchain and sysroot contents are installed under another prefix. The kept-file scanner does not forbid c.shelf.dir, and the stdout mapper only rewrites shown trees, OUT_DIR, and the package, so neither path catches this; expose the tools through fixed sandbox spellings or normalize every such value before storing output.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +585 to +589
let has_marker = FHS_GCC_MARKERS.iter().any(|marker| {
let p = text(&[real_dir.as_str(), "/", marker], alloc);
stat_meta(p.as_str()).is_ok_and(|m| m.is_file())
});
if !has_marker {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Require a complete GCC runtime before selecting it

On an FHS host with multiple GCC versions, this treats a directory containing any one marker as usable and then selects the highest version. If the newest installation is partial—for example it has crtbegin.o but no libstdc++.so, or only a stale libstdc++.so without libgcc.a—the generated Clang configuration forces that directory with --gcc-install-dir and never considers an older complete installation, so otherwise valid native C++ build scripts fail to compile or link. Require the complete runtime needed by the supported C/C++ link mode before admitting a candidate.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 4 Round 13 findings in 4259814f8:

  1. Secure private fallback config dir (native_unit.rs, native_c_tasks.rs): Replaced shared /tmp fresh_folder staging in both stage_linux_clang_cfg and ShelfTree::run with one shared helper create_private_cfg_dir that atomically creates a mode-0700 directory (via DirBuilder::mode(0o700) + collision-retry counter, never probing exists() or removing pre-existing paths) under a trusted user-owned whitespace-free parent ($XDG_RUNTIME_DIR or $HOME/.blaze/v2/cfg-tmp), refusing loudly with a typed error if none exists. Added unit tests verifying 0o700 mode, non-/tmp placement, collision safety, and refusal when unavailable.
  2. 1:1 FHS library file grants (native_c_tasks.rs, native_runner_c.rs): Added sdk_extra_reads to CTasksSetting (populated from setup.setting.sdk_extra_reads) and narrowed ShelfTree::read_roots on Sysroot::LinuxHost to grant <sdk>/include, <sdk_extra>/include, sdk_gcc_lib, sdk_rpaths, and the exact hashed sdk_extra_reads (NixOS whole sdk_lib store dir, or on FHS ONLY the individual hashed FHS_LIBC_FILES and loader files — never whole /usr, /usr/lib/<arch>-linux-gnu, or sdk_dynamic_linker's parent). Added unit test verifying an unlisted sibling /usr/lib/aarch64-linux-gnu/libz.so is not granted in read_roots and that blaze_roots::Mounts::new accepts the resulting mounts.
  3. Complete GCC runtime check (native_setting.rs, native_setting_tests.rs): Updated find_fhs_gcc_dir to require a complete GCC runtime (crtbeginS.o/crtbegin.o, crtendS.o/crtend.o, libgcc.a, and libgcc_s.so/libgcc_s.so.1/libgcc_eh.a) via has_complete_fhs_gcc_runtime before selecting a version directory. Added unit test with a partial newer 15/ directory beside complete 14/, verifying 14/ is selected.
  4. Linux C environment host-path hygiene (native_script.rs): Normalized c.shelf.dir, linux_cfg_dir, and non-/usr Linux sysroot roots in build-script stdout (build_stdout_pairs, longest-first) and added c.shelf.dir alongside linux_cfg_dir and non-/usr sysroot roots to build_forbidden_hosts for store_out_dir_checked. Added unit test verifying CC/CCC_OVERRIDE_OPTIONS/BINDGEN_EXTRA_CLANG_ARGS normalize identically across hosts in cargo:rustc-env and are refused with NativeScriptError::HostPath in kept OUT_DIR files.

Verified: blaze-build-script (171 passed), blaze-proc-macro lib (39 passed), integration/example checks, blaze-cli --bin blaze --no-default-features, blaze-cli --bin blaze-fact-shim --bin blaze, all ratchets (0 net new sites), clean git merge-tree against origin/main, 0 diff in scripts/.

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4259814f8d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

}
if let Some(chunk) = buf.get(..n) {
out.extend_from_slice(chunk);
has_any(FHS_GCC_CRT_BEGIN) && has_any(FHS_GCC_CRT_END) && has_any(FHS_GCC_LIBGCC) && has_any(FHS_GCC_UNWIND)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Require every GCC object used by supported link modes

When a newer GCC directory contains only crtbegin.o/crtend.o plus the libgcc files, this predicate accepts it and find_fhs_gcc_dir selects it over an older complete installation, but Clang's default PIE link needs crtbeginS.o and crtendS.o; C++ linking can likewise fail because the predicate never requires the documented libstdc++.so. Fresh evidence after the earlier completeness finding is that the new predicate treats the PIE and non-PIE objects as alternatives and omits libstdc++ entirely, so require the files needed by every supported link mode before selecting the directory.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +443 to +445
#[cfg(unix)]
if (meta.mode() & 0o077) != 0 {
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Verify the staging parent belongs to the current user

When XDG_RUNTIME_DIR or the derived HOME directory is mode 0700 but owned by another uid and writable to Blaze through an ACL or elevated execution, this check accepts it because it verifies only the mode. That owner can rename the newly created child and substitute a directory containing a modified clang.cfg before Clang reads it, changing keyed build output. Fresh evidence after the earlier fallback-directory finding is that this new helper claims a user-owned parent without checking st_uid; compare ownership with the effective uid before selecting it.

AGENTS.md reference: AGENTS.md:L135-L138

Useful? React with 👍 / 👎.

Comment on lines +709 to +713
while let Some((prefix, cur_dir, ancestors)) = stack.pop() {
let listed = crate::native_script::listed_under(cur_dir.as_str()).map_err(|_| NativeSettingError::NoSdk {
path: String::from_str_in(cur_dir.as_str(), alloc),
error: io::Error::from(io::ErrorKind::Other),
})?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Hash every entry in granted sysroot directories

When a granted SDK, GCC, or RPATH tree contains a directory named target, .blaze, or .git, reusing listed_under omits that entire subtree from sdk_digest; it also omits ordinary empty directories. The sandbox nevertheless grants the complete root, so a build script can read or test those entries and change its persisted output while retaining the same key. Use an unfiltered sysroot traversal that includes directory entries rather than the OUT_DIR-specific listing helper.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +983 to +987
let canonical_sdk = crate::work::held_str(keyed.sdk.as_str(), frame);
let sdk_extra = keyed.sdk_extra.as_ref().map(|s| crate::work::held_str(s.as_str(), frame));
let sdk_lib = keyed.sdk_lib.as_ref().map(|s| crate::work::held_str(s.as_str(), frame));
let sdk_gcc_lib = keyed.sdk_gcc_lib.as_ref().map(|s| crate::work::held_str(s.as_str(), frame));
let sdk_dynamic_linker = keyed.sdk_dynamic_linker.as_ref().map(|s| crate::work::held_str(s.as_str(), frame));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pin the sysroot bytes represented by the computed digest

When /usr/include, the selected GCC directory, or a Nix library changes after resolve_linux_sysroot hashes it but before a native script or deferred process tree runs, this retains only the live host path strings while id remains the earlier digest. Execution can therefore consume replacement bytes under the old Script key, producing stale reuse or an immutable-record conflict; the value described as a snapshot must either refer to a content-addressed staged tree or be revalidated before committing outputs.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 4 Round 14 findings in b6560d726:

  1. Complete GCC runtime across all supported link modes (native_setting.rs, native_setting_tests.rs): has_complete_fhs_gcc_runtime now requires every object needed by both non-PIE and PIE C/C++ linking (crtbegin.o, crtbeginS.o, crtend.o, crtendS.o, libgcc.a, unwind/shared libgcc libgcc_s.so/libgcc_s.so.1/libgcc_eh.a, AND libstdc++.so/libstdc++.a). Added unit tests proving newer GCC directories missing PIE crtbeginS.o/crtendS.o or missing libstdc++.so are skipped in favor of a complete older install.
  2. Verify staging parent ownership (native_unit.rs): create_private_cfg_dir_in (shared by stage_linux_clang_cfg and ShelfTree::run) now checks BOTH (meta.mode() & 0o777) == 0o700 AND meta.uid() == geteuid(), rejecting mode-0700 directories owned by another UID. Added unit test verifying mismatched-UID rejection.
  3. Unfiltered sysroot directory hashing (native_setting.rs, native_setting_tests.rs): Replaced listed_under in resolve_linux_sysroot's hash_dir with a dedicated unfiltered deterministic traversal (list_sysroot_dir_unfiltered) that hashes every entry (including target/, .git/, .blaze/, and empty directories) with bounded directory and symlink cycle protection. Added unit tests proving empty directories, target/, and .git/ subtrees under granted sysroot trees invalidate sdk_digest.
  4. Pre-commit Linux host sysroot revalidation (native_setting.rs, sdk.rs, scripts.rs, native_runner_c.rs): Added verify_linux_sysroot_unchanged / ResolvedLinuxHost::verify_unchanged and wired pre-commit revalidation after native build-script execution (scripts.rs, returning a hole so stale outputs are never committed) and around deferred C / process-tree execution (native_runner_c.rs, before run_tasks and before on.store.put). Updated ResolvedLinuxHost docs to accurately describe edge digest capture + pre-commit revalidation, and added unit test verifying unchanged passes while mid-run sysroot mutation is refused before commit.

Verified: blaze-build-script (171 passed), blaze-proc-macro lib (39 passed), integration/example checks, blaze-cli --bin blaze --no-default-features, blaze-cli --bin blaze-fact-shim --bin blaze, all 9 ratchet gates (0 net new sites), clean git merge-tree against latest origin/main, 0 diff in scripts/.

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6560d7269

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment on lines +642 to +645
if let Some(pin) = setup.linux_pin.as_ref()
&& let Err(why) = pin.verify_unchanged(crate::graph::TRIPLE, alloc)
{
return Err(CTaskWhy::Built { words: kept(scratch, format_args!("{}", why.as_str())) });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Delay C cache writes until sysroot validation

When the Linux sysroot changes after the pre-run check while a deferred C task is executing, this post-run check occurs after run_tasks has already received the real OnCStore: c_tasks::record_object writes path-set and object records and c_tasks::archive writes archive records through CStore::put before control returns here. Although this branch refuses the final built record, those stale intermediate records remain under keys derived from the old SDK digest and can be reused if the sysroot returns to that digest. Fresh evidence beyond the prior snapshot finding is this direct store passed into run_tasks; buffer its writes until validation succeeds or execute against an immutable sysroot snapshot.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +1898 to +1900
if ran_as == RanAs::Native
&& let Some(linux) = shared.linux_sysroot
&& let Err(why) = linux.verify_unchanged(crate::graph::TRIPLE, alloc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the sysroot pinned through record publication

When the Linux sysroot changes after this worker-side check but before the coordinator publishes the returned script record, the stale output is still committed under the earlier SDK key; the record is not processed until engine_scripts.rs's Completed::pooled/observe_next path, well after this function returns. The digest comparison also cannot detect an A→B→A mutation whose B bytes were consumed during execution. Fresh evidence beyond the prior snapshot finding is that the new check ends before the publication path rather than guarding it, so use an immutable staged tree or a generation guard spanning execution through publication.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +796 to +800
SysrootEntryKind::Link => {
sha.update(b"L");
sha.update(&u64::try_from(name.len()).unwrap_or(u64::MAX).to_le_bytes());
sha.update(name.as_bytes());
let meta = stat_meta(full.as_str())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve symlink target spellings in sysroot identity

When a granted sysroot symlink is retargeted between two files or directories with identical contents, this branch hashes only the link's name and the resolved target contents, so sdk_digest remains unchanged even though native code can observe the different target with readlink and absolute-link resolution can behave differently. Revalidation therefore also accepts the changed tree and permits different outputs under one key; stage symlinks with stable normalized targets or include their observable target spelling in the identity.

AGENTS.md reference: AGENTS.md:L124-L126

Useful? React with 👍 / 👎.

Comment on lines +1014 to +1015
if let Some(ext_dir) = external_cfg_dir.as_deref() {
shown.push(("/cfg", ext_dir));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Grant the external process-tree clang config for reading

When the process-tree work path contains ASCII whitespace, clang.cfg is staged in the external private directory, but this branch only adds that directory to the display-path mappings. The subsequent hermetic roots come from read_roots plus the writable process-tree folder, and external_cfg_dir is added to neither, so Clang cannot open the path supplied through CCC_OVERRIDE_OPTIONS and every Linux C/C++ process-tree step fails on such a checkout or HOME path. Add the external config directory as a read-only root, as the native build-script path already does.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant