Skip to content

Commit 299f4e9

Browse files
committed
Move examples into their own workspaces
This is more clear, as they don't need to round-trip via two .bzl files, so the examples are self-contained. However, we'll need to work out how to make them build on CI.
1 parent 3a00856 commit 299f4e9

File tree

14 files changed

+178
-110
lines changed

14 files changed

+178
-110
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
docs
22
examples
3+
examples/crate_universe
34
examples/cargo_manifest_dir/external_crate

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# bazel
77
/bazel-*
88
/examples/bazel-*
9-
/examples/*/bazel-*
9+
/examples/crate_universe/*/bazel-*
1010
/docs/bazel-*
1111

1212
# rustfmt

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ examples_repositories()
6363

6464
load("@examples//:examples_deps.bzl", examples_deps = "deps")
6565

66-
examples_deps(is_top_level = True)
66+
examples_deps()
6767

6868
load("@examples//:examples_transitive_deps.bzl", examples_transitive_deps = "transitive_deps")
6969

examples/crate_universe/basic/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ load(
22
"@rules_rust//rust:rust.bzl",
33
"rust_binary",
44
)
5-
load("@crate_universe_basic_rust_deps//:defs.bzl", "crate")
5+
load("@rust_deps//:defs.bzl", "crate")
66

77
rust_binary(
88
name = "basic",
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local_repository(
2+
name = "rules_rust",
3+
path = "../../..",
4+
)
5+
6+
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
7+
8+
rust_repositories()
9+
10+
load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")
11+
12+
crate_universe_deps()
13+
14+
load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")
15+
16+
crate_universe(
17+
name = "rust_deps",
18+
packages = [
19+
crate.spec(
20+
name = "lazy_static",
21+
semver = "=1.4",
22+
),
23+
],
24+
supported_targets = [
25+
"x86_64-apple-darwin",
26+
"x86_64-unknown-linux-gnu",
27+
],
28+
)
29+
30+
load("@rust_deps//:defs.bzl", "pinned_rust_install")
31+
32+
pinned_rust_install()

examples/crate_universe/has_aliased_deps/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ load(
22
"@rules_rust//rust:rust.bzl",
33
"rust_binary",
44
)
5-
load("@crate_universe_has_aliased_deps_rust_deps//:defs.bzl", "crate")
5+
load("@rust_deps//:defs.bzl", "crate")
66

77
rust_binary(
88
name = "has_aliased_deps",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
local_repository(
2+
name = "rules_rust",
3+
path = "../../..",
4+
)
5+
6+
local_repository(
7+
name = "examples",
8+
path = "../../../examples",
9+
)
10+
11+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
12+
13+
http_archive(
14+
name = "openssl",
15+
strip_prefix = "openssl-OpenSSL_1_1_1d",
16+
urls = ["https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz"],
17+
sha256 = "23011a5cc78e53d0dc98dfa608c51e72bcd350aa57df74c5d5574ba4ffb62e74",
18+
build_file = "@examples//third_party/openssl:BUILD.openssl.bazel",
19+
)
20+
21+
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
22+
23+
rust_repositories()
24+
25+
load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")
26+
27+
crate_universe_deps()
28+
29+
load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")
30+
31+
crate_universe(
32+
name = "rust_deps",
33+
cargo_toml_files = ["//:Cargo.toml"],
34+
overrides = {
35+
"openssl-sys": crate.override(
36+
extra_build_script_env_vars = {
37+
"OPENSSL_DIR": "../openssl/openssl",
38+
},
39+
extra_bazel_deps = {
40+
"cfg(all())": ["@openssl//:openssl"],
41+
},
42+
extra_build_script_bazel_data_deps = {
43+
"cfg(all())": ["@openssl//:openssl"],
44+
},
45+
),
46+
},
47+
supported_targets = [
48+
"x86_64-apple-darwin",
49+
"x86_64-unknown-linux-gnu",
50+
],
51+
)
52+
53+
load("@rust_deps//:defs.bzl", "pinned_rust_install")
54+
55+
pinned_rust_install()

examples/crate_universe/uses_proc_macro/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load(
33
"rust_binary",
44
)
55

6-
load("@crate_universe_uses_proc_macro_rust_deps//:defs.bzl", "crate")
6+
load("@rust_deps//:defs.bzl", "crate")
77

88
rust_binary(
99
name = "uses_proc_macro",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local_repository(
2+
name = "rules_rust",
3+
path = "../../..",
4+
)
5+
6+
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
7+
8+
rust_repositories()
9+
10+
load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")
11+
12+
crate_universe_deps()
13+
14+
load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")
15+
16+
crate_universe(
17+
name = "rust_deps",
18+
cargo_toml_files = ["//:Cargo.toml"],
19+
supported_targets = [
20+
"x86_64-apple-darwin",
21+
"x86_64-unknown-linux-gnu",
22+
],
23+
)
24+
25+
load("@rust_deps//:defs.bzl", "pinned_rust_install")
26+
27+
pinned_rust_install()

examples/crate_universe/uses_sys_crate/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ load(
44
"@rules_rust//rust:rust.bzl",
55
"rust_binary",
66
)
7-
load("@crate_universe_uses_sys_crate_rust_deps//:defs.bzl", "crate")
7+
load("@rust_deps//:defs.bzl", "crate")
88

99
rust_binary(
1010
name = "uses_sys_crate",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local_repository(
2+
name = "rules_rust",
3+
path = "../../..",
4+
)
5+
6+
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
7+
8+
rust_repositories()
9+
10+
load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")
11+
12+
crate_universe_deps()
13+
14+
load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")
15+
16+
crate_universe(
17+
name = "rust_deps",
18+
cargo_toml_files = ["//:Cargo.toml"],
19+
lockfile = "//:lockfile.lock",
20+
packages = [
21+
crate.spec(
22+
name = "libc",
23+
semver = "=0.2.76",
24+
),
25+
],
26+
supported_targets = [
27+
"x86_64-apple-darwin",
28+
"x86_64-unknown-linux-gnu",
29+
],
30+
)
31+
32+
load("@rust_deps//:defs.bzl", "pinned_rust_install")
33+
34+
pinned_rust_install()

examples/crate_universe/uses_sys_crate/lockfile.lock

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# rules_rust crate_universe file format 1
2-
# config hash d555ad6fce4572c24cb874f784ca32c0b4c5c6b6655c759f6b1381c0ef72667a
2+
# config hash 6194c33fc29701bfce95fa6d31095bf1268a7ae6aab060692153d2e9fcd34373
33

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

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

88
def pinned_rust_install():
99
http_archive(
10-
name = "crate_universe_uses_sys_crate_rust_deps__bzip2__0_3_3",
10+
name = "rust_deps__bzip2__0_3_3",
1111
# TODO: Allow configuring where rust_library comes from
1212
build_file_content = """# buildifier: disable=load
1313
load(
@@ -35,8 +35,8 @@ rust_library(
3535
name = "bzip2",
3636
crate_type = "lib",
3737
deps = [
38-
"@crate_universe_uses_sys_crate_rust_deps__bzip2_sys__0_1_10_1_0_8//:bzip2_sys",
39-
"@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc",
38+
"@rust_deps__bzip2_sys__0_1_10_1_0_8//:bzip2_sys",
39+
"@rust_deps__libc__0_2_76//:libc",
4040
],
4141
srcs = glob(["**/*.rs"]),
4242
crate_root = "src/lib.rs",
@@ -78,7 +78,7 @@ rust_library(
7878
)
7979

8080
http_archive(
81-
name = "crate_universe_uses_sys_crate_rust_deps__bzip2_sys__0_1_10_1_0_8",
81+
name = "rust_deps__bzip2_sys__0_1_10_1_0_8",
8282
# TODO: Allow configuring where rust_library comes from
8383
build_file_content = """# buildifier: disable=load
8484
load(
@@ -113,8 +113,8 @@ cargo_build_script(
113113
crate_root = "build.rs",
114114
edition = "2015",
115115
deps = [
116-
"@crate_universe_uses_sys_crate_rust_deps__cc__1_0_66//:cc",
117-
"@crate_universe_uses_sys_crate_rust_deps__pkg_config__0_3_19//:pkg_config",
116+
"@rust_deps__cc__1_0_67//:cc",
117+
"@rust_deps__pkg_config__0_3_19//:pkg_config",
118118
],
119119
rustc_flags = [
120120
"--cap-lints=allow",
@@ -151,7 +151,7 @@ rust_library(
151151
crate_type = "lib",
152152
deps = [
153153
":bzip2_sys_build_script",
154-
"@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc",
154+
"@rust_deps__libc__0_2_76//:libc",
155155
],
156156
srcs = glob(["**/*.rs"]),
157157
crate_root = "lib.rs",
@@ -192,7 +192,7 @@ rust_library(
192192
)
193193

194194
http_archive(
195-
name = "crate_universe_uses_sys_crate_rust_deps__cc__1_0_66",
195+
name = "rust_deps__cc__1_0_67",
196196
# TODO: Allow configuring where rust_library comes from
197197
build_file_content = """# buildifier: disable=load
198198
load(
@@ -242,7 +242,7 @@ rust_binary(
242242
"WORKSPACE.bazel",
243243
"WORKSPACE",
244244
]),
245-
version = "1.0.66",
245+
version = "1.0.67",
246246
tags = [
247247
"cargo-raze",
248248
"manual",
@@ -280,7 +280,7 @@ rust_library(
280280
"WORKSPACE.bazel",
281281
"WORKSPACE",
282282
]),
283-
version = "1.0.66",
283+
version = "1.0.67",
284284
tags = [
285285
"cargo-raze",
286286
"manual",
@@ -298,14 +298,14 @@ rust_library(
298298
# Unsupported target "cxxflags" with type "test" omitted
299299
# Unsupported target "test" with type "test" omitted
300300
""",
301-
sha256 = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48",
302-
strip_prefix = "cc-1.0.66",
301+
sha256 = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd",
302+
strip_prefix = "cc-1.0.67",
303303
type = "tar.gz",
304-
url = "https://crates.io/api/v1/crates/cc/1.0.66/download",
304+
url = "https://crates.io/api/v1/crates/cc/1.0.67/download",
305305
)
306306

307307
http_archive(
308-
name = "crate_universe_uses_sys_crate_rust_deps__libc__0_2_76",
308+
name = "rust_deps__libc__0_2_76",
309309
# TODO: Allow configuring where rust_library comes from
310310
build_file_content = """# buildifier: disable=load
311311
load(
@@ -420,7 +420,7 @@ rust_library(
420420
)
421421

422422
http_archive(
423-
name = "crate_universe_uses_sys_crate_rust_deps__pkg_config__0_3_19",
423+
name = "rust_deps__pkg_config__0_3_19",
424424
# TODO: Allow configuring where rust_library comes from
425425
build_file_content = """# buildifier: disable=load
426426
load(
@@ -490,8 +490,8 @@ rust_library(
490490

491491

492492
CRATE_TARGET_NAMES = {
493-
"bzip2": "@crate_universe_uses_sys_crate_rust_deps__bzip2__0_3_3//:bzip2",
494-
"libc": "@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc",
493+
"bzip2": "@rust_deps__bzip2__0_3_3//:bzip2",
494+
"libc": "@rust_deps__libc__0_2_76//:libc",
495495
}
496496

497497
def crate(crate_name):
@@ -520,25 +520,25 @@ def all_proc_macro_deps():
520520

521521
def crates_from(label):
522522
mapping = {
523-
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [crate("bzip2")],
523+
"//:Cargo.toml": [crate("bzip2")],
524524
}
525525
return mapping[_absolutify(label)]
526526

527527
def dev_crates_from(label):
528528
mapping = {
529-
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [],
529+
"//:Cargo.toml": [],
530530
}
531531
return mapping[_absolutify(label)]
532532

533533
def build_crates_from(label):
534534
mapping = {
535-
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [],
535+
"//:Cargo.toml": [],
536536
}
537537
return mapping[_absolutify(label)]
538538

539539
def proc_macro_crates_from(label):
540540
mapping = {
541-
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [],
541+
"//:Cargo.toml": [],
542542
}
543543
return mapping[_absolutify(label)]
544544

0 commit comments

Comments
 (0)