I've created a crate that will act as "core" for any further binaries built on top of this crate. As this core crates depends on specific linker symbols provided by a linker script the building of the final binary should always use the linker script provided by the core crate.
I'm able to pass the link script by copy it from the git repository or the src folder where cargo put the core crate after downloading it from crates.io to the actual project directory and use the rustflag -C linker-args=-T./link.ld
As I'm sure cargo will download the crate source to some fixed location, or a location following some patterns, so is there a way to get the src folder location of the dependent crate in an environment variable to pass this to the rustflags when building the final binary? This would ensure always the correct and latest version of the link script is used for linking the binary.
I've checked that there are some related questions about passing linker arguments from build scripts etc, but I could not find any solution or hint how this could be achieved if at all possible.
Thx in advance for any hint.
I'v also checked the
#[linker_args]attribute which is working fine if it is part of the crate building the binary, but this does not work if it is part of the dependent crate.
So the summary is:
kernel depends on a crate
link.ld link script. This shall be used while building
kernel crate, preferably some sort of "automatically" as soon as the dependency to
core crate is defined in the cargo.toml of
kernel crate. May be "secured" by a feature gate of the
corecrate to ensure one could explicitly configure when not to use this provided link script.
Thanks in advance for any hint ...