Skip to content

Commit 6475fa9

Browse files
authored
Merge branch 'main' into revert
2 parents fe2f534 + 0e2fbbf commit 6475fa9

Some content is hidden

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

76 files changed

+2504
-2830
lines changed

.bazelci/presubmit.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,17 +539,13 @@ tasks:
539539
platform: ubuntu2004
540540
working_directory: examples/crate_universe_local_path
541541
run_targets:
542-
- "//:vendor_lazy_static_out_of_tree"
543-
test_targets:
544-
- "//..."
542+
- "//:vendor_edit_test_out_of_tree"
545543
crate_universe_local_path_in_tree:
546544
name: Crate Universe Local Path In Tree
547545
platform: ubuntu2004
548546
working_directory: examples/crate_universe_local_path
549547
run_targets:
550-
- "//:vendor_lazy_static_in_tree"
551-
test_targets:
552-
- "//..."
548+
- "//:vendor_edit_test_in_tree"
553549
# See https://github.com/bazelbuild/rules_rust/issues/2186 about re-enabling these.
554550
# crate_universe_examples_windows:
555551
# name: Crate Universe Examples

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module(
44
name = "rules_rust",
5-
version = "0.55.6",
5+
version = "0.56.0",
66
)
77

88
###############################################################################

cargo/BUILD.bazel

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

3-
package(default_visibility = ["//visibility:public"])
3+
exports_files(["defs.bzl"])
44

55
bzl_library(
66
name = "bzl_lib",
7-
srcs = glob(["**/*.bzl"]),
8-
deps = ["//cargo/private:bzl_lib"],
7+
srcs = glob(["*.bzl"]),
8+
visibility = ["//visibility:public"],
9+
deps = [
10+
"//cargo/private:bzl_lib",
11+
"//cargo/settings:bzl_lib",
12+
],
913
)

cargo/defs.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Common definitions for the `@rules_rust//cargo` package"""
1+
"""# Cargo
2+
3+
Common definitions for the `@rules_rust//cargo` package
4+
"""
25

36
load(
47
"//cargo/private:cargo_bootstrap.bzl",

cargo/private/cargo_build_script.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,6 @@ cargo_build_script = rule(
654654
"_cargo_manifest_dir_filename_suffixes_to_retain": attr.label(
655655
default = Label("//cargo/settings:cargo_manifest_dir_filename_suffixes_to_retain"),
656656
),
657-
"_cc_toolchain": attr.label(
658-
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
659-
),
660657
"_debug_std_streams_output_group": attr.label(
661658
default = Label("//cargo/settings:debug_std_streams_output_group"),
662659
),

cargo/settings/BUILD.bazel

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,32 @@
1-
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_list_flag")
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load(
3+
":settings.bzl",
4+
"cargo_manifest_dir_filename_suffixes_to_retain",
5+
"debug_std_streams_output_group",
6+
"experimental_symlink_execroot",
7+
"incompatible_runfiles_cargo_manifest_dir",
8+
"use_default_shell_env",
9+
)
210

311
package(default_visibility = ["//visibility:public"])
412

5-
# A flag for which causes `cargo_build_script` to symlink the execroot of the action to
6-
# the `CARGO_MANIFEST_DIR` where the scripts are run.
7-
bool_flag(
8-
name = "experimental_symlink_execroot",
9-
build_setting_default = False,
10-
)
13+
exports_files(["settings.bzl"])
1114

12-
# A flag which causes `cargo_build_script` to write an explicit `CARGO_MANFIEST_DIR`
13-
# directory from an action instead of using runfiles directories which cannot be
14-
# passed to downstream actions.
15-
# https://github.com/bazelbuild/bazel/issues/15486
16-
bool_flag(
17-
name = "incompatible_runfiles_cargo_manifest_dir",
18-
build_setting_default = True,
19-
)
20-
21-
# A flag which determines what files are retained in `CARGO_MANIFEST_DIR` directories
22-
# that are created in `CargoBuildScriptRun` actions.
23-
string_list_flag(
24-
name = "cargo_manifest_dir_filename_suffixes_to_retain",
25-
build_setting_default = [
26-
".lib",
27-
".so",
15+
bzl_library(
16+
name = "bzl_lib",
17+
srcs = glob(["*.bzl"]),
18+
visibility = ["//cargo:__pkg__"],
19+
deps = [
20+
"@bazel_skylib//rules:common_settings",
2821
],
2922
)
3023

31-
# A flag which adds a `streams` output group to `cargo_build_script` targets that contain
32-
# the raw `stderr` and `stdout` streams from the build script.
33-
bool_flag(
34-
name = "debug_std_streams_output_group",
35-
build_setting_default = False,
36-
)
24+
cargo_manifest_dir_filename_suffixes_to_retain()
3725

38-
# A flag which controls the global default of `ctx.actions.run.use_default_shell_env`
39-
# for `cargo_build_script` targets.
40-
bool_flag(
41-
name = "use_default_shell_env",
42-
build_setting_default = True,
43-
)
26+
debug_std_streams_output_group()
27+
28+
experimental_symlink_execroot()
29+
30+
incompatible_runfiles_cargo_manifest_dir()
31+
32+
use_default_shell_env()

cargo/settings/settings.bzl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""# Cargo settings
2+
3+
Definitions for all `@rules_rust//cargo` settings
4+
"""
5+
6+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_list_flag")
7+
8+
def experimental_symlink_execroot():
9+
"""A flag for which causes `cargo_build_script` to symlink the execroot of the action to \
10+
the `CARGO_MANIFEST_DIR` where the scripts are run.
11+
"""
12+
bool_flag(
13+
name = "experimental_symlink_execroot",
14+
build_setting_default = False,
15+
)
16+
17+
def incompatible_runfiles_cargo_manifest_dir():
18+
"""A flag which causes `cargo_build_script` to write an explicit `CARGO_MANFIEST_DIR` \
19+
directory from an action instead of using runfiles directories which cannot be \
20+
passed to downstream actions.
21+
22+
https://github.com/bazelbuild/bazel/issues/15486
23+
"""
24+
bool_flag(
25+
name = "incompatible_runfiles_cargo_manifest_dir",
26+
build_setting_default = True,
27+
)
28+
29+
def cargo_manifest_dir_filename_suffixes_to_retain():
30+
"""A flag which determines what files are retained in `CARGO_MANIFEST_DIR` directories \
31+
that are created in `CargoBuildScriptRun` actions.
32+
"""
33+
string_list_flag(
34+
name = "cargo_manifest_dir_filename_suffixes_to_retain",
35+
build_setting_default = [
36+
".lib",
37+
".so",
38+
],
39+
)
40+
41+
def debug_std_streams_output_group():
42+
"""A flag which adds a `streams` output group to `cargo_build_script` targets that contain \
43+
the raw `stderr` and `stdout` streams from the build script.
44+
"""
45+
bool_flag(
46+
name = "debug_std_streams_output_group",
47+
build_setting_default = False,
48+
)
49+
50+
def use_default_shell_env():
51+
"""A flag which controls the global default of `ctx.actions.run.use_default_shell_env` for `cargo_build_script` targets.
52+
"""
53+
bool_flag(
54+
name = "use_default_shell_env",
55+
build_setting_default = True,
56+
)

crate_universe/src/cli/generate.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ pub fn generate(opt: GenerateOptions) -> Result<()> {
119119
// Write the outputs to disk
120120
write_outputs(normalized_outputs, opt.dry_run)?;
121121

122+
let splicing_manifest = SplicingManifest::try_from_path(&opt.splicing_manifest)?;
123+
122124
write_paths_to_track(
123125
&opt.paths_to_track,
124126
&opt.warnings_output_path,
127+
splicing_manifest.manifests.keys().cloned(),
125128
context
126129
.crates
127130
.values()
@@ -164,9 +167,12 @@ pub fn generate(opt: GenerateOptions) -> Result<()> {
164167
&opt.nonhermetic_root_bazel_workspace_dir,
165168
)?;
166169

170+
let splicing_manifest = SplicingManifest::try_from_path(&opt.splicing_manifest)?;
171+
167172
write_paths_to_track(
168173
&opt.paths_to_track,
169174
&opt.warnings_output_path,
175+
splicing_manifest.manifests.keys().cloned(),
170176
annotations.lockfile.crates.values(),
171177
cargo_lockfile.patch.unused.iter(),
172178
)?;
@@ -189,8 +195,6 @@ pub fn generate(opt: GenerateOptions) -> Result<()> {
189195

190196
// Ensure Bazel lockfiles are written to disk so future generations can be short-circuited.
191197
if let Some(lockfile) = opt.lockfile {
192-
let splicing_manifest = SplicingManifest::try_from_path(&opt.splicing_manifest)?;
193-
194198
let lock_content =
195199
lock_context(context, &config, &splicing_manifest, &cargo_bin, rustc_bin)?;
196200

@@ -220,10 +224,12 @@ fn update_cargo_lockfile(path: &Path, cargo_lockfile: Lockfile) -> Result<()> {
220224
fn write_paths_to_track<
221225
'a,
222226
SourceAnnotations: Iterator<Item = &'a SourceAnnotation>,
227+
Paths: Iterator<Item = Utf8PathBuf>,
223228
UnusedPatches: Iterator<Item = &'a cargo_lock::Dependency>,
224229
>(
225230
output_file: &Path,
226231
warnings_output_path: &Path,
232+
manifests: Paths,
227233
source_annotations: SourceAnnotations,
228234
unused_patches: UnusedPatches,
229235
) -> Result<()> {
@@ -235,6 +241,7 @@ fn write_paths_to_track<
235241
None
236242
}
237243
})
244+
.chain(manifests)
238245
.collect();
239246
std::fs::write(
240247
output_file,

crate_universe/src/metadata/cargo_tree_resolver.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl TreeResolver {
150150
// host triple instead of the host triple detected by rustc.
151151
.env("RUSTC_WRAPPER", rustc_wrapper)
152152
.env("HOST_TRIPLE", host_triple)
153+
.env("CARGO_CACHE_RUSTC_INFO", "0")
153154
.current_dir(manifest_path.parent().expect("All manifests should have a valid parent."))
154155
.arg("tree")
155156
.arg("--manifest-path")

crate_universe/tests/cargo_integration_test.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,24 @@ fn host_specific_build_deps() {
526526
}
527527

528528
let r = runfiles::Runfiles::create().unwrap();
529+
530+
let src_cargo_toml = runfiles::rlocation!(
531+
r,
532+
"rules_rust/crate_universe/test_data/metadata/host_specific_build_deps/Cargo.toml"
533+
)
534+
.unwrap();
535+
536+
// Put Cargo.toml into writable directory structure and create target/ directory to verify that
537+
// cargo does not incorrectly cache rustc info in target/.rustc_info.json file.
538+
let scratch = tempfile::tempdir().unwrap();
539+
let cargo_toml = scratch.path().join("Cargo.toml");
540+
fs::copy(src_cargo_toml, &cargo_toml).unwrap();
541+
fs::create_dir(scratch.path().join("target")).unwrap();
542+
529543
let metadata = run(
530544
"host_specific_build_deps",
531545
HashMap::from([(
532-
runfiles::rlocation!(
533-
r,
534-
"rules_rust/crate_universe/test_data/metadata/host_specific_build_deps/Cargo.toml"
535-
)
536-
.unwrap()
537-
.to_string_lossy()
538-
.to_string(),
546+
cargo_toml.to_string_lossy().to_string(),
539547
"//:test_input".to_string(),
540548
)]),
541549
"rules_rust/crate_universe/test_data/metadata/host_specific_build_deps/Cargo.lock",

0 commit comments

Comments
 (0)