we develop software for an embedded environment where our build process goes like this: we compile all source code as static libraries and then we link them with a modified linker that takes care of adapting the program entry to the embedded environment.
We are able to use rust, which is great. But our procedure is extremely hackish and I was hoping for some hints how we can enhance it.
So this is what we do with for a rust program:
- We replace the original
#[no_mangle] pub extern fn main()to expose the main function and make it accessible as
mainto our starter code.
- We add the following section to
Cargo.tomlto make cargo build everything as a static library
[lib] crate-type= ["staticlib"]
- We link the resulting library with our linker and voíla it works.
All of those steps are done manually, which is not optimal. It would be nice to have this process directly in cargo invoked with a special
--target triple. Is this possible?
Last but not least, while testing we found the rust runtime and that we have to initialize it to receive program arguments for example. Since the runtime is not publicly exposed by the
std crate we have no means to do this. It seems that rustc generates a
rust_main function to initialize the runtime through llvm when a rust executable is built. This is at least what we think ;). How could we do this initialization on our own?