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>
diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel
index d32161a..8845e38 100644
--- a/WORKSPACE.bazel
+++ b/WORKSPACE.bazel
@@ -79,7 +79,7 @@
http_archive(
name = "rules_testing",
- sha256 = "b84ed8546f1969d700ead4546de9f7637e0f058d835e47e865dcbb13c4210aed",
- strip_prefix = "rules_testing-0.5.0",
- url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.5.0/rules_testing-v0.5.0.tar.gz",
+ sha256 = "02c62574631876a4e3b02a1820cb51167bb9cdcdea2381b2fa9d9b8b11c407c4",
+ strip_prefix = "rules_testing-0.6.0",
+ url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz",
)