Skip to content

perf: declare artifact cdylibs as normal dependencies - #636

Merged
wan9chi merged 1 commit into
revert-artifact-profile-overridesfrom
artifact-cdylib-normal-deps
Aug 11, 2026
Merged

perf: declare artifact cdylibs as normal dependencies#636
wan9chi merged 1 commit into
revert-artifact-profile-overridesfrom
artifact-cdylib-normal-deps

Conversation

@wan9chi

@wan9chi wan9chi commented Aug 10, 2026

Copy link
Copy Markdown
Member

Motivation

Cargo compiles artifact dependencies declared under [build-dependencies] with the build-override profile — opt-level 0 even in release builds — and only root-manifest profile overrides can fix it, which every downstream workspace has to copy (rust-lang/cargo#16719). The preload libraries run inside every intercepted libc call and vt_client_napi backs the Node.js client, so their optimization should not depend on fragile per-workspace boilerplate. Declaring them under [dependencies] applies the normal profile everywhere automatically.

What this does

  • Moves fspy_preload_unix/fspy_preload_windows/vt_client_napi from [build-dependencies] to target-scoped [dependencies]. They now build with the full release profile (opt-level=3, lto=fat, codegen-units=1, strip=symbols) and additionally gain panic = "abort", in this workspace and downstream ones, with no profile overrides.
  • CARGO_CDYLIB_FILE_* is provided while the consuming crate compiles rather than to its build script, so hashing moves into a new materialized_artifact_macros::artifact! proc macro that reads and hashes the file at expansion time (same xxh3 {:x} format, so materialized filenames are unchanged).
  • The macro declares its reads via proc_macro::tracked so a future proc-macro expansion cache can never serve a stale hash next to fresh bytes, and its expansion re-references the env var and file through include_bytes!(env!(…)) for dep-info tracking.
  • When the env var is unset, the expansion branches on cfg(rust_analyzer): a well-typed stub under rust-analyzer, an actionable compile_error! under rustc. The cfg tokens never appear in successful builds, so no check-cfg declarations are needed.
  • The macOS downloaded binaries switch to the same macro (their build script now publishes only a path via cargo:rustc-env), leaving materialized_artifact_build without consumers; the crate is removed.
  • Target-scoping the preload deps stops musl and cross-OS builds from producing useless empty cdylibs. The known resolver panic on cfg-scoped artifact deps only affects [build-dependencies] placement.

Behavior note: panic = "abort" now applies to vt_client_napi — a panic in the addon aborts the Node process instead of unwinding into napi-rs's catch_unwind. This matches the workspace-wide abort policy.

🤖 Generated with Claude Code

Move the fspy preload libraries and vt_client_napi from
`[build-dependencies]` to (target-scoped) `[dependencies]`. Cargo
compiles build-dependency artifact deps with the build-override profile
— opt-level 0 in release builds, and only a root-manifest override can
fix it, which every downstream workspace had to copy (see
rust-lang/cargo#16719). Under `[dependencies]` the normal profile
applies everywhere with no overrides, and the cdylibs additionally gain
`panic = "abort"` from the release profile.

`CARGO_CDYLIB_FILE_*` is now provided while the consuming crate
compiles instead of to its build script, so hashing moves from
`materialized_artifact_build::register` into a new
`materialized_artifact_macros::artifact!` proc macro that reads and
hashes the file at expansion time. The macro declares its reads via
`proc_macro::tracked` so a future expansion cache cannot serve a stale
hash next to fresh bytes, and its expansion re-references the file and
env var through `include_bytes!(env!(…))` for dep-info tracking. When
the env var is unset the expansion branches on `cfg(rust_analyzer)`:
a well-typed stub under rust-analyzer, an actionable `compile_error!`
under rustc.

The macOS downloaded binaries switch to the same macro (their build
script now publishes only a path via `cargo:rustc-env`), which leaves
`materialized_artifact_build` without consumers; the crate is removed.
Scoping the preload deps to the targets that embed them also stops
musl and Windows/Unix cross-builds from producing empty cdylibs —
resolver panics on cfg-scoped artifact deps only affect
`[build-dependencies]` placement.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  -5.12%  [-12.17% ..  +4.35%]  overhead   +50.92%
dynamic/access             change -34.24%  [-35.47% .. -33.11%]  overhead    +6.32%
dynamic/access-relative    change -46.60%  [-47.20% .. -46.09%]  overhead   +46.51%
static/launch              change  +0.53%  [-10.51% ..  +9.73%]  overhead  +144.96%
static/access              change  +0.66%  [ -1.35% ..  +5.07%]  overhead  +813.60%
static/access-relative     change  +1.37%  [ -1.32% ..  +6.24%]  overhead +1318.01%

macos

dynamic/launch             change  -1.27%  [ -7.17% ..  +4.26%]  overhead  +238.11%
dynamic/access             change -21.96%  [-27.57% .. -12.53%]  overhead    +3.74%
dynamic/access-relative    change -12.68%  [-18.46% ..  -5.33%]  overhead  +252.16%

windows

dynamic/launch             change  -2.84%  [-13.15% ..  +5.73%]  overhead   +25.73%
dynamic/access             change  -5.27%  [-11.66% ..  -0.13%]  overhead    +2.54%
dynamic/access-relative    change  -7.28%  [-30.58% ..  +0.62%]  overhead    +1.85%

@wan9chi
wan9chi merged commit 521422f into main Aug 11, 2026
29 of 31 checks passed
@wan9chi
wan9chi deleted the artifact-cdylib-normal-deps branch August 11, 2026 01:03
wan9chi added a commit that referenced this pull request Aug 11, 2026
## Motivation

#597 worked around Cargo compiling `[build-dependencies]` artifact deps
with the build-override profile (opt-level 0 in release;
rust-lang/cargo#16719) using per-package `[profile.release.package.*]`
overrides plus the `artifact_profile` build-script guard. The next PR in
this stack (#636) moves the artifact cdylibs to `[dependencies]`, where
the normal release profile applies in this workspace and every
downstream one — making both the overrides and the guard dead machinery.

## What this does

Reverts #597 (5ed7a5a): removes the three profile-override blocks, the
`artifact_profile` crate, and its build-script guard calls from the
preload and napi crates.

Note: artifact cdylibs build unoptimized between this PR and #636; the
stack lands together.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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