Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressed additional Buildifier defects #431

Merged
merged 4 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
workspace(name = "io_bazel_rules_rust")

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("@io_bazel_rules_rust//proto:repositories.bzl", "rust_proto_repositories")

rust_proto_repositories()
Expand Down Expand Up @@ -53,9 +57,9 @@ load("@examples//:examples_deps.bzl", examples_deps = "deps")

examples_deps()

load("@examples//:examples_extra_deps.bzl", examples_extra_deps = "extra_deps")
load("@examples//:examples_transitive_deps.bzl", examples_transitive_deps = "transitive_deps")

examples_extra_deps()
examples_transitive_deps()

# Load all dependencies for docs

Expand All @@ -70,4 +74,8 @@ docs_repositories()

load("@docs//:docs_deps.bzl", docs_deps = "deps")

docs_deps(is_top_level = True)
docs_deps()

load("@docs//:docs_transitive_deps.bzl", docs_transitive_deps = "transitive_deps")

docs_transitive_deps(is_top_level = True)
4 changes: 2 additions & 2 deletions bindgen/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library")
load("@io_bazel_rules_rust//rust:private/legacy_cc_starlark_api_shim.bzl", "get_libs_for_static_executable")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library")

def rust_bindgen_library(
name,
Expand Down Expand Up @@ -141,8 +141,8 @@ def _rust_bindgen_impl(ctx):
)

rust_bindgen = rule(
_rust_bindgen_impl,
doc = "Generates a rust source file from a cc_library and a header.",
implementation = _rust_bindgen_impl,
attrs = {
"header": attr.label(
doc = "The .h file to generate bindings for.",
Expand Down
2 changes: 1 addition & 1 deletion cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "BuildInfo", "DepInfo", "get_cc_toolchain", "get_compilation_mode_opts", "get_linker_and_args")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")

def _cargo_build_script_run(ctx, script):
toolchain = find_toolchain(ctx)
Expand Down
4 changes: 4 additions & 0 deletions docs/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ repositories()
load(":docs_deps.bzl", "deps")

deps()

load(":docs_transitive_deps.bzl", "transitive_deps")

transitive_deps()
30 changes: 3 additions & 27 deletions docs/docs_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
"""Define dependencies for `rules_rust` docs"""

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
load("@io_bazel_rules_rust//proto:repositories.bzl", "rust_proto_repositories")
load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def deps(is_top_level = False):
"""Define dependencies for `rules_rust` docs

Args:
is_top_level (bool, optional): Indicates wheather or not this is being called
from the root WORKSPACE file of `rules_rust`. Defaults to False.
"""
def deps():
"""Define dependencies for `rules_rust` docs"""
rust_repositories()
rust_proto_repositories()
bazel_version(name = "bazel_version")
stardoc_repositories()

# Rules proto does not declare a bzl_library, we stub it there for now.
# TODO: Remove this hack if/when rules_proto adds a bzl_library.
if is_top_level:
maybe(
native.local_repository,
name = "rules_proto",
path = "docs/rules_proto_stub",
)
else:
maybe(
native.local_repository,
name = "rules_proto",
path = "rules_proto_stub",
)
stardoc_repositories()
10 changes: 0 additions & 10 deletions docs/docs_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ def repositories(is_top_level = False):
path = "..",
)

maybe(
http_archive,
name = "bazel_skylib",
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
)

maybe(
http_archive,
name = "io_bazel_stardoc",
Expand Down
31 changes: 31 additions & 0 deletions docs/docs_transitive_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Define transitive dependencies for `rules_rust` docs"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
load("@io_bazel_rules_rust//proto:repositories.bzl", "rust_proto_repositories")

def transitive_deps(is_top_level = False):
"""Define transitive dependencies for `rules_rust` docs

Args:
is_top_level (bool, optional): Indicates wheather or not this is being called
from the root WORKSPACE file of `rules_rust`. Defaults to False.
"""
rust_proto_repositories()

rust_workspace()

# Rules proto does not declare a bzl_library, we stub it there for now.
# TODO: Remove this hack if/when rules_proto adds a bzl_library.
if is_top_level:
maybe(
native.local_repository,
name = "rules_proto",
path = "docs/rules_proto_stub",
)
else:
maybe(
native.local_repository,
name = "rules_proto",
path = "rules_proto_stub",
)
3 changes: 1 addition & 2 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ toolchain(
)
```

Then, either add the label of the toolchain rule to register_toolchains in the WORKSPACE, or pass
it to the "--extra_toolchains" flag for Bazel, and it will be used.
Then, either add the label of the toolchain rule to register_toolchains in the WORKSPACE, or pass it to the "--extra_toolchains" flag for Bazel, and it will be used.

See @io_bazel_rules_rust//proto:BUILD for examples of defining the toolchain.

Expand Down
3 changes: 1 addition & 2 deletions docs/rust_proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ toolchain(
)
```

Then, either add the label of the toolchain rule to register_toolchains in the WORKSPACE, or pass
it to the "--extra_toolchains" flag for Bazel, and it will be used.
Then, either add the label of the toolchain rule to register_toolchains in the WORKSPACE, or pass it to the "--extra_toolchains" flag for Bazel, and it will be used.

See @io_bazel_rules_rust//proto:BUILD for examples of defining the toolchain.

Expand Down
4 changes: 2 additions & 2 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ load(":examples_deps.bzl", "deps")

deps()

load(":examples_extra_deps.bzl", "extra_deps")
load(":examples_transitive_deps.bzl", "transitive_deps")

extra_deps()
transitive_deps()
23 changes: 7 additions & 16 deletions examples/examples_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
"""Define dependencies for `rules_rust` examples"""

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
load("@examples//hello_sys/raze:crates.bzl", "rules_rust_examples_hello_sys_fetch_remote_crates")
load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
load("@io_bazel_rules_rust//bindgen:repositories.bzl", "rust_bindgen_repositories")
load("@io_bazel_rules_rust//proto:repositories.bzl", "rust_proto_repositories")
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories", "rust_repository_set")
load("@io_bazel_rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

def deps():
"""Define dependencies for `rules_rust` examples"""
bazel_skylib_workspace()

rust_repositories()

rust_bindgen_repositories()

rust_wasm_bindgen_repositories()

rust_proto_repositories()

# Example of `rust_repository_set`
rust_repository_set(
name = "fake_toolchain_for_test_of_sha256",
edition = "2018",
Expand All @@ -32,8 +35,6 @@ def deps():
version = "1.46.0",
)

rust_proto_repositories()

node_repositories()

# Dependencies for the @examples//hello_world_wasm example.
Expand All @@ -43,18 +44,8 @@ def deps():
package_lock_json = "@examples//:package-lock.json",
)

rust_bindgen_repositories()

rust_wasm_bindgen_repositories()

rust_workspace()

rules_rust_examples_hello_sys_fetch_remote_crates()

rules_proto_dependencies()

rules_proto_toolchains()

maybe(
http_archive,
name = "libc",
Expand Down
13 changes: 0 additions & 13 deletions examples/examples_extra_deps.bzl

This file was deleted.

10 changes: 0 additions & 10 deletions examples/examples_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ def repositories():
path = "..",
)

maybe(
http_archive,
name = "bazel_skylib",
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
)

maybe(
http_archive,
name = "build_bazel_rules_nodejs",
Expand Down
21 changes: 21 additions & 0 deletions examples/examples_transitive_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Define transitive dependencies for `rules_rust` examples

There are some transitive dependencies of the dependencies of the examples'
dependencies. This file contains the required macros to pull these dependencies
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
"""

load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

def transitive_deps():
"""Define transitive dependencies for `rules_rust` examples"""

rules_proto_dependencies()

rules_proto_toolchains()

rust_workspace()

# Install all Bazel dependencies needed for npm packages that supply Bazel rules
install_bazel_dependencies()
4 changes: 2 additions & 2 deletions proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_proto//proto:defs.bzl", "ProtoInfo")

"""Rust Protobuf Rules

These build rules are used for building [protobufs][protobuf]/[gRPC][grpc] in [Rust][rust] with Bazel.
Expand Down Expand Up @@ -43,6 +41,7 @@ load(
)
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "CrateInfo", "rustc_compile_action")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "determine_output_hash", "find_toolchain")
load("@rules_proto//proto:defs.bzl", "ProtoInfo")

RustProtoInfo = provider(
fields = {
Expand Down Expand Up @@ -158,6 +157,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, grpc,
crate_name,
output_hash,
))

result = rustc_compile_action(
ctx = ctx,
toolchain = find_toolchain(ctx),
Expand Down
12 changes: 1 addition & 11 deletions proto/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//proto/raze:crates.bzl", _crate_deps = "raze_fetch_remote_crates")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//proto/raze:crates.bzl", _crate_deps = "raze_fetch_remote_crates")

# buildifier: disable=unnamed-macro
def rust_proto_repositories():
Expand Down Expand Up @@ -42,16 +42,6 @@ def rust_proto_repositories():
sha256 = "f73c0cf51c32c7aaeaf02669ed03b32d12f2d92e1b05699eb938a75f35a210f4",
)

maybe(
http_archive,
name = "bazel_skylib",
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
)

maybe(
http_archive,
name = "six",
Expand Down
6 changes: 3 additions & 3 deletions proto/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ def _rust_proto_toolchain_impl(ctx):
edition = ctx.attr.edition,
)

# Default dependencies needed to compile protobuf stubs.
PROTO_COMPILE_DEPS = [
"@io_bazel_rules_rust//proto/raze:protobuf",
]
"""Default dependencies needed to compile protobuf stubs."""

# Default dependencies needed to compile gRPC stubs.
GRPC_COMPILE_DEPS = PROTO_COMPILE_DEPS + [
"@io_bazel_rules_rust//proto/raze:grpc",
"@io_bazel_rules_rust//proto/raze:tls_api",
"@io_bazel_rules_rust//proto/raze:tls_api_stub",
]
"""Default dependencies needed to compile gRPC stubs."""

# TODO(damienmg): Once bazelbuild/bazel#6889 is fixed, reintroduce
# proto_compile_deps and grpc_compile_deps and remove them from the
Expand Down Expand Up @@ -186,7 +186,7 @@ toolchain(
)
```

Then, either add the label of the toolchain rule to register_toolchains in the WORKSPACE, or pass
Then, either add the label of the toolchain rule to register_toolchains in the WORKSPACE, or pass \
it to the "--extra_toolchains" flag for Bazel, and it will be used.

See @io_bazel_rules_rust//proto:BUILD for examples of defining the toolchain.
Expand Down
Loading