Skip to content

Commit 5998baf

Browse files
authored
Removed duplicate dependencies of examples in the top level workspace (#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.
1 parent fcbb17b commit 5998baf

File tree

9 files changed

+55
-1083
lines changed

9 files changed

+55
-1083
lines changed

WORKSPACE

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
workspace(name = "io_bazel_rules_rust")
22

3-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
4-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5-
6-
http_archive(
7-
name = "bazel_skylib",
8-
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
9-
urls = [
10-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
11-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
12-
],
13-
)
14-
15-
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
16-
17-
bazel_skylib_workspace()
18-
19-
new_git_repository(
20-
name = "libc",
21-
build_file = "@io_bazel_rules_rust//:libc.BUILD",
22-
remote = "https://github.com/rust-lang/libc",
23-
tag = "0.2.20",
24-
)
25-
263
load("@io_bazel_rules_rust//proto:repositories.bzl", "rust_proto_repositories")
274

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

3613
rust_wasm_bindgen_repositories()
3714

15+
load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
16+
17+
rust_workspace()
18+
3819
# --- end stardoc
3920

21+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22+
4023
http_archive(
4124
name = "bazel_toolchains",
4225
sha256 = "d8c2f20deb2f6143bac792d210db1a4872102d81529fe0ea3476c1696addd7ff",
@@ -55,10 +38,6 @@ rbe_autoconfig(
5538
name = "buildkite_config",
5639
)
5740

58-
load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
59-
60-
bazel_version(name = "bazel_version")
61-
6241
# Load all dependencies for examples
6342

6443
local_repository(

docs/index.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,25 @@ To use the Rust rules, add the following to your `WORKSPACE` file to add the ext
1616
```python
1717
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1818

19-
http_archive(
20-
name = "bazel_skylib",
21-
urls = [
22-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
23-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
24-
],
25-
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
26-
)
27-
28-
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
29-
bazel_skylib_workspace()
30-
3119
http_archive(
3220
name = "io_bazel_rules_rust",
33-
sha256 = "b6da34e057a31b8a85e343c732de4af92a762f804fc36b0baa6c001423a70ebc",
34-
strip_prefix = "rules_rust-55f77017a7f5b08e525ebeab6e11d8896a4499d2",
21+
sha256 = "9158524bbbdfded6326d00e76d4fb293efbb07d4e4881416210bac221613432f",
22+
strip_prefix = "rules_rust-7d9e890c58ca00eacf8dd4a2ba991cfe9c3f44e4",
3523
urls = [
36-
# Master branch as of 2019-10-07
37-
"https://github.com/bazelbuild/rules_rust/archive/55f77017a7f5b08e525ebeab6e11d8896a4499d2.tar.gz",
24+
# Master branch as of 2020-09-09
25+
"https://github.com/bazelbuild/rules_rust/archive/7d9e890c58ca00eacf8dd4a2ba991cfe9c3f44e4.tar.gz",
3826
],
3927
)
4028

4129
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
30+
4231
rust_repositories()
4332

44-
load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
45-
bazel_version(name = "bazel_version")
33+
load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
34+
35+
rust_workspace()
4636
```
37+
4738
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.
4839

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

8677
## WebAssembly
8778

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

90-
bazel build @examples//hello_world_wasm --platforms=//rust/platform:wasm
81+
```command
82+
bazel build @examples//hello_world_wasm --platforms=@io_bazel_rules_rust//rust/platform:wasm
83+
```
9184

9285
`rust_wasm_bindgen` will automatically transition to the wasm platform and can be used when
9386
building wasm code for the host target.

examples/examples_deps.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
44
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
55
load("@examples//hello_sys:workspace.bzl", "remote_deps")
6-
load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
6+
load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
77
load("@io_bazel_rules_rust//bindgen:repositories.bzl", "rust_bindgen_repositories")
88
load("@io_bazel_rules_rust//proto:repositories.bzl", "rust_proto_repositories")
99
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories", "rust_repository_set")
@@ -37,15 +37,15 @@ def deps():
3737
# Dependencies for the @examples//hello_world_wasm example.
3838
npm_install(
3939
name = "npm",
40-
package_json = "//:package.json",
41-
package_lock_json = "//:package-lock.json",
40+
package_json = "@examples//:package.json",
41+
package_lock_json = "@examples//:package-lock.json",
4242
)
4343

4444
rust_bindgen_repositories()
4545

4646
rust_wasm_bindgen_repositories()
4747

48-
bazel_version(name = "bazel_version")
48+
rust_workspace()
4949

5050
remote_deps()
5151

examples/examples_repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def repositories():
1414
maybe(
1515
http_archive,
1616
name = "libc",
17-
build_file = "@//:libc.BUILD",
17+
build_file = "@examples//:libc.BUILD",
1818
sha256 = "1ac4c2ac6ed5a8fb9020c166bc63316205f1dc78d4b964ad31f4f21eb73f0c6d",
1919
strip_prefix = "libc-0.2.20",
2020
urls = [

libc.BUILD

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)