-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split rust_library and add //rust:defs.bzl
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
- Loading branch information
Showing
10 changed files
with
1,094 additions
and
696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ exports_files([ | |
"known_shas.bzl", | ||
"repositories.bzl", | ||
"rust.bzl", | ||
"defs.bzl", | ||
"toolchain.bzl", | ||
]) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Copyright 2021 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Public entry point to all Rust rules and supported APIs.""" | ||
|
||
load( | ||
"//rust/private:clippy.bzl", | ||
_rust_clippy = "rust_clippy", | ||
_rust_clippy_aspect = "rust_clippy_aspect", | ||
) | ||
load("//rust/private:common.bzl", _rust_common = "rust_common") | ||
load( | ||
"//rust/private:rust.bzl", | ||
_rust_benchmark = "rust_benchmark", | ||
_rust_binary = "rust_binary", | ||
_rust_library = "rust_library", | ||
_rust_proc_macro = "rust_proc_macro", | ||
_rust_shared_library = "rust_shared_library", | ||
_rust_static_library = "rust_static_library", | ||
_rust_test = "rust_test", | ||
_rust_test_binary = "rust_test_binary", | ||
) | ||
load( | ||
"//rust/private:rust_analyzer.bzl", | ||
_rust_analyzer = "rust_analyzer", | ||
_rust_analyzer_aspect = "rust_analyzer_aspect", | ||
) | ||
load( | ||
"//rust/private:rustc.bzl", | ||
_error_format = "error_format", | ||
) | ||
load( | ||
"//rust/private:rustdoc.bzl", | ||
_rust_doc = "rust_doc", | ||
) | ||
load( | ||
"//rust/private:rustdoc_test.bzl", | ||
_rust_doc_test = "rust_doc_test", | ||
) | ||
|
||
rust_library = _rust_library | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_static_library = _rust_static_library | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_shared_library = _rust_shared_library | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_proc_macro = _rust_proc_macro | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_binary = _rust_binary | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_test = _rust_test | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_test_binary = _rust_test_binary | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_benchmark = _rust_benchmark | ||
# See @rules_rust//rust/private:rust.bzl for a complete description. | ||
|
||
rust_doc = _rust_doc | ||
# See @rules_rust//rust/private:rustdoc.bzl for a complete description. | ||
|
||
rust_doc_test = _rust_doc_test | ||
# See @rules_rust//rust/private:rustdoc_test.bzl for a complete description. | ||
|
||
rust_clippy_aspect = _rust_clippy_aspect | ||
# See @rules_rust//rust/private:clippy.bzl for a complete description. | ||
|
||
rust_clippy = _rust_clippy | ||
# See @rules_rust//rust/private:clippy.bzl for a complete description. | ||
|
||
error_format = _error_format | ||
# See @rules_rust//rust/private:rustc.bzl for a complete description. | ||
|
||
rust_common = _rust_common | ||
# See @rules_rust//rust/private:common.bzl for a complete description. | ||
|
||
rust_analyzer_aspect = _rust_analyzer_aspect | ||
# See @rules_rust//rust:private/rust_analyzer.bzl for a complete description. | ||
|
||
rust_analyzer = _rust_analyzer | ||
# See @rules_rust//rust:private/rust_analyzer.bzl for a complete description. |
Oops, something went wrong.