Skip to content

Commit a364d44

Browse files
Fixes crates_vendor labels in remote mode when used from the root workspace (#1575)
* Fixes crates_vendor labels in remote mode when used from an unnamed workspace * Adds examples for unnamed workspaces using crates_universe Co-authored-by: UebelAndre <[email protected]>
1 parent 1cc37c2 commit a364d44

File tree

146 files changed

+19106
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+19106
-2
lines changed

.bazelci/presubmit.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ crate_universe_vendor_example_targets: &crate_universe_vendor_example_targets
1919
- "//vendor_local_pkgs:crates_vendor"
2020
- "//vendor_remote_manifests:crates_vendor_manifests"
2121
- "//vendor_remote_pkgs:crates_vendor_pkgs"
22+
crate_universe_unnamed_vendor_example_targets: &crate_universe_unnamed_vendor_example_targets
23+
- "//vendor_remote_manifests:crates_vendor_manifests"
24+
- "//vendor_remote_pkgs:crates_vendor_pkgs"
2225
tasks:
2326
ubuntu2004:
2427
build_targets: *default_linux_targets
@@ -302,6 +305,16 @@ tasks:
302305
test_targets:
303306
- "//..."
304307
build_flags: *aspects_flags
308+
crate_universe_unnamed_examples_ubuntu2004:
309+
name: Crate Universe Unnamed Examples
310+
platform: ubuntu2004
311+
working_directory: examples/crate_universe_unnamed
312+
run_targets: *crate_universe_unnamed_vendor_example_targets
313+
build_targets:
314+
- "//..."
315+
test_targets:
316+
- "//..."
317+
build_flags: *aspects_flags
305318
crate_universe_rbe_ubuntu1604:
306319
name: Crate Universe Examples
307320
platform: rbe_ubuntu1604
@@ -315,6 +328,19 @@ tasks:
315328
test_targets:
316329
- "//..."
317330
build_flags: *aspects_flags
331+
crate_universe_unnamed_rbe_ubuntu1604:
332+
name: Crate Universe Unnamed Examples
333+
platform: rbe_ubuntu1604
334+
working_directory: examples/crate_universe_unnamed
335+
shell_commands:
336+
- sed -i 's/^# load("@bazelci_rules/load("@bazelci_rules/' WORKSPACE.bazel
337+
- sed -i 's/^# rbe_preconfig/rbe_preconfig/' WORKSPACE.bazel
338+
run_targets: *crate_universe_unnamed_vendor_example_targets
339+
build_targets:
340+
- "//..."
341+
test_targets:
342+
- "//..."
343+
build_flags: *aspects_flags
318344
crate_universe_examples_macos:
319345
name: Crate Universe Examples
320346
platform: macos
@@ -325,6 +351,16 @@ tasks:
325351
test_targets:
326352
- "//..."
327353
build_flags: *aspects_flags
354+
crate_universe_unnamed_examples_macos:
355+
name: Crate Universe Unnamed Examples
356+
platform: macos
357+
working_directory: examples/crate_universe_unnamed
358+
run_targets: *crate_universe_unnamed_vendor_example_targets
359+
build_targets:
360+
- "//..."
361+
test_targets:
362+
- "//..."
363+
build_flags: *aspects_flags
328364
crate_universe_examples_windows:
329365
name: Crate Universe Examples
330366
platform: windows
@@ -338,6 +374,19 @@ tasks:
338374
- "//..."
339375
test_targets:
340376
- "//..."
377+
crate_universe_unnamed_examples_windows:
378+
name: Crate Universe Unnamed Examples
379+
platform: windows
380+
working_directory: examples/crate_universe_unnamed
381+
batch_commands:
382+
- echo startup --windows_enable_symlinks >> user.bazelrc
383+
- echo build --enable_runfiles >> user.bazelrc # this is not enabled by default on windows and is necessary for the cargo build scripts
384+
run_targets: *crate_universe_unnamed_vendor_example_targets
385+
build_flags: *aspects_flags
386+
build_targets:
387+
- "//..."
388+
test_targets:
389+
- "//..."
341390
cc_common_link_ubuntu2004:
342391
name: Build via cc_common.link
343392
platform: ubuntu2004

crate_universe/private/crates_vendor.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def _write_config_file(ctx):
129129

130130
output_pkg = _get_output_package(ctx)
131131

132+
workspace_name = ctx.workspace_name
133+
if ctx.workspace_name == "__main__":
134+
workspace_name = ""
135+
132136
if ctx.attr.mode == "local":
133137
build_file_base_template = "@{}//{}/{{name}}-{{version}}:BUILD.bazel"
134138
crate_label_template = "//{}/{{name}}-{{version}}:{{target}}".format(
@@ -140,12 +144,12 @@ def _write_config_file(ctx):
140144

141145
rendering_config.update({
142146
"build_file_template": build_file_base_template.format(
143-
ctx.workspace_name,
147+
workspace_name,
144148
output_pkg,
145149
),
146150
"crate_label_template": crate_label_template,
147151
"crates_module_template": "@{}//{}:{{file}}".format(
148-
ctx.workspace_name,
152+
workspace_name,
149153
output_pkg,
150154
),
151155
"vendor_mode": ctx.attr.mode,

examples/.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
android
22
cargo_manifest_dir/external_crate
33
crate_universe
4+
crate_universe_unnamed
45
ios
56
ios_build
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# `.bazelrc` is a Bazel configuration file.
2+
# https://bazel.build/docs/best-practices#bazelrc-file
3+
4+
# Enable rustfmt for all targets in the workspace
5+
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
6+
build:rustfmt --output_groups=+rustfmt_checks
7+
8+
# Enable clippy for all targets in the workspace
9+
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
10+
build:clippy --output_groups=+clippy_checks
11+
12+
# This import should always be last to allow users to override
13+
# settings for local development.
14+
try-import %workspace%/user.bazelrc

examples/crate_universe_unnamed/BUILD.bazel

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Developing crate_universe examples
2+
3+
## Bootstrapping
4+
5+
Crate Universe examples require a bootstrapping process the first time
6+
`rules_rust` is checked out. To setup the examples, run the following
7+
bazel commands:
8+
9+
```shell
10+
bazel run //vendor_remote_manifests:crates_vendor_manifests
11+
bazel run //vendor_remote_pkgs:crates_vendor_pkgs
12+
```
13+
14+
## Repinning/Updating Dependencies
15+
16+
After bootstrapping, Bazel lockfiles can be regenerated by running the following:
17+
18+
```shell
19+
CARGO_BAZEL_REPIN=1 bazel test //...
20+
```
21+
22+
For more information on repinning, see: https://bazelbuild.github.io/rules_rust/crate_universe.html#repinning--updating-dependencies
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Examples
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
local_repository(
2+
name = "rules_rust",
3+
path = "../../",
4+
)
5+
6+
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
7+
8+
rules_rust_dependencies()
9+
10+
rust_register_toolchains(
11+
edition = "2018",
12+
)
13+
14+
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
15+
16+
crate_universe_dependencies(bootstrap = True)
17+
18+
###############################################################################
19+
# V E N D O R R E M O T E M A N I F E S T S
20+
###############################################################################
21+
22+
load(
23+
"//vendor_remote_manifests/crates:crates.bzl",
24+
crates_vendor_manifests_repositories = "crate_repositories",
25+
)
26+
27+
crates_vendor_manifests_repositories()
28+
29+
###############################################################################
30+
# V E N D O R R E M O T E P A C K A G E S
31+
###############################################################################
32+
33+
load(
34+
"//vendor_remote_pkgs/crates:crates.bzl",
35+
crates_vendor_packages_repositories = "crate_repositories",
36+
)
37+
38+
crates_vendor_packages_repositories()
39+
40+
###############################################################################
41+
42+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
43+
44+
# Used for Bazel CI
45+
http_archive(
46+
name = "bazelci_rules",
47+
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
48+
strip_prefix = "bazelci_rules-1.0.0",
49+
url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
50+
)
51+
52+
load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")
53+
54+
# Creates a default toolchain config for RBE.
55+
# Use this as is if you are using the rbe_ubuntu16_04 container,
56+
# otherwise refer to RBE docs.
57+
rbe_preconfig(
58+
name = "buildkite_config",
59+
toolchain = "ubuntu1804-bazel-java11",
60+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
load("@crates_vendor_manifests//:defs.bzl", "aliases", "all_crate_deps")
2+
load("@rules_rust//crate_universe:defs.bzl", "crates_vendor")
3+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
4+
5+
crates_vendor(
6+
name = "crates_vendor_manifests",
7+
manifests = [":Cargo.toml"],
8+
)
9+
10+
rust_library(
11+
name = "cargo_local",
12+
srcs = glob(["**/*.rs"]),
13+
aliases = aliases(),
14+
edition = "2018",
15+
proc_macro_deps = all_crate_deps(proc_macro = True),
16+
deps = all_crate_deps(normal = True),
17+
)
18+
19+
rust_test(
20+
name = "unit_test",
21+
crate = ":cargo_local",
22+
proc_macro_deps = all_crate_deps(proc_macro_dev = True),
23+
deps = all_crate_deps(normal_dev = True),
24+
)

0 commit comments

Comments
 (0)