Add //rust/private/BUILD (therefore create a package there) (#569)
This PR achieves the following:
* buildifier bzl-visibility check was not detecting violations as it assumes private package, not just a directory
* adds //rust:common.bzl file where all the publicly available and supported API for writing custom rules interacting with Rust will reside
* the private package now sets the stability expectations, and it forces us to think about API layering and abstractions.
This turned out to be much bigger PR than expected :(
diff --git a/rust/BUILD b/rust/BUILD
index 49dd028..d38e41a 100644
--- a/rust/BUILD
+++ b/rust/BUILD
@@ -18,5 +18,6 @@
srcs = glob(["**/*.bzl"]),
deps = [
"//rust/platform:rules",
+ "//rust/private:rules",
],
)
diff --git a/rust/common.bzl b/rust/common.bzl
new file mode 100644
index 0000000..d23e513
--- /dev/null
+++ b/rust/common.bzl
@@ -0,0 +1,32 @@
+# Copyright 2015 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.
+
+"""Module with Rust definitions required to write custom Rust rules."""
+
+CrateInfo = provider(
+ doc = "A provider containing general Crate information.",
+ fields = {
+ "aliases": "Dict[Label, String]: Renamed and aliased crates",
+ "deps": "List[Provider]: This crate's (rust or cc) dependencies' providers.",
+ "edition": "str: The edition of this crate.",
+ "is_test": "bool: If the crate is being compiled in a test context",
+ "name": "str: The name of this crate.",
+ "output": "File: The output File that will be produced, depends on crate type.",
+ "proc_macro_deps": "List[CrateInfo]: This crate's rust proc_macro dependencies' providers.",
+ "root": "File: The source File entrypoint to this crate, eg. lib.rs",
+ "rustc_env": "Dict[String, String]: Additional `\"key\": \"value\"` environment variables to set for rustc.",
+ "srcs": "List[File]: All source Files that are part of the crate.",
+ "type": "str: The type of this crate. eg. lib or bin",
+ },
+)
diff --git a/rust/platform/BUILD b/rust/platform/BUILD
index c0e5204..5dfb945 100644
--- a/rust/platform/BUILD
+++ b/rust/platform/BUILD
@@ -1,5 +1,5 @@
-load(":platform.bzl", "declare_config_settings")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+load(":platform.bzl", "declare_config_settings")
package(default_visibility = ["//visibility:public"])
@@ -15,5 +15,5 @@
bzl_library(
name = "rules",
srcs = glob(["**/*.bzl"]),
- visibility = ["//rust:__pkg__"],
+ visibility = ["//rust:__subpackages__"],
)
diff --git a/rust/private/BUILD b/rust/private/BUILD
new file mode 100644
index 0000000..119af07
--- /dev/null
+++ b/rust/private/BUILD
@@ -0,0 +1,12 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
+bzl_library(
+ name = "rules",
+ srcs = glob(
+ ["**/*.bzl"],
+ ),
+ visibility = ["//rust:__subpackages__"],
+ deps = [
+ "//rust/platform:rules",
+ ],
+)
diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl
index 3b96b79..4299015 100644
--- a/rust/private/clippy.bzl
+++ b/rust/private/clippy.bzl
@@ -13,19 +13,19 @@
# limitations under the License.
# buildifier: disable=module-docstring
+load("//rust:common.bzl", "CrateInfo")
load(
- "//rust:private/rust.bzl",
+ "//rust/private:rust.bzl",
"crate_root_src",
)
load(
- "//rust:private/rustc.bzl",
- "CrateInfo",
+ "//rust/private:rustc.bzl",
"collect_deps",
"collect_inputs",
"construct_arguments",
"get_cc_toolchain",
)
-load("//rust:private/utils.bzl", "determine_output_hash", "find_toolchain")
+load("//rust/private:utils.bzl", "determine_output_hash", "find_toolchain")
_rust_extensions = [
"rs",
diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl
index e3da225..28beebb 100644
--- a/rust/private/rust.bzl
+++ b/rust/private/rust.bzl
@@ -13,8 +13,9 @@
# limitations under the License.
# buildifier: disable=module-docstring
-load("//rust:private/rustc.bzl", "CrateInfo", "rustc_compile_action")
-load("//rust:private/utils.bzl", "determine_output_hash", "find_toolchain")
+load("//rust:common.bzl", "CrateInfo")
+load("//rust/private:rustc.bzl", "rustc_compile_action")
+load("//rust/private:utils.bzl", "determine_output_hash", "find_toolchain")
# TODO(marco): Separate each rule into its own file.
@@ -355,7 +356,7 @@
"""
return "\n".join([line.strip() for line in doc_string.splitlines()])
-_rust_common_attrs = {
+_common_attrs = {
"aliases": attr.label_keyed_string_dict(
doc = _tidy("""
Remap crates to a new name or moniker for linkage to this target
@@ -501,7 +502,7 @@
rust_library = rule(
implementation = _rust_library_impl,
- attrs = dict(_rust_common_attrs.items() +
+ attrs = dict(_common_attrs.items() +
_rust_library_attrs.items()),
fragments = ["cpp"],
host_fragments = ["cpp"],
@@ -591,7 +592,7 @@
rust_binary = rule(
implementation = _rust_binary_impl,
- attrs = dict(_rust_common_attrs.items() + _rust_binary_attrs.items()),
+ attrs = dict(_common_attrs.items() + _rust_binary_attrs.items()),
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
@@ -687,7 +688,7 @@
rust_test = rule(
implementation = _rust_test_impl,
- attrs = dict(_rust_common_attrs.items() +
+ attrs = dict(_common_attrs.items() +
_rust_test_attrs.items()),
executable = True,
fragments = ["cpp"],
@@ -836,7 +837,7 @@
rust_test_binary = rule(
implementation = _rust_test_impl,
- attrs = dict(_rust_common_attrs.items() +
+ attrs = dict(_common_attrs.items() +
_rust_test_attrs.items()),
executable = True,
fragments = ["cpp"],
@@ -860,7 +861,7 @@
rust_benchmark = rule(
implementation = _rust_benchmark_impl,
- attrs = _rust_common_attrs,
+ attrs = _common_attrs,
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
index b95a8b7..65754df 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
@@ -18,8 +18,9 @@
"CPP_LINK_EXECUTABLE_ACTION_NAME",
)
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
+load("//rust:common.bzl", "CrateInfo")
load(
- "//rust:private/utils.bzl",
+ "//rust/private:utils.bzl",
"expand_locations",
"get_lib_name",
"get_libs_for_static_executable",
@@ -27,23 +28,6 @@
"rule_attrs",
)
-CrateInfo = provider(
- doc = "A provider containing general Crate information.",
- fields = {
- "aliases": "Dict[Label, String]: Renamed and aliased crates",
- "deps": "List[Provider]: This crate's (rust or cc) dependencies' providers.",
- "edition": "str: The edition of this crate.",
- "is_test": "bool: If the crate is being compiled in a test context",
- "name": "str: The name of this crate.",
- "output": "File: The output File that will be produced, depends on crate type.",
- "proc_macro_deps": "List[CrateInfo]: This crate's rust proc_macro dependencies' providers.",
- "root": "File: The source File entrypoint to this crate, eg. lib.rs",
- "rustc_env": "Dict[String, String]: Additional `\"key\": \"value\"` environment variables to set for rustc.",
- "srcs": "List[File]: All source Files that are part of the crate.",
- "type": "str: The type of this crate. eg. lib or bin",
- },
-)
-
BuildInfo = provider(
doc = "A provider containing `rustc` build settings for a given Crate.",
fields = {
diff --git a/rust/private/rustdoc.bzl b/rust/private/rustdoc.bzl
index e19af23..528d0d2 100644
--- a/rust/private/rustdoc.bzl
+++ b/rust/private/rustdoc.bzl
@@ -13,8 +13,9 @@
# limitations under the License.
# buildifier: disable=module-docstring
-load("//rust:private/rustc.bzl", "CrateInfo", "DepInfo", "add_crate_link_flags", "add_edition_flags")
-load("//rust:private/utils.bzl", "find_toolchain")
+load("//rust:common.bzl", "CrateInfo")
+load("//rust/private:rustc.bzl", "DepInfo", "add_crate_link_flags", "add_edition_flags")
+load("//rust/private:utils.bzl", "find_toolchain")
_rust_doc_doc = """Generates code documentation.
diff --git a/rust/private/rustdoc_test.bzl b/rust/private/rustdoc_test.bzl
index 404013c..37546c9 100644
--- a/rust/private/rustdoc_test.bzl
+++ b/rust/private/rustdoc_test.bzl
@@ -13,8 +13,9 @@
# limitations under the License.
# buildifier: disable=module-docstring
-load("//rust:private/rustc.bzl", "CrateInfo", "DepInfo")
-load("//rust:private/utils.bzl", "find_toolchain", "get_lib_name")
+load("//rust:common.bzl", "CrateInfo")
+load("//rust/private:rustc.bzl", "DepInfo")
+load("//rust/private:utils.bzl", "find_toolchain", "get_lib_name")
def _rust_doc_test_impl(ctx):
"""The implementation for the `rust_doc_test` rule
diff --git a/rust/rust.bzl b/rust/rust.bzl
index 955f596..99277cc 100644
--- a/rust/rust.bzl
+++ b/rust/rust.bzl
@@ -14,12 +14,12 @@
# buildifier: disable=module-docstring
load(
- "//rust:private/clippy.bzl",
+ "//rust/private:clippy.bzl",
_rust_clippy = "rust_clippy",
_rust_clippy_aspect = "rust_clippy_aspect",
)
load(
- "//rust:private/rust.bzl",
+ "//rust/private:rust.bzl",
_rust_benchmark = "rust_benchmark",
_rust_binary = "rust_binary",
_rust_library = "rust_library",
@@ -27,37 +27,37 @@
_rust_test_binary = "rust_test_binary",
)
load(
- "//rust:private/rustdoc.bzl",
+ "//rust/private:rustdoc.bzl",
_rust_doc = "rust_doc",
)
load(
- "//rust:private/rustdoc_test.bzl",
+ "//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.
+# 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.
+# 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.
+# 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.
+# 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.
+# 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.
+# 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.
+# 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.
+# 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.
+# See @rules_rust//rust/private:clippy.bzl for a complete description.