I link against a C library with a very small function, and I would like its code to be inlined in the Rust function that calls it. I had hoped that it would be possible by setting lto = true in Cargo.toml, but there is still a call in the final executable. This comment confirms that at the moment there is no LTO between Rust and C.
I remember seeing an issue comment here that explained how to do it manually by emitting LLVM IR with rustc and clang and linking it together with llvm-link, then opt, but I cannot seem to find it any more.
The call overhead can be substantial. For my current use case that calls a C function in an inner loop, it causes the running time to be 9 times as long as the equivalent program where the function is inlined. (It relies on a number of unstable features to be able to express the function in Rust.)
So for “efficient C bindings”, LTO that can inline across C and Rust objects would be nice to have.
I link against a C library with a very small function, and I would like its code to be inlined in the Rust function that calls it. I had hoped that it would be possible by setting
lto = trueinCargo.toml, but there is still a call in the final executable. This comment confirms that at the moment there is no LTO between Rust and C.I remember seeing an issue comment here that explained how to do it manually by emitting LLVM IR with
rustcandclangand linking it together withllvm-link, thenopt, but I cannot seem to find it any more.The call overhead can be substantial. For my current use case that calls a C function in an inner loop, it causes the running time to be 9 times as long as the equivalent program where the function is inlined. (It relies on a number of unstable features to be able to express the function in Rust.)
So for “efficient C bindings”, LTO that can inline across C and Rust objects would be nice to have.