commit | e7f55168ace5920eb41488133f3c03ada7fcd998 | [log] [tgz] |
---|---|---|
author | Vinh Tran <vinhdaitran@google.com> | Fri Feb 23 10:58:54 2024 -0500 |
committer | GitHub <noreply@github.com> | Fri Feb 23 15:58:54 2024 +0000 |
tree | 647270b2803eb0f47f16807becf33485fdce520d | |
parent | 33fdddd03c9a958d82efcf9658f9dce13a9f06df [diff] |
Implement support for dylib linkage (#2414) This PR implements dylib linkage against the standard library behind a feature flag `--@rules_rust//rust/settings:experimental_use_dylib_linkage`. The main part of this feature is [here](https://github.com/bazelbuild/rules_rust/pull/2414/files#diff-2a806da393e47c07ffe67c78ace69eb488b4ac44b029a46d8237b8e2a05637beR258) where we skip exporting static rust stdlibs and export only `libstd.so` instead. This feature is useful when the subset of libstd being statically linked to downstream shared libraries and binaries is **larger** than the entire dylib version of libstd. The following diagram is the high level of what dylib linkage is trying to achieve.  Running the feature against `android_binary` yields a size reduction on the shared library produced by `android_binary` because it doesn't statically link the rust stdlibs anymore. ``` > bazel build //:android_app --config=android_x86_64 > unzip -l bazel-bin/android_app.apk Archive: bazel-bin/android_app.apk Length Date Time Name --------- ---------- ----- ---- 1381968 2010-01-01 00:00 lib/x86_64/libandroid_app.so <--- static link with rust stdlibs --------- ------- 1390294 9 files ``` ``` > bazel build //:android_app --config=android_x86_64 --config=dylib_linkage > unzip -l bazel-bin/android_app.apk Archive: bazel-bin/android_app.apk Length Date Time Name --------- ---------- ----- ---- 8080 2010-01-01 00:00 lib/x86_64/libandroid_app.so <--- reduced size because of dynamic linking 13055776 2010-01-01 00:00 lib/x86_64/libstd-8d416d49cf02ecea.so --------- ------- 13072400 10 files ``` Here, the benefit comes when there are enough shared libraries statically linking against the rust stdlibs. "Enough" here means that the total up size of those libraries being more than just the entire `libstd.so`. TODO: I'm leaving this PR without unit tests until I get some feedback or suggestions on my approach. --------- Co-authored-by: scentini <rosica@google.com>
This repository provides rules for building Rust projects with Bazel.
General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust
.
Please refer to the full documentation.