Skip to content

Commit

Permalink
Removed duplicate dependencies of examples in the top level workspace (
Browse files Browse the repository at this point in the history
…#407)

This PR adds `rust_workspace` which is meant to define transitive dependencies as well as cleans up some duplicate files that were in the root of the project but only used by examples.

## Updated documentation
Note the updated documentation in [docs/index.md](https://github.com/UebelAndre/rules_rust/blob/workspace-structure/docs/index.md)

## Added `bazel_skylib` to `rust_repositories`
It appears there are some uses of `bazel_skylib` within these rules but there aren't really any guarantees that that repository is available. This may be my fault with the changes made in #399 to [@io_bazel_rules_rust//rust/platform:platform.bzl](https://github.com/bazelbuild/rules_rust/blob/master/rust/platform/platform.bzl#L3) but I feel the `bazel_skylib` dependency should be conditionally added

## Added `rust_workspace`
I feel this is much nicer on the users's end as it gives them a single place to go to look at dependencies and is nicer on the repo because it means dependencies can more easily updated. I'm not the biggest fan of the name `rust_workspace` so if this was an acceptable concept, I'm happy to take suggestions on what the name should be called.
  • Loading branch information
UebelAndre authored Sep 24, 2020
1 parent fcbb17b commit 5998baf
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 1,083 deletions.
33 changes: 6 additions & 27 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
workspace(name = "io_bazel_rules_rust")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

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",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

new_git_repository(
name = "libc",
build_file = "@io_bazel_rules_rust//:libc.BUILD",
remote = "https://github.com/rust-lang/libc",
tag = "0.2.20",
)

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

rust_proto_repositories()
Expand All @@ -35,8 +12,14 @@ load("@io_bazel_rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_r

rust_wasm_bindgen_repositories()

load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")

rust_workspace()

# --- end stardoc

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_toolchains",
sha256 = "d8c2f20deb2f6143bac792d210db1a4872102d81529fe0ea3476c1696addd7ff",
Expand All @@ -55,10 +38,6 @@ rbe_autoconfig(
name = "buildkite_config",
)

load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")

bazel_version(name = "bazel_version")

# Load all dependencies for examples

local_repository(
Expand Down
33 changes: 13 additions & 20 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,25 @@ To use the Rust rules, add the following to your `WORKSPACE` file to add the ext
```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
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",
],
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()

http_archive(
name = "io_bazel_rules_rust",
sha256 = "b6da34e057a31b8a85e343c732de4af92a762f804fc36b0baa6c001423a70ebc",
strip_prefix = "rules_rust-55f77017a7f5b08e525ebeab6e11d8896a4499d2",
sha256 = "9158524bbbdfded6326d00e76d4fb293efbb07d4e4881416210bac221613432f",
strip_prefix = "rules_rust-7d9e890c58ca00eacf8dd4a2ba991cfe9c3f44e4",
urls = [
# Master branch as of 2019-10-07
"https://github.com/bazelbuild/rules_rust/archive/55f77017a7f5b08e525ebeab6e11d8896a4499d2.tar.gz",
# Master branch as of 2020-09-09
"https://github.com/bazelbuild/rules_rust/archive/7d9e890c58ca00eacf8dd4a2ba991cfe9c3f44e4.tar.gz",
],
)

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

rust_repositories()

load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
bazel_version(name = "bazel_version")
load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")

rust_workspace()
```

The rules are under active development, as such the lastest commit on the master branch should be used. `master` currently requires Bazel >= 0.26.0.

## Rules
Expand Down Expand Up @@ -85,9 +76,11 @@ Currently the most common approach to managing external dependencies is using

## WebAssembly

To build a `rust_binary` for wasm32-unknown-unknown add the `--platforms=//rust/platform:wasm` flag.
To build a `rust_binary` for wasm32-unknown-unknown add the `--platforms=@io_bazel_rules_rust//rust/platform:wasm` flag.

bazel build @examples//hello_world_wasm --platforms=//rust/platform:wasm
```command
bazel build @examples//hello_world_wasm --platforms=@io_bazel_rules_rust//rust/platform:wasm
```

`rust_wasm_bindgen` will automatically transition to the wasm platform and can be used when
building wasm code for the host target.
8 changes: 4 additions & 4 deletions examples/examples_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
load("@examples//hello_sys:workspace.bzl", "remote_deps")
load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
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")
Expand Down Expand Up @@ -37,15 +37,15 @@ def deps():
# Dependencies for the @examples//hello_world_wasm example.
npm_install(
name = "npm",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
package_json = "@examples//:package.json",
package_lock_json = "@examples//:package-lock.json",
)

rust_bindgen_repositories()

rust_wasm_bindgen_repositories()

bazel_version(name = "bazel_version")
rust_workspace()

remote_deps()

Expand Down
2 changes: 1 addition & 1 deletion examples/examples_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def repositories():
maybe(
http_archive,
name = "libc",
build_file = "@//:libc.BUILD",
build_file = "@examples//:libc.BUILD",
sha256 = "1ac4c2ac6ed5a8fb9020c166bc63316205f1dc78d4b964ad31f4f21eb73f0c6d",
strip_prefix = "libc-0.2.20",
urls = [
Expand Down
7 changes: 0 additions & 7 deletions libc.BUILD

This file was deleted.

Loading

0 comments on commit 5998baf

Please sign in to comment.