Add support for Rust ABI dynamic libraries (#4179) Currently, there is not explicit stable Rust ABI for dynamic libraries, but Rust library may still be compiled as one. This can be useful if a large project wants to compile some core portion of its code as a shared object that can be dynamically linked against several different binaries. Bevy, for example, offers this capability as a way to allow customers of Bevy to tweak their own code without having to statically re-link the central Bevy engine code. This PR exposes the Rust ABI dylib capabilities with a new rule, `rust_dylib_library`. For clarity, it also creates a `rust_cylib_library` rule, and updates methods to this name, with `rust_shared_library` just aliasing to the `rust_cdylib_library` implementation. Building a Rust ABI dylib may cause the standard library to be linked dynamically against the generated dylib. When depended on, the dynamic standard library needs to be included to get the binary to execute. Currently, `rules_rust` offers this as a toolchain-level flag, but applying a toolchain transition at the dylib's interface imposes a new toolchain on its deps, which then forces any upstream `rlibs`, for example, to recompile. To fix this, this PR exposes a `link_std_dylib` attr to `rust_binary`, `rust_dylib_library` and `rust_test` to allow these targets to optionally bundle themselves with the dynamically-linked stdlib. --------- Co-authored-by: UebelAndre <github@uebelandre.com>
This repository provides rules for building Rust projects with Bazel.
The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/rust.
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.