Skip to content

feat(build-script,proc-macro,cli): add pre-run Tier-2 native classification for protobuf build-deps and host-OS build.rs sources - #2883

Closed
mteacher360 wants to merge 5 commits into
mainfrom
feat/tier2-prerun-native-classifier
Closed

mteacher360 wants to merge 5 commits into
mainfrom
feat/tier2-prerun-native-classifier

Conversation

@mteacher360

Copy link
Copy Markdown
Collaborator

Summary

Implements Tier-2 PR 1: deterministic pre-run Tier-2 native build-script classification before compilation or execution (Rules 3 no-fallback, 30 single source of truth, 54 guard-the-cause, 60 no hashing build.rs into UnitGraph).

Changes

  • crates/blaze-build-script/src/native.rs (#![blaze::sans_io], #![forbid(unsafe_code)], zero std, zero regex, zero allocations):
    • Expanded sorted NO_WASM_CLASS with protobuf/gRPC codegen build-deps: ["bindgen", "clang-sys", "libloading", "prost-build", "protobuf-build", "protoc-bin-vendored", "tonic-build", "tonic-prost-build"] (covers raft-proto and codex-code-mode-protocol).
    • Added NativeSourceReason::{HostOsStd, ExternC, HostFamilyCfg} and source_requires_native(source: &str) -> Option<NativeSourceReason> backed by a zero-allocation Rust lexical scanner (handles line comments, nested /* ... */ block comments, "..." escapes, raw/byte/c strings r#"..."#, char literals vs lifetimes, and raw identifiers) plus a 3-valued WASI #[cfg(...)] / #![cfg(...)] guard evaluator (all/any/not, block/statement/item scoping).
    • HostFamilyCfg specifically matches cfg!(target_family = "unix") / cfg!(unix) (without matching cfg!(target_os = "linux") / cfg!(target_os = "macos") / cfg!(windows)), preserving pure-Rust Wasm scripts like anyhow, proc-macro2, and thiserror.
    • Added placement_with_source(closure, mode, package, script, source) -> Runner as the single source of truth.
  • crates/blaze-proc-macro/src/{native_unit.rs,script_unit.rs}:
    • Added placed_with_source, placed_in_store_with_source, and script_source_in_tree.
    • Wired both script_unit::outputs and script_unit::outputs_viewing_on to read unit.root from tree and place deterministically before execution.
  • crates/blaze-cli/src/{names.rs,scripts.rs}:
    • Wired scripts::placement, scripts::job, scripts::run, and names::make_world (checkout, eager PackView, and lazy SyncLazyTrees) so every call site agrees 100%.
    • Verified Rule 21 cache-key coverage: script_modules::subject and scripts::parts both already hash ran_as as u8 and files digest covers build.rs edits.

Real-Registry & Workspace Audit (Safety Check Before PR 4)

Audited 2,531 .crate tarballs in /home/ix/.cargo/registry/cache/ (351 unpacked in /home/ix/.cargo/registry/src/) plus 4 workspaces (tieline-local, codex-rs, ix, blaze-src):

  • Source classifier matches: ONLY kvm-ioctls-0.24.0 (HostOsStd + ExternC) and rustler-0.38.0 (HostFamilyCfg).
  • Confirmed negative controls (stay Wasm): psm-0.1.32 (#[cfg(unix)] let ... = { use std::os::unix::... }), libsqlite3-sys-0.37.0/0.39.1 (r#"extern "C" {..."#), and anyhow/proc-macro2/thiserror (cfg!(target_os = "linux")).
  • NO_WASM_CLASS dependents: 0 in tieline-local, 0 in blaze-src, protobuf/bindgen/libloading crates only in codex-rs (codex-code-mode-protocol, codex-config, tonic-prost-build, v8, codex-voice-host, bindgen, clang-sys) and ix (raft-proto, protobuf-build, rustler, io-uring, storage-dpdk-sys, storage-spdk-sys, antithesis_sdk, napi-sys, wintun-bindings, bindgen, clang-sys).
  • 0 currently-working Wasm build scripts falsely moved to Native.

Verification

  • cargo test -p blaze-build-script: 169 passed, 0 failed
  • cargo test -p blaze-proc-macro --lib -- native_unit script_unit: 15 passed, 0 failed
  • cargo test -p blaze-cli --bin blaze -- scripts::tests:: script_modules::: 12 passed, 0 failed (+ engine_ready_edit_tests & collect_dedup_script_units / native_script_deps_digest: 9 passed, 0 failed)
  • All 5 ratchets (stops, casts, clones, allocs, ambient) vs origin/main: 0 net new sites (-1 stop in blaze-proc-macro)
  • domains '{"root": "."}': PASS (514 hash domains)
  • git merge-tree --write-tree origin/main HEAD: clean

…cation for protobuf build-deps and host-OS build.rs sources
@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-28T16:40:11.649379Z e58d63b 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: 9b7a2d7874

ℹ️ 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 thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +974 to +976
_ => {
skip_delimited(lex, Token::LParen, Token::RParen);
false

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 Recognize negated Unix cfg macros

On the supported macOS/Linux hosts, cfg!(not(unix)) is false, while it is true in the WASI build-script module. Falling through here therefore leaves such a script on the Wasm runner, so a valid script can emit different Cargo directives or take a failure path compared with native Rust execution. Handle not(...) and other predicates whose host and WASI values differ before choosing Wasm.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment on lines +832 to +835
pub fn script_source_in_tree<'a>(tree: &Tree, root: &ScriptRoot, unit_root: &str, alloc: Alloc<'a>) -> Option<blaze_own::AString<'a>> {
let script_rel = unit_root.trim_start_matches("./");
let bytes = match root.seen() {
blaze_expand::seen::SeenRoot::Package => tree.file(script_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 Inspect build-script modules before placing the unit

This reads only unit.root, so a valid build.rs containing mod host; or include!("host.rs") is classified without inspecting the included source. If that module uses std::os::unix or an FFI block, the root appears Wasm-safe and the build is sent to WASI, where it can fail even though the same package builds on the supported native host. Placement needs to cover the build script's complete module source set, not just the root file.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +203 to +204
if brace_depth == 0 {
return 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 Run crate-level host-gated scripts natively

For a build script such as #![cfg(unix)] fn main() { ... }, this returns None and therefore selects Wasm. On the supported Unix host the script is a valid binary, but under WASI the crate-level attribute removes main, causing compilation to fail; the crate-level false predicate should classify the unit as native rather than as having no native requirement.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment on lines +304 to +310
Token::Ident("extern") => {
let mut look = lex;
match look.next_token() {
Some(Token::LBrace) => return Some(NativeSourceReason::ExternC),
Some(Token::Str(_)) if look.next_token() == Some(Token::LBrace) => {
return Some(NativeSourceReason::ExternC);
}

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 Ignore unexpanded macro bodies during classification

The lexical scan treats every extern token sequence as executable Rust, including tokens inside an unexpanded macro definition. For example, a pure build.rs with an unused macro_rules! ffi { () => { extern "C" { fn f(); } } } is valid for the Wasm runner, but this branch forces it onto the currently unsupported Tier-2 path and blocks the package. Classification must operate on expanded/active code or otherwise distinguish macro token trees from compiled extern blocks.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment thread crates/blaze-cli/src/names.rs Outdated
Comment on lines +2003 to +2005
let view = packs.get(tree_k.checked_sub(1)?)?;
let bytes = view.read_slice(full.as_str(), scratch).ok().flatten()?;
core::str::from_utf8(bytes).ok()

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 source-read failures instead of assuming Wasm

When a fetched pack entry is missing, corrupt, unreadable, or non-UTF-8, these conversions collapse the failure to None; the caller then treats that exactly like a source with no native requirement and derives a Wasm module subject. A later successful job-side read can classify the same script as Native, making the planned key disagree with the run, while a persistent failure produces an unrelated downstream error. Return a named NamesError for the source and path instead of silently changing placement.

AGENTS.md reference: AGENTS.md:L64-L65

Useful? React with 👍 / 👎.

Comment on lines +835 to +839
blaze_expand::seen::SeenRoot::Package => tree.file(script_rel)?,
blaze_expand::seen::SeenRoot::Member { dir } if dir.is_empty() => tree.file(script_rel)?,
blaze_expand::seen::SeenRoot::Member { dir } => {
let full = blaze_own::format_in!(alloc, "{dir}/{script_rel}");
tree.file(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 Read script source through the supplied allocator

Tree::file returns an implicitly globally allocated Vec<u8>, so every placement through outputs or outputs_viewing_on first copies the entire build script onto the process heap and then copies it again into the supplied Alloc as an AString. This bypasses the task allocator and unnecessarily doubles the source footprint; expose a borrowed or allocator-backed tree read and scan those bytes directly.

AGENTS.md reference: AGENTS.md:L50-L51

Useful? React with 👍 / 👎.

Comment thread crates/blaze-cli/src/scripts.rs Outdated
Comment on lines +1785 to +1789
let script_source = script_unit::script_source_in_tree(&tree, &root, unit.root.as_str(), alloc);
let runner = placed_in_store_with_source(
&shared.store,
graph,
job.script,

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 Reuse the placement that named the script task

The module subject and Script task key were already planned with a particular RanAs, but execution rereads mutable source and independently recomputes the runner here. If build.rs changes from pure to host-only during the command, the handed module and task name remain keyed as Wasm while this path runs Native and files a Native payload under that Wasm key. Carry the planned placement proof into ScriptJob and refuse a changed snapshot rather than recomputing it at execution time.

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

Useful? React with 👍 / 👎.

Comment on lines +38 to +42
"prost-build",
"protobuf-build",
"protoc-bin-vendored",
"tonic-build",
"tonic-prost-build",

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 package identity in the no-Wasm classification

These new entries are matched only against Unit.name, so an unrelated workspace, Git, or alternate-registry package named prost-build, protobuf-build, or tonic-build is treated as the crates.io codegen crate. A pure local package with one of these legal names therefore has every dependent build script forced onto the unsupported native path even though its closure compiles for Wasm. Match a source-qualified package identity or an actual required capability rather than a bare package name.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

@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: 0a9e2fbb98

ℹ️ 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 thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +566 to +567
Some(Token::Ident("unix" | "linux" | "macos" | "fd")) => {
return Some(NativeSourceReason::HostOsStd);

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 WASI-compatible std::os::fd scripts on Wasm

When a pure build script uses std::os::fd::{AsFd, OwnedFd, ...}, this arm reports HostOsStd, although the pinned standard library explicitly exposes std::os::fd for target_os = "wasi" in library/std/src/os/mod.rs. Placement therefore sends a script that can compile and run under WASI to the Tier-2 native path, currently blocking the package rather than using the working Wasm runner; remove fd from the host-only set.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +449 to +458
// Skip unexpanded `macro_rules! name { ... }` / `(...)` / `[...]` token trees completely
// so tokens inside macro definitions are never misclassified as compiled code.
if tok == Token::Ident("macro_rules") {
let mut look = lex;
if look.next_token() == Some(Token::Bang)
&& matches!(look.next_token(), Some(Token::Ident(_)))
&& let Some(open) = look.next_token()
&& let Some(close) = closing_delim(open)
{
skip_delimited(&mut look, open, close);

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 constructs from invoked macros

When an invoked macro_rules! macro expands to a native-only construct—for example, its body imports std::os::unix and main calls the macro—the new blanket skip discards the only tokens that reveal that requirement, while the invocation is never expanded. source_requires_native consequently returns None and the valid host build script is compiled for WASI, where the expansion fails; unused macro definitions must be ignored without also hiding expansions that are actually invoked.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +240 to +241
if visited.len() >= MAX_SCRIPT_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 source trees that exceed the scan limit

For a valid build script with more than 256 reachable module/include files, this branch stops scanning and then returns Ok(None), so a native-only reference in any later file is silently classified as Wasm. Keep the traversal bounded, but surface a typed placement error when the limit is reached instead of treating an incomplete scan as proof that no native requirement exists.

AGENTS.md reference: AGENTS.md:L64-L67

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +640 to +641
if let Some(Token::Str(inc_path)) = body.next_token()
&& body.next_token() == Some(close)

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 Follow raw-string include paths

When a valid build script writes include!(r#"host.rs"#), the lexer produces Token::RawStr, but this branch accepts only Token::Str, so host.rs is never inspected. If that included file contains an unguarded host API or foreign block, the script is incorrectly classified as Wasm and fails there; preserve the contents of raw string literals and resolve them exactly like ordinary static include paths.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +561 to +564
if look.next_token() == Some(Token::ColonColon)
&& look.next_token() == Some(Token::Ident("os"))
&& look.next_token() == Some(Token::ColonColon)
{

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 Inspect nested grouped std imports

When a build script uses the common grouped form use std::{env, os::unix::fs::MetadataExt};, the token after std:: is { rather than os, so this matcher never reaches the host-OS check and the remaining tokens are not reconsidered as a std path. The script is therefore classified as Wasm even though std::os::unix is unavailable there; descend through grouped imports and detect an os::{unix,linux,macos} branch before choosing the runner.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

…gs on Tier-2 classifier

- Keep WASI-compatible std::os::fd scripts on Wasm (remove fd from host-only std::os set)
- Inspect nested grouped std::{..., os::{unix,linux,macos}} imports
- Preserve native constructs and child files from invoked macro_rules! definitions (including transitive and cross-file invocations) while still ignoring unused definitions
- Follow raw-string include!(r#"..."#) and #[path = r#"..."#] paths
- Refuse build-script source trees exceeding MAX_SCRIPT_FILES (256) with typed ScriptSourceError::TooManyFiles propagated through script_unit, names, and scripts
@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: 0edbb17e14

ℹ️ 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 thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +1878 to +1879
("target_os", _) => {
CfgEval { host: TriBool::Unknown, wasi: TriBool::False, family_div: false }

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 Treat concrete host cfg values as divergent

On a Linux host, a build script containing if cfg!(target_os = "linux") { println!("cargo:rustc-cfg=foo"); } must take that branch, but this arm produces (Unknown, False) without family_div, so diverges_host_vs_wasi() returns false and the script is run as WASI, where the branch is skipped. The same problem affects concrete host architectures and environments, causing accepted build scripts to emit different directives or execute different failure paths; classify these predicates using the actual supported host rather than treating its side as unknown.

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

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +566 to +568
let is_ready = self.defs.get(i).is_some_and(|def| {
!def.resolved && self.invoked.iter().any(|inv| inv.as_str() == def.name.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 Resolve macro invocations in their lexical scope

When two modules define macros with the same name, this global name comparison marks both definitions invoked even though Rust resolves the call only in its lexical scope. For example, an uninvoked a::m! whose transcriber imports std::os::unix and an invoked, WASI-safe b::m! cause the native transcriber in a to be selected, forcing an otherwise valid WASI script onto the currently unsupported Tier-2 path. The fresh issue is that the new invocation propagation compares only macro names across the entire source tree; definitions and calls need scope-aware identities.

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

Useful? React with 👍 / 👎.

Comment on lines +1298 to +1301
if b == b'\\' {
self.at += 1;
if self.peek_byte(0).is_some() {
self.at += 1;

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 Decode escapes in static source paths

When a valid build script uses an escaped ordinary string such as include!("host\x2ers") or #[path = "host\x2ers"], Rust resolves the literal value to host.rs, but this scanner merely skips over the escape and returns the original backslash-containing slice. The traversal consequently treats the real file as absent; if it contains std::os::unix or an extern block, the script is classified as Wasm and then fails when compilation follows the decoded path. Decode ordinary string literals before using them as module or include paths.

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

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +815 to +817
} else if cfg.wasi == TriBool::False && excluded_depth == 0 {
pending_excluded = true;
pending_depth = brace_depth;

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 Exclude modules disabled by the build script's cfg set

For non-target predicates such as #[cfg(test)] or a disabled #[cfg(feature = "native")], eval_cfg_pair returns Unknown, so this condition leaves the item active and the source-tree walk follows its external module. A normal build of #[cfg(test)] mod tests; fn main() {} is WASI-safe even if tests.rs imports std::os::unix, but the scanner reports that inactive file as native-only and sends the package to the currently unsupported Tier-2 path. Evaluate attributes using the unit's actual features and build-script cfg set before scanning guarded code.

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

Useful? React with 👍 / 👎.

…gs on Tier-2 classifier

- Add ScriptCfg (concrete host target_os/arch/env/vendor/pointer_width + unit features) and treat concrete host cfg! mismatches against WASI as divergent
- Evaluate #[cfg(test)], #[cfg(doctest)], and unit #[cfg(feature = "...")] attributes so disabled modules/items are excluded from scanning
- Resolve macro_rules! definitions and invocations in lexical scope with #[macro_use], #![macro_use], #[macro_export], textual shadowing, and qualified module paths
- Decode Rust string escapes in ordinary include!(...) and #[path = ...] string literals (and cfg values) while keeping raw strings verbatim
@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: 00c649ad76

ℹ️ 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 thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +1430 to +1432
} else if attr_cfg.wasi == TriBool::False && excluded_depth == 0 {
pending_excluded = true;
pending_depth = brace_depth;

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 host-gated build-script entry points

When a valid host build script uses #[cfg(unix)] fn main() { ... }, this branch treats the item as merely inactive on WASI and skips it, so classification returns Wasm; compiling that script for WASI then removes the only entry point and fails with a missing main. Detect a host-active/WASI-inactive main as requiring native placement rather than excluding it like an ordinary guarded item.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment thread crates/blaze-build-script/src/native.rs Outdated
Comment on lines +2685 to +2687
match look.next_token() {
Some(Token::Ident("cfg")) if look.next_token() == Some(Token::LParen) => {
out.cfg = Some(eval_cfg_pair(&mut look, cfg, 0));

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 Evaluate cfg_attr when resolving module paths

When a build script uses #[cfg_attr(unix, path = "host.rs")] mod imp;, this parser ignores cfg_attr and the traversal inspects imp.rs instead of the host.rs selected on the supported host. If those files implement different behavior or host.rs uses host-only APIs, the script is classified and compiled for WASI with the wrong module, changing emitted Cargo directives or failing despite being valid on the host; resolve active cfg_attr attributes before following the module.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Token::Ident("std") if is_root_std_path(prev, prev_prev) => {
let mut look = lex;
if look.next_token() == Some(Token::ColonColon) {
match look.next_token() {

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 Classify target-dependent std environment constants

When a build script emits output based on std::env::consts::OS, ARCH, or FAMILY, this std matcher ignores the path because it only recognizes std::os. The script is therefore placed on WASI, where those compile-time constants describe WASI rather than the supported native host, so a valid script such as println!("cargo:rustc-cfg=os_{}", std::env::consts::OS) produces different Cargo directives from native execution; classify these target-dependent constants as requiring the host runner.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

buf.extend_from_slice(slice);
}
}
Err(e) if e.kind() == ErrorKind::Interrupted => 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.

P2 Badge Bound retries for interrupted source reads

When this file read is repeatedly interrupted, the unconditional continue can keep a worker in source classification forever because the loop has no retry count, deadline, or cancellation check. Propagate the interruption or run the read through a bounded wait so signal-heavy execution cannot stall the whole build indefinitely.

AGENTS.md reference: AGENTS.md:L64-L67

Useful? React with 👍 / 👎.

…n Tier-2 classifier

- Preserve host-gated build-script entry points (#[cfg(unix)] fn main()) as HostFamilyCfg instead of skipping them
- Evaluate #[cfg_attr(pred, ...)] (including nested/multi-item forms) for path, cfg, macro_use, and macro_export attributes
- Classify target-dependent std::env::consts::* references (direct, grouped, and imported env::consts) as HostFamilyCfg
- Bound EINTR retries (MAX_EINTR_RETRIES = 16) in Tree::with_file_bytes_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: e58d63b330

ℹ️ 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 +1680 to +1684
Token::Ident("std") if is_root_std_path(prev, prev_prev) => {
let mut look = lex;
if look.next_token() == Some(Token::ColonColon) {
match look.next_token() {
Some(Token::Ident("os")) if look.next_token() == Some(Token::ColonColon) => {

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 Track aliases of the standard library

When a valid host build script aliases std, such as extern crate std as host_std; use host_std::os::unix::fs::MetadataExt;, this matcher sees neither a root std::os path nor an extern block and classifies the script as Wasm. Compilation then fails because host_std::os::unix is unavailable under WASI, even though the script is accepted on the supported native host; resolve std aliases before matching host-only paths.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

}
("target_endian", "little") => CfgEval::leaf(TriBool::True, TriBool::True),
("target_endian", _) => CfgEval::leaf(TriBool::False, TriBool::False),
_ => CfgEval::UNKNOWN,

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 Evaluate target_feature predicates for both runners

For build scripts using cfg!(target_feature = "sse2") on x86_64 or analogous host features, this default arm returns Unknown for both targets, so the classifier selects Wasm even though the predicate's native and WASI values differ. Such a script can emit different Cargo directives or take a different failure path under WASI; evaluate target features from the concrete host and WASI targets, or refuse predicates whose equivalence cannot be established.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment on lines +1818 to +1823
let mut body = look;
if let Some(inc_lit) = str_literal(body.next_token())
&& body.next_token() == Some(close)
{
sink.push_include(current_rel, current_scope, inc_lit);
}

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 computed include paths before classifying

When a build script uses the common valid form include!(concat!(env!("CARGO_MANIFEST_DIR"), "/host.rs")), the first token is not a string literal, so this branch skips the entire invocation without inspecting host.rs. If that file imports std::os::unix or contains a foreign block, the script is classified as Wasm and fails there; expand statically resolvable include! arguments or refuse placement when the included source cannot be determined.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment on lines +2401 to +2404
if self.peek_byte(1) == Some(b'#') {
self.at += 2;
self.skip_ident_tail();
return Some(Token::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 Recognize raw identifiers in module declarations

For a valid declaration such as mod r#type;, the lexer emits Other for r#type, so the mod matcher never queues the corresponding type.rs. A host-only import or foreign block in that module is therefore missed and the build script is compiled as Wasm; return the raw identifier's decoded name as an identifier token so module traversal follows the file.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment on lines +1321 to +1325
if let Some(transcriber) = body_src.get(t_start..t_end)
&& let Some(reason) = scan_source_core(transcriber, false, current_rel, def_scope, cfg, macro_depth, sink)
{
def_reason = Some(reason);
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.

P1 Badge Match the invoked macro arm before classifying it

When an invoked macro_rules! definition has a WASI-safe selected arm and an unselected arm containing std::os::unix or an extern block, this loop records the native reason from the unselected transcriber and propagates it merely because the macro name was invoked. For example, platform!(safe) is forced onto the native path if a separate (native) arm is host-only, blocking an otherwise valid WASI script; classification must match the invocation tokens to the expanded arm rather than merging every arm's requirements.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

Comment on lines +1435 to +1441
if attr_cfg.wasi == TriBool::False {
if pending_excluded && pending_depth == brace_depth {
pending_excluded_host_active &= attr_cfg.host != TriBool::False;
} else {
pending_excluded = true;
pending_excluded_host_active = attr_cfg.host != TriBool::False;
pending_depth = brace_depth;

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 host-active cfg-attributed behavior

When executable behavior is guarded by a host-only attribute, such as fn main() { #[cfg(unix)] println!("cargo:rustc-cfg=host_unix"); }, this branch simply excludes the statement from the WASI scan and returns no native reason. The native build script emits the Cargo directive while the selected WASI runner does not, so dependent compilation changes despite both sources being valid; host-active/WASI-inactive executable code must require native placement rather than being treated as safely absent.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.

@mteacher360

Copy link
Copy Markdown
Collaborator Author

Closing the lexical pre-run source classifier approach: static lexical scanning cannot soundly approximate Rust macro expansion, include!(concat!(...)), std aliasing, and host-vs-WASI cfg evaluation. Instead, we will land Tier-2 native self-compilation (#2884 + native export_par script builder) first and drive Tier-2 placement from Blaze's real frontend/wasm64 compiler.

@mteacher360
mteacher360 deleted the feat/tier2-prerun-native-classifier branch November 28, 2026 16:44
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