This PR splits rust_library into multiple smaller rules:
* rust_library: rust_library will represent a non-transitive library
similar to how cc_library, java_library and others behave. It will
always provide CrateInfo, and depending on it will always mean you can
access the crate from source. Once we support dynamic linking we can
consider producing both rlib and dylib from rust_library, but let's
leave that for another discussion.
* rust_static_library: this will only provide CcInfo and it will
represent an archive of all transitive objects, both Rustc-made and
native.
* rust_shared_library: this will only provide CcInfo and it will
represent an shared library of all transitive objects, both Rustc-made
and native.
* rust_proc_macro: similar to rust_library, but with different
crate_type passed to rustc and different validation logic for its
attributes.
I this this makes sense based on these observations:
* Right now rust_library covers all possible crate types except `bin`.
* rust_library always provides CrateInfo, rust_libraries can depend on
other rust_libraries.
* When the crate type is `cdylib` or `staticlib`, rust_library provides
CcInfo.
* When the crate type is `cdylib` or `staticlib`, Rust code will not be
able to access the crate by `extern crate Foo` in the source; the
behavior will be similar to depending on a CcInfo providing rule.
I believe smaller rules will make them less confusing and
will allow us to have more focused implementations.
This PR is mostly backwards compatible. //rust:rust.bzl#rust_library is
a macro. If the crate_type attribute is present, macro dispatches to
the right new rule. If it's not present, macro will choose the new
rust_library. New rules are added, so people can migrate at
their own pace.
defs.bzl is the bzl file that we now expect people to load. Bazel docs
recommend to store public rules in defs.bzl
(https://docs.bazel.build/versions/master/skylark/deploying.html#repository-content).
This change was first socialized at
https://groups.google.com/g/rules_rust/c/kGMg6haEF44.
Regenerate documentation
Regenerate documentation
Regenerate documentation
Regenerate documentation
Regenerate documentation