5 ms·
> You just need to provide a C ABI compatible with the original one. How does this interact with dynamic linking? Doesn't the current Rust toolchain mandate st
by rlpb 1y ago
> You just need to provide a C ABI compatible with the original one.
How does this interact with dynamic linking? Doesn't the current Rust toolchain mandate static linking?
- sedatk 1y agoNo. https://doc.rust-lang.org/reference/linkage.html#r-link.dylib https://doc.rust-lang.org/reference/linkage.html#r-link.dyli...
- arcticbull 1y agoRust lets you generate dynamic C-linkage libraries. Use crate-type=["cdylib"]
- nicoburns 1y agoDynamic linking works fine if you target the C ABI.
- timeon 1y agoYou can use dynamic linking in Rust with C ABI. Which means going through `unsafe` keyword - also known as 'trust me bro'. Static linking directly to Rust source means it is checked by compiler so there is no need for unsafe.
- bluGill 1y agoRust cannot dynamic link to rust. It can dynamic link to C and be dynamicly linked by C - if you combine the two you can cheat but it is still C that you are dealing with not rust even if rust is on both sides.
- deleted 1y ago[deleted]
- mjevans 1y agoIt might help to think of it as two IPC 'servers' written in rust that happen to have the C ABI interfaces as their communication protocol.
- filmor 1y agoRust can absolutely link to Rust libraries dynamically. There is no stable ABI, so it has to be the same compiler version, but it will still be dynamically linked.
- conradev 1y agoRust importing Rust must be statically linked, yes. You can statically link Rust into a dynamic library that other libraries link to, though!
- alxhill 1y agoThe commenters below are confusing two things - Rust binaries can be dynamically linked, but because Rust doesn’t have a stable ABI you can’t do this across compiler versions the way you would with C. So in practice, everything is statically linked.
- eru 1y agoStatic linking also produces smaller binaries and lets you do link-time-optimisation.
- emidln 1y agoStatic linking doesn't produce smaller binaries. You are literally adding the symbols from a library into your executable rather than simply mentioning them and letting the dynamic linker figure out how to map those symbols at runtime. The sum size of a dynamic binary plus the dynamic libraries may be larger than one static linked binary, but whether that holds for more static binaries (2, 3, or 100s) depends on the surface area your application uses of those libraries. It's relatively common to see certain large libraries only dynamically linked, with the build going to great lengths to build certain libraries as shared objects with the executables linking them using a location-relative RPATH (using the $ORIGIN feature) to avoid the extra binary size bloat over large sets of binaries.
- IshKebab 1y agoStatic linking does produce smaller binaries when you bundle dependencies. You're conflating two things - static vs dynamic linking, and bundled vs shared dependencies. They are often conflated because you can't have shared dependencies with static linking, and bundling dynamically linked libraries is uncommon in FOSS Linux software. It's very common on Windows or with commercial software on Linux though.
- guappa 1y agoYou know how the page cache works? Static linking makes it not work. So 3000 processes won't share the same pages for the libc but will have to load it 3000 times.