More granual `build.rs` companion: `links.rs`
Rust Internals [Unofficial]
April 15, 2026
The problem
Click to fold (click for more details)
Palliatives / working around it with the current tools
Click to seeRelevant snippet from my rust-analyzer config (click for more details)
The suggested solution
Would be for Cargo to fully acknowledge and embrace this package.links with a companion build script (the "conceptual links.rs build script"), and reïfy this concept :
Allow for
package.linksto be set to an object rather than just a string, with, at least:nameentry, to be set to its identifying name,scriptentry: to be set to point to some.rsfile.- Optionally, it could be set to
trueto default to"links.rs"; and/or having such a file alongside aCargo.tomland alinks = "libfoo" kind of entry could be tantamount to all this.
- Optionally, it could be set to
[package]
links = { name = "libfoo", script = "links.rs" }
Such a
links.rs-specified Rust file shall:be interpreted like a
build.rsdoes currently in Rust:- involving
build-dependencies, - living in the
build/host universe (e.g. , w.r.t. Cargoresolveror whatnot); - being bypassable through
linksoverrides (thebuild.rsbeing the one bypassed as a fallback , for retro-compat).
- involving
but only involved:
- for actual
cargo-compiling commands, such asbuild/run/test/bench, i.e. , it would be skipped when runningcargo check/clippy/doc. - invoked in the tail-end of the compilation pipeline.
- for actual
Or, more precisely, deemed to have no dependents inside Cargo pipelining but for the compilation/linkage of the very final artifact(s) (which cargo check/clippy/doc do not produce).
Discussion in the ATmosphere