Skip to content

Commit ba6e34d

Browse files
authored
Merge branch 'main' into process-wrapper-rust
2 parents 029f34e + e5fefdc commit ba6e34d

File tree

673 files changed

+119764
-7695
lines changed

Some content is hidden

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

673 files changed

+119764
-7695
lines changed

.bazelci/presubmit.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ default_windows_targets: &default_windows_targets
1515
- "-//test/proto/..."
1616
- "-//tools/rust_analyzer/..."
1717
- "-//test/rustfmt/..."
18+
crate_universe_vendor_example_targets: &crate_universe_vendor_example_targets
19+
- "//vendor_local_manifests:crates_vendor"
20+
- "//vendor_local_pkgs:crates_vendor"
21+
- "//vendor_remote_manifests:crates_vendor_manifests"
22+
- "//vendor_remote_pkgs:crates_vendor_pkgs"
1823
tasks:
1924
ubuntu2004:
2025
build_targets: *default_linux_targets
@@ -249,9 +254,8 @@ tasks:
249254
crate_universe_examples_ubuntu2004:
250255
name: Crate Universe Examples
251256
platform: ubuntu2004
252-
environment:
253-
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
254257
working_directory: examples/crate_universe
258+
run_targets: *crate_universe_vendor_example_targets
255259
build_targets:
256260
- "//..."
257261
test_targets:
@@ -260,12 +264,11 @@ tasks:
260264
crate_universe_rbe_ubuntu1604:
261265
name: Crate Universe Examples
262266
platform: rbe_ubuntu1604
263-
environment:
264-
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
265267
working_directory: examples/crate_universe
266268
shell_commands:
267269
- sed -i 's/^# load("@bazelci_rules/load("@bazelci_rules/' WORKSPACE.bazel
268270
- sed -i 's/^# rbe_preconfig/rbe_preconfig/' WORKSPACE.bazel
271+
run_targets: *crate_universe_vendor_example_targets
269272
build_targets:
270273
- "//..."
271274
test_targets:
@@ -274,9 +277,8 @@ tasks:
274277
crate_universe_examples_macos:
275278
name: Crate Universe Examples
276279
platform: macos
277-
environment:
278-
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
279280
working_directory: examples/crate_universe
281+
run_targets: *crate_universe_vendor_example_targets
280282
build_targets:
281283
- "//..."
282284
test_targets:
@@ -285,22 +287,16 @@ tasks:
285287
crate_universe_examples_windows:
286288
name: Crate Universe Examples
287289
platform: windows
288-
environment:
289-
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
290290
working_directory: examples/crate_universe
291-
build_flags:
292-
- "--enable_runfiles" # this is not enabled by default on windows and is necessary for the cargo build scripts
293-
- "--config=rustfmt"
294-
- "--config=clippy"
295-
crate_universe_windows_targets: &crate_universe_windows_targets
291+
batch_commands:
292+
- echo startup --windows_enable_symlinks >> user.bazelrc
293+
- echo build --enable_runfiles >> user.bazelrc # this is not enabled by default on windows and is necessary for the cargo build scripts
294+
run_targets: *crate_universe_vendor_example_targets
295+
build_flags: *aspects_flags
296+
build_targets:
297+
- "//..."
298+
test_targets:
296299
- "//..."
297-
# TODO: There are windows specific build issues in the generated
298-
# dependencies. This should be fixed and all testing enabled.
299-
- "-//uses_proc_macro/..."
300-
- "-//uses_sys_crate/..."
301-
build_targets: *crate_universe_windows_targets
302-
# TODO: fix test targets in `crate_universe_windows_targets`
303-
test_targets: *crate_universe_windows_targets
304300
buildifier:
305301
version: latest
306302
warnings: "all"

.bazelrc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# `.bazelrc` is a Bazel configuration file.
2-
# https://docs.bazel.build/versions/master/best-practices.html#using-the-bazelrc-file
2+
# https://bazel.build/docs/best-practices#bazelrc-file
33

44
# Enable rustfmt for all targets in the workspace
55
build:rustfmt --aspects=//rust:defs.bzl%rustfmt_aspect
@@ -9,5 +9,9 @@ build:rustfmt --output_groups=+rustfmt_checks
99
build:clippy --aspects=//rust:defs.bzl%rust_clippy_aspect
1010
build:clippy --output_groups=+clippy_checks
1111

12-
# https://bazel.googlesource.com/bazel/+/master/site/docs/windows.md#enable-symlink-support
13-
startup --windows_enable_symlinks
12+
# https://bazel.build/docs/windows#symlink
13+
startup --windows_enable_symlinks
14+
15+
# This import should always be last to allow users to override
16+
# settings for local development.
17+
try-import %workspace%/user.bazelrc

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/examples/bazel-*
99
/examples/crate_universe/*/bazel-*
1010
/docs/bazel-*
11+
user.bazelrc
1112

1213
# rustfmt
1314
*.rs.bk

WORKSPACE.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ rules_rust_dependencies()
66

77
rust_register_toolchains(include_rustc_srcs = True)
88

9+
load("@rules_rust//crate_universe:crates.bzl", "crate_deps_repository")
10+
11+
crate_deps_repository(bootstrap = True)
12+
913
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
1014

1115
rust_proto_repositories()

cargo/cargo_bootstrap.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ exports_files([
116116
"{binary}"
117117
])
118118
119+
alias(
120+
name = "binary",
121+
actual = "{binary}",
122+
)
123+
119124
rust_binary(
120125
name = "install",
121126
rustc_env = {{

cargo/cargo_build_script.bzl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ load("//rust:defs.bzl", "rust_binary", "rust_common")
77
load("//rust/private:rustc.bzl", "BuildInfo", "get_compilation_mode_opts", "get_linker_and_args")
88

99
# buildifier: disable=bzl-visibility
10-
load("//rust/private:utils.bzl", "expand_dict_value_locations", "find_cc_toolchain", "find_toolchain", "name_to_crate_name")
10+
load("//rust/private:utils.bzl", "dedent", "expand_dict_value_locations", "find_cc_toolchain", "find_toolchain", "name_to_crate_name")
1111

1212
def get_cc_compile_env(cc_toolchain, feature_configuration):
1313
"""Gather cc environment variables from the given `cc_toolchain`
@@ -56,11 +56,7 @@ def _build_script_impl(ctx):
5656

5757
pkg_name = _name_to_pkg_name(ctx.label.name)
5858

59-
toolchain_tools = [
60-
# Needed for rustc to function.
61-
toolchain.rustc_lib,
62-
toolchain.rust_std,
63-
]
59+
toolchain_tools = [toolchain.all_files]
6460

6561
cc_toolchain = find_cpp_toolchain(ctx)
6662

@@ -121,6 +117,13 @@ def _build_script_impl(ctx):
121117
if cc_toolchain.sysroot:
122118
env["SYSROOT"] = cc_toolchain.sysroot
123119

120+
# Inform build scripts of rustc flags
121+
# https://github.com/rust-lang/cargo/issues/9600
122+
env["CARGO_ENCODED_RUSTFLAGS"] = "\\x1f".join([
123+
# Allow build scripts to locate the generated sysroot
124+
"--sysroot=${{pwd}}/{}".format(toolchain.sysroot),
125+
] + ctx.attr.rustc_flags)
126+
124127
for f in ctx.attr.crate_features:
125128
env["CARGO_FEATURE_" + f.upper().replace("-", "_")] = "1"
126129

@@ -136,7 +139,6 @@ def _build_script_impl(ctx):
136139
direct = [
137140
script,
138141
ctx.executable._cargo_build_script_runner,
139-
toolchain.rustc,
140142
] + ctx.files.data + ctx.files.tools + ([toolchain.target_json] if toolchain.target_json else []),
141143
transitive = toolchain_tools,
142144
)
@@ -217,6 +219,16 @@ _build_script_run = rule(
217219
"links": attr.string(
218220
doc = "The name of the native library this crate links against.",
219221
),
222+
"rustc_flags": attr.string_list(
223+
doc = dedent("""\
224+
List of compiler flags passed to `rustc`.
225+
226+
These strings are subject to Make variable expansion for predefined
227+
source/output path variables like `$location`, `$execpath`, and
228+
`$rootpath`. This expansion is useful if you wish to pass a generated
229+
file of arguments to rustc: `@$(location //package:target)`.
230+
"""),
231+
),
220232
# The source of truth will be the `cargo_build_script` macro until stardoc
221233
# implements documentation inheritence. See https://github.com/bazelbuild/stardoc/issues/27
222234
"script": attr.label(
@@ -262,6 +274,7 @@ def cargo_build_script(
262274
tools = [],
263275
links = None,
264276
rustc_env = {},
277+
rustc_flags = [],
265278
visibility = None,
266279
tags = None,
267280
**kwargs):
@@ -333,6 +346,7 @@ def cargo_build_script(
333346
tools (list, optional): Tools (executables) needed by the build script.
334347
links (str, optional): Name of the native library this crate links against.
335348
rustc_env (dict, optional): Environment variables to set in rustc when compiling the build script.
349+
rustc_flags (list, optional): List of compiler flags passed to `rustc`.
336350
visibility (list of label, optional): Visibility to apply to the generated build script output.
337351
tags: (list of str, optional): Tags to apply to the generated build script output.
338352
**kwargs: Forwards to the underlying `rust_binary` rule.
@@ -357,6 +371,7 @@ def cargo_build_script(
357371
deps = deps,
358372
data = data,
359373
rustc_env = rustc_env,
374+
rustc_flags = rustc_flags,
360375
tags = binary_tags,
361376
**kwargs
362377
)
@@ -370,6 +385,7 @@ def cargo_build_script(
370385
deps = deps,
371386
data = data,
372387
tools = tools,
388+
rustc_flags = rustc_flags,
373389
visibility = visibility,
374390
tags = tags,
375391
)

cargo/cargo_build_script_runner/bin.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ fn run_buildrs() -> Result<(), String> {
123123
}
124124
}
125125

126+
// Bazel does not support byte strings so in order to correctly represent `CARGO_ENCODED_RUSTFLAGS`
127+
// the escaped `\x1f` sequences need to be unescaped
128+
if let Ok(encoded_rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
129+
command.env(
130+
"CARGO_ENCODED_RUSTFLAGS",
131+
encoded_rustflags.replace("\\x1f", "\x1f"),
132+
);
133+
}
134+
126135
let (buildrs_outputs, process_output) = BuildScriptOutput::outputs_from_command(&mut command)
127136
.map_err(|process_output| {
128137
format!(

crate_universe/3rdparty/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("//crate_universe:crates.bzl", "crate_deps_target")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
crate_deps_target()
6+
7+
filegroup(
8+
name = "distro",
9+
srcs = glob([
10+
"*.bzl",
11+
"*.bazel",
12+
]) + [
13+
"//crate_universe/3rdparty/crates:srcs",
14+
],
15+
)
16+
17+
filegroup(
18+
name = "bzl_srcs",
19+
srcs = glob(["*.bzl"]),
20+
)

0 commit comments

Comments
 (0)