The context for this thread is the pull request here: https://github.com/rust-lang/cargo/pull/7811
We at the Enarx project are writing low level code, including kernel-like things. We need to control linking arguments on things that aren't
cdylib. I submitted a pull request implementing this feature.
Build scripts can already specify linker flags using
rustc-cdylib-link-arg. I simply extended this to support
rustc-bin-link-arg as well as
rustc-link-arg (for either
bin). However, gathering broader input before merging such a feature seems wise.
Low level code needs access to the linker. No, it isn't portable. Yes, you can shoot yourself in the foot. But there isn't really any other way around it. Adding an option just for linker scripts isn't a good enough option because:
- Linker scripts don't work on all platforms.
- Linker scripts aren't portable.
- Access to other linker options is desirable.
The best option is to allow
build.rs to make some intelligent choices based on which linker is in use. From here, utility crates (similar to
cc) can attempt to build additional functionality on top of the raw primitives.