Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xaeroxe/strict_linking_rs
Enforces the requirement that all symbols link correctly for a rust project
https://github.com/xaeroxe/strict_linking_rs
Last synced: 23 days ago
JSON representation
Enforces the requirement that all symbols link correctly for a rust project
- Host: GitHub
- URL: https://github.com/xaeroxe/strict_linking_rs
- Owner: Xaeroxe
- Created: 2022-04-03T22:19:54.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-02T17:28:09.000Z (over 2 years ago)
- Last Synced: 2025-01-06T01:08:14.670Z (23 days ago)
- Language: Rust
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# strict_linking_rs
Enforces the requirement that all functions defined inside your crate's `extern "C"` blocks must be resolved in the final executable.## Warning
This software has not been tested on many systems and is known to be incompatible with some project setups. It's considered to be "In Beta".
Our aim is to be compatible with as much as possible, however linkers are moody and fickle. I welcome issue reports and minimal reproductions.
Additionally, using this may significantly increase your build time.# To use
In your [`build.rs`](https://doc.rust-lang.org/cargo/reference/build-scripts.html) file add this line to your `main()` function
```rust
strict_linking::init();
```And then in your `Cargo.toml` file add this
```toml
[build-dependencies]
strict_linking = "0.1"
```# How does it work?
First, we use `cargo +nightly rustc --profile=check -- -Zunpretty-expanded` to expand macros inside the code for your
crate. Then we parse that with the [`syn`](https://crates.io/crates/syn) crate, and walk down the syntax tree
recursively, looking for `extern "C"` blocks. We use the information from these to build a linker script, which we'll
then feed into your linker via
[`cargo:rustc-link-arg`](https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-arg).
The linker script uses platform specific flags like
[`/INCLUDE`](https://docs.microsoft.com/en-us/cpp/build/reference/include-force-symbol-references?view=msvc-170)
and `--undefined` so that the linker will not link successfully if one of those symbols is missing.