Skip to content

Commit 85c7d04

Browse files
authored
Moved examples and docs repository definitions into their WORKSPACE files (#896)
1 parent af2f908 commit 85c7d04

12 files changed

+149
-189
lines changed

docs/WORKSPACE.bazel

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
workspace(name = "rules_rust_docs")
22

3-
load(":docs_repositories.bzl", "repositories")
3+
local_repository(
4+
name = "rules_rust",
5+
path = "..",
6+
)
47

5-
repositories()
8+
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
69

7-
load(":docs_deps.bzl", "deps")
10+
rust_repositories(include_rustc_srcs = True)
811

9-
deps()
12+
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
1013

11-
load(":docs_transitive_deps.bzl", "transitive_deps")
14+
rust_proto_repositories()
1215

13-
transitive_deps()
16+
load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")
17+
18+
rust_proto_transitive_repositories()
19+
20+
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")
21+
22+
rust_wasm_bindgen_repositories()
23+
24+
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
25+
26+
node_repositories()
27+
28+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
29+
30+
http_archive(
31+
name = "io_bazel_stardoc",
32+
sha256 = "ff10a8b1503f5606fab5aa5bc9ae267272c023af7789f03caef95b5ab3fe0df2",
33+
strip_prefix = "stardoc-d93ee5347e2d9c225ad315094507e018364d5a67",
34+
urls = [
35+
"https://github.com/bazelbuild/stardoc/archive/d93ee5347e2d9c225ad315094507e018364d5a67.zip",
36+
],
37+
)
38+
39+
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
40+
41+
stardoc_repositories()

docs/docs_deps.bzl

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

docs/docs_repositories.bzl

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

docs/docs_transitive_deps.bzl

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

examples/WORKSPACE.bazel

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,110 @@
11
workspace(name = "examples")
22

3-
load(":examples_repositories.bzl", "repositories")
3+
# Users of `rules_rust` will commonly be unable to load it
4+
# using a `local_repository`. Instead, to setup the rules,
5+
# please see https://bazelbuild.github.io/rules_rust/#setup
6+
local_repository(
7+
name = "rules_rust",
8+
path = "..",
9+
)
10+
11+
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
12+
13+
rust_repositories(include_rustc_srcs = True)
14+
15+
load("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_repositories")
416

5-
repositories()
17+
rust_bindgen_repositories()
618

7-
load(":examples_deps.bzl", "deps")
19+
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
820

9-
deps()
21+
rust_proto_repositories()
1022

11-
load(":examples_transitive_deps.bzl", "transitive_deps")
23+
load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")
1224

13-
transitive_deps()
25+
rust_proto_transitive_repositories()
26+
27+
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")
28+
29+
rust_wasm_bindgen_repositories()
1430

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

33+
###############################################################################
34+
# Workspace examples
35+
###############################################################################
36+
37+
# buildifier: disable=same-origin-load
38+
load("@rules_rust//rust:repositories.bzl", "rust_repository_set")
39+
40+
# `rust_repository_set` is the core repository rule for downloading and defining
41+
# a rust_toolchain. Should there be a need for a customized toolchain, this macro can
42+
# be used to define and register one.
43+
rust_repository_set(
44+
name = "fake_toolchain_for_test_of_sha256",
45+
edition = "2018",
46+
exec_triple = "x86_64-unknown-linux-gnu",
47+
extra_target_triples = [],
48+
rustfmt_version = "1.4.12",
49+
sha256s = {
50+
"rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5",
51+
"rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc",
52+
"rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0",
53+
},
54+
version = "1.46.0",
55+
)
56+
57+
###############################################################################
58+
# Examples dependencies
59+
###############################################################################
60+
61+
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
62+
63+
node_repositories()
64+
65+
http_archive(
66+
name = "rules_foreign_cc",
67+
sha256 = "3c6445404e9e5d17fa0ecdef61be00dd93b20222c11f45e146a98c0a3f67defa",
68+
strip_prefix = "rules_foreign_cc-d54c78ab86b40770ee19f0949db9d74a831ab9f0",
69+
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/d54c78ab86b40770ee19f0949db9d74a831ab9f0.zip",
70+
)
71+
72+
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
73+
74+
rules_foreign_cc_dependencies()
75+
76+
load("//sys:sys_deps.bzl", "sys_deps")
77+
78+
sys_deps()
79+
80+
local_repository(
81+
name = "rules_rust_example_cargo_manifest_dir",
82+
path = "cargo_manifest_dir/external_crate",
83+
)
84+
85+
_LIBC_BUILD_FILE_CONTENT = """\
86+
load("@rules_rust//rust:rust.bzl", "rust_library")
87+
88+
rust_library(
89+
name = "libc",
90+
srcs = glob(["src/**/*.rs"]),
91+
visibility = ["//visibility:public"],
92+
)
93+
"""
94+
95+
http_archive(
96+
name = "libc",
97+
build_file_content = _LIBC_BUILD_FILE_CONTENT,
98+
sha256 = "1ac4c2ac6ed5a8fb9020c166bc63316205f1dc78d4b964ad31f4f21eb73f0c6d",
99+
strip_prefix = "libc-0.2.20",
100+
urls = [
101+
"https://mirror.bazel.build/github.com/rust-lang/libc/archive/0.2.20.zip",
102+
"https://github.com/rust-lang/libc/archive/0.2.20.zip",
103+
],
104+
)
105+
106+
###############################################################################
107+
17108
http_archive(
18109
name = "bazel_toolchains",
19110
sha256 = "179ec02f809e86abf56356d8898c8bd74069f1bd7c56044050c2cd3d79d0e024",

examples/examples_deps.bzl

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

examples/examples_repositories.bzl

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

examples/examples_transitive_deps.bzl

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

examples/sys/BUILD.bazel

Whitespace-only changes.

examples/sys/basic/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ rust_binary(
2020
name = "hello_sys",
2121
srcs = ["src/main.rs"],
2222
edition = "2018",
23+
# Note the `cargo-raze` dependencies here need to have been loaded
24+
# in the WORKSPACE file. See `//sys:sys_deps.bzl` for rmore details.
2325
deps = ["//sys/basic/raze:bzip2"],
2426
)
2527

examples/sys/complex/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ rust_binary(
2020
name = "complex_sys",
2121
srcs = ["src/main.rs"],
2222
edition = "2018",
23+
# Note the `cargo-raze` dependencies here need to have been loaded
24+
# in the WORKSPACE file. See `//sys:sys_deps.bzl` for rmore details.
2325
deps = ["//sys/complex/raze:git2"],
2426
)

examples/sys/sys_deps.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# buildifier: disable=module-docstring
2+
load("//sys/basic/raze:crates.bzl", "rules_rust_examples_basic_sys_fetch_remote_crates")
3+
load("//sys/complex:repositories.bzl", "rules_rust_examples_complex_sys_repositories")
4+
5+
def sys_deps():
6+
"""This macro loads dependencies for the `sys` crate examples
7+
8+
Commonly `*-sys` crates are built on top of some existing library and
9+
will have a number of dependencies. The examples here use
10+
[cargo-raze](https://github.com/google/cargo-raze) to gather these
11+
dependencies and make them avaialble in the workspace.
12+
"""
13+
rules_rust_examples_basic_sys_fetch_remote_crates()
14+
rules_rust_examples_complex_sys_repositories()

0 commit comments

Comments
 (0)