From 5f8a980f15fa5bb0cdab4599b2ceab11227b32c6 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Wed, 8 Feb 2023 14:47:00 -0800 Subject: [PATCH] Various cleanups --- docs/index.md | 4 +++- proto/repositories.bzl | 3 ++- rust/private/clippy.bzl | 8 +++++-- .../dummy_cc_toolchain/dummy_cc_toolchain.bzl | 3 ++- rust/private/rust.bzl | 3 ++- rust/private/transitions.bzl | 23 ++----------------- rust/toolchain.bzl | 2 +- .../load_arbitrary_tool_test.bzl | 3 ++- wasm_bindgen/BUILD.bazel | 1 + wasm_bindgen/private/BUILD.bazel | 9 ++++++++ wasm_bindgen/private/transitions.bzl | 21 +++++++++++++++++ wasm_bindgen/repositories.bzl | 3 ++- wasm_bindgen/wasm_bindgen.bzl | 7 +++--- 13 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 wasm_bindgen/private/BUILD.bazel create mode 100644 wasm_bindgen/private/transitions.bzl diff --git a/docs/index.md b/docs/index.md index 62532f1b52..78fdd1d5ca 100644 --- a/docs/index.md +++ b/docs/index.md @@ -60,7 +60,9 @@ To build with a particular version of the Rust compiler, pass that version to [` ```python rust_register_toolchains( edition = "2021", - versions = ["1.66.1"], + versions = [ + "1.66.1" + ], ) ``` diff --git a/proto/repositories.bzl b/proto/repositories.bzl index 159161394c..ddb17e132f 100644 --- a/proto/repositories.bzl +++ b/proto/repositories.bzl @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# buildifier: disable=module-docstring +"""Dependencies for Rust proto rules""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//proto/3rdparty/crates:defs.bzl", "crate_repositories") diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl index d0f04ea715..b98aab65d7 100644 --- a/rust/private/clippy.bzl +++ b/rust/private/clippy.bzl @@ -217,8 +217,12 @@ rust_clippy_aspect = aspect( doc = "The desired `--error-format` flags for clippy", default = "//:error_format", ), - "_extra_rustc_flag": attr.label(default = "//:extra_rustc_flag"), - "_extra_rustc_flags": attr.label(default = "//:extra_rustc_flags"), + "_extra_rustc_flag": attr.label( + default = Label("//:extra_rustc_flag"), + ), + "_extra_rustc_flags": attr.label( + default = Label("//:extra_rustc_flags"), + ), "_process_wrapper": attr.label( doc = "A process wrapper for running clippy on all platforms", default = Label("//util/process_wrapper"), diff --git a/rust/private/dummy_cc_toolchain/dummy_cc_toolchain.bzl b/rust/private/dummy_cc_toolchain/dummy_cc_toolchain.bzl index e867564d89..8cbf6170e5 100644 --- a/rust/private/dummy_cc_toolchain/dummy_cc_toolchain.bzl +++ b/rust/private/dummy_cc_toolchain/dummy_cc_toolchain.bzl @@ -1,4 +1,5 @@ -# buildifier: disable=module-docstring +"""Cc toolchain definitions for use on wasm platforms""" + def _dummy_cc_toolchain_impl(_ctx): # The `all_files` attribute is referenced by rustc_compile_action(). return [platform_common.ToolchainInfo(all_files = depset([]))] diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 6f237a9656..42704b5c0b 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# buildifier: disable=module-docstring +"""Rust rule implementations""" + load("@bazel_skylib//lib:paths.bzl", "paths") load("//rust/private:common.bzl", "rust_common") load("//rust/private:rustc.bzl", "rustc_compile_action") diff --git a/rust/private/transitions.bzl b/rust/private/transitions.bzl index 23336f49e1..cbc6a06e30 100644 --- a/rust/private/transitions.bzl +++ b/rust/private/transitions.bzl @@ -1,25 +1,6 @@ -# buildifier: disable=module-docstring -load("//rust:defs.bzl", "rust_common") - -def _wasm_bindgen_transition(_settings, _attr): - """The implementation of the `wasm_bindgen_transition` transition - - Args: - _settings (dict): A dict {String:Object} of all settings declared - in the inputs parameter to `transition()` - _attr (dict): A dict of attributes and values of the rule to which - the transition is attached - - Returns: - dict: A dict of new build settings values to apply - """ - return {"//command_line_option:platforms": str(Label("//rust/platform:wasm"))} +"""Internal transition implementations for core Rust rules""" -wasm_bindgen_transition = transition( - implementation = _wasm_bindgen_transition, - inputs = [], - outputs = ["//command_line_option:platforms"], -) +load("//rust:defs.bzl", "rust_common") def _import_macro_dep_bootstrap_transition(_settings, _attr): """The implementation of the `import_macro_dep_bootstrap_transition` transition. diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl index 0656bddcbe..47bebeacb0 100644 --- a/rust/toolchain.bzl +++ b/rust/toolchain.bzl @@ -729,7 +729,7 @@ rust_toolchain = rule( default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), ), "_pipelined_compilation": attr.label( - default = "@rules_rust//rust/settings:pipelined_compilation", + default = Label("//rust/settings:pipelined_compilation"), ), "_rename_first_party_crates": attr.label( default = Label("//rust/settings:rename_first_party_crates"), diff --git a/test/load_arbitrary_tool/load_arbitrary_tool_test.bzl b/test/load_arbitrary_tool/load_arbitrary_tool_test.bzl index deeba9c292..5d8d91d6e0 100644 --- a/test/load_arbitrary_tool/load_arbitrary_tool_test.bzl +++ b/test/load_arbitrary_tool/load_arbitrary_tool_test.bzl @@ -1,4 +1,5 @@ -# buildifier: disable=module-docstring +"""Tests for `load_arbitrary_tool`""" + load("//rust:repositories.bzl", "load_arbitrary_tool") load("//rust/platform:triple.bzl", "get_host_triple") load("//rust/platform:triple_mappings.bzl", "system_to_binary_ext") diff --git a/wasm_bindgen/BUILD.bazel b/wasm_bindgen/BUILD.bazel index 1c5dadeda5..db37710b9b 100644 --- a/wasm_bindgen/BUILD.bazel +++ b/wasm_bindgen/BUILD.bazel @@ -20,6 +20,7 @@ bzl_library( deps = [ "//rust:bzl_lib", "//wasm_bindgen/3rdparty:bzl_lib", + "//wasm_bindgen/private:bzl_lib", ], ) diff --git a/wasm_bindgen/private/BUILD.bazel b/wasm_bindgen/private/BUILD.bazel new file mode 100644 index 0000000000..f719ebccc3 --- /dev/null +++ b/wasm_bindgen/private/BUILD.bazel @@ -0,0 +1,9 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "bzl_lib", + srcs = [ + "transitions.bzl", + ], + visibility = ["//wasm_bindgen:__pkg__"], +) diff --git a/wasm_bindgen/private/transitions.bzl b/wasm_bindgen/private/transitions.bzl new file mode 100644 index 0000000000..ef84443673 --- /dev/null +++ b/wasm_bindgen/private/transitions.bzl @@ -0,0 +1,21 @@ +"""Transition implementations for wasm-bindgen rust Rules""" + +def _wasm_bindgen_transition(_settings, _attr): + """The implementation of the `wasm_bindgen_transition` transition + + Args: + _settings (dict): A dict {String:Object} of all settings declared + in the inputs parameter to `transition()` + _attr (dict): A dict of attributes and values of the rule to which + the transition is attached + + Returns: + dict: A dict of new build settings values to apply + """ + return {"//command_line_option:platforms": str(Label("//rust/platform:wasm"))} + +wasm_bindgen_transition = transition( + implementation = _wasm_bindgen_transition, + inputs = [], + outputs = ["//command_line_option:platforms"], +) diff --git a/wasm_bindgen/repositories.bzl b/wasm_bindgen/repositories.bzl index e4ea784b2a..9126e3a9ea 100644 --- a/wasm_bindgen/repositories.bzl +++ b/wasm_bindgen/repositories.bzl @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# buildifier: disable=module-docstring +"""Dependency definitions for wasm-bindgen rules""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//wasm_bindgen/3rdparty/crates:defs.bzl", "crate_repositories") diff --git a/wasm_bindgen/wasm_bindgen.bzl b/wasm_bindgen/wasm_bindgen.bzl index 9794313b38..437d88448f 100644 --- a/wasm_bindgen/wasm_bindgen.bzl +++ b/wasm_bindgen/wasm_bindgen.bzl @@ -12,16 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -# buildifier: disable=module-docstring -load("//rust:defs.bzl", "rust_common") +"""Bazel rules for [wasm-bindgen](https://crates.io/crates/wasm-bindgen)""" -# buildifier: disable=bzl-visibility -load("//rust/private:transitions.bzl", "wasm_bindgen_transition") +load("//rust:defs.bzl", "rust_common") load( "//wasm_bindgen:providers.bzl", "DeclarationInfo", "JSModuleInfo", ) +load("//wasm_bindgen/private:transitions.bzl", "wasm_bindgen_transition") _WASM_BINDGEN_DOC = """\ Generates javascript and typescript bindings for a webassembly module using [wasm-bindgen][ws].