|
|
|
|
|
by MarkSweep
1367 days ago
|
|
Not that this is based on some Googleing and experimentation; I could not find official docs. It actually is possible to dynamically link to the standard library. Add this to your project's .cargo/config.toml file: [build]
rustflags = ["-C", "prefer-dynamic"]
And add a reference to this crate, which copies the stdlib's shared library to your output directory:https://github.com/WilliamVenner/prefer-dynamic After you do `cargo build --release`, you will notice you hello world EXE is much smaller than a typical rust binary. Like 10~20KB small. On Windows it runs just fine. On Linux, I has to change the exe's RPATH to look for the standard library in the current directory: patchelf --set-rpath '$ORIGIN' ./exe_name
Anyways, it is possible. The rustc compiler itself is shipped in this way. |
|
tried all size reduction tricks,still the size is much large,like 15x large than c,c++. even the stdlib is a 3x larger than to libstdc++