Greetings. I need help in building chain of my rust libraries without duplication.
I have N libraries, some of which use functions from each other. Let's say I have 3 libraries: lib1, lib2 and lib3. lib2 calls some of lib1 functions, lib3 calls some of lib2 functions and uses structs from lib1 too.
What I need: std, lib1, lib2 and lib3 built statically, with their functions only (no std, no including each other). Then I link all of them (std.a, lib1.a, lib2.a, lib3.a) onto binary, binary calls some functions from lib2 and lib3, maybe lib1, doesn't matter. No duplication.
What cargo does now, when I build crates with lib target statically:
lib1:
--std
--function set 1
lib2:
--std
--function set 1
--function set 2
lib3:
--std
--function set 1
--function set 2
--function set 3
Binary (non-rust) will conflict when tried to link all of these into one piece.
What I'd like to have:
lib1:
--function set 1
lib2:
--function set 2
lib3:
--function set 3
std:
-- function set std (suppose all of them, or even better if I could cut off anything lib1, lib2 and lib3 don't use)
Binary then links separately all the libs, including Rust std, because it's non-rust.
How do I do this? I did this before with my C libs, went all in with Rust this time and now struggling with linking.
I understand that Rust doesn't have stable ABI, but all of the above guaranteed to be built with the same toolchain before including into target binary and linking, so it doesn't matter to me. I just don't want to assemble those lib files manually from .o files each time using some script, I'd like to use cargo for building 'thin' libraries, without including all dependencies they use, and include those dependencies separately later in binary.