1

I have a Rust crate A that depends on another Rust crate B; both of them are STD-clean (i.e. both use #![no_std]) and there are no other dependencies. I would like to get my hands on the LLVM IR of all the code needed to statically link it together with lld.

To get the LLVM IR from just A, I am currently passing --emit=llvm-ir to cargo rustc. This results in target/debug/deps/A-someKindOfHash.ll which I can then consume -- in my case, by using Clang to link it with some C code that calls (non-mangled) Rust functions.

However, that .ll file doesn't contain all transitive dependencies, so as soon as A actually starts using functions from B, this breaks down.

How do I tell Cargo to create LLVM IR from all dependencies and put them somewhere under target/?

kmdreko
  • 42,554
  • 6
  • 57
  • 106
Cactus
  • 27,075
  • 9
  • 69
  • 149
  • 2
    Does this answer your question? [Rust: Including dependenies in LLVM Bitcode](https://stackoverflow.com/questions/69042049/rust-including-dependenies-in-llvm-bitcode) (bitcode is the binary form of the IR) – smitop Sep 04 '21 at 13:24

0 Answers0