Inject the hermit crate if necessary#154130
Conversation
On Hermit, the OS is included in the `hermit` crate. This commit makes sure we link against the possibly renamed `hermit` crate if it is provided even if there is no explicit `extern hermit`. This is similar to replacing `--extern hermit` with `--extern force:hermit`.
|
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Individual targets certainly shouldn't require special casing like this from the compiler. Stabilizing If the |
|
I agree with @petrochenkov. This is not something that should be done in the crate loader. Having the standard library depend on the hermit library would be a much better solution. If that is not an option as you want to allow users to use a newer version of Hermit than was available when the standard library got compiled, then having users add As for stabilizing |
|
Thanks for the swift responses! Currently (for the past seven years), we tell users to put For the Hermit OS, the
In that case it might be useful to introduce an option to the Such a thing would likely not require an RFC, right? Instead, I should open an issue on Cargo's issue tracker for this feature request, right? |
This PR makes rustc always link against the
hermitcrate on Hermit if the crate is present.For Hermit, the static library OS (
libhermit.a) is compiled in thehermitcrate's build script and then linked against. Users just addhermitto the application'sCargo.toml. This causes Cargo to call rustc with--extern hermit=$PATH_TO_libhermit-hash.rlib. Unless users also specifyextern crate hermit, though, rustc calls the linker withoutlibhermit.rlib, which is intended:Command-line Arguments - The rustc book
This PR makes sure that rustc links against the
hermitcrate if somelibhermit-hash.rlibfile is being supplied. From the outside, this is similar to replacing--extern hermitwith--extern force:hermitbut also supports crate renaming. Internally, the crate mechanism works similarly to the one that is used for compiler builtins, forced externs, the profiler runtime, the allocator crate, and the panic runtime. This allows users to avoid modifying their Rust applications to use Hermit. Putting the crate into theCargo.tomlis sufficient.This approach is very similar to what we do in our GCC cross compiler (hermit-os/gcc/gcc/config/i386/hermit.h#L5): we put
-lhermitintoLIB_SPECto ensure that each Hermit application links againstlibhermit.a. This PR applies the same approach to rustc but has to account for the hash inlibhermit-hash.rliband accounts for the possibility of users renaming thehermitcrate.An alternative for a more general approach to avoid adding more target-specific code to
rustc-metadatecould be stabilizing--extern force(#111302) and making this available for dependencies. Then, thehermitcrate could enableextern forcein itsCargo.toml, which would ensure it is linked even if unused. This would likely take a while, though, and I am not sure if we have the resources to put significant effort into such a more general approach. Meanwhile, this small patch might be bearable.