Skip to content

Commit e448b09

Browse files
authored
Merge branch 'main' into zbarsky/update-deps
2 parents b26e19e + 31d8c8a commit e448b09

File tree

35 files changed

+639
-65
lines changed

35 files changed

+639
-65
lines changed

.github/workflows/release.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jobs:
5757
- os: windows-2022
5858
env:
5959
TARGET: "aarch64-pc-windows-msvc"
60+
- os: ubuntu-22.04
61+
env:
62+
TARGET: "s390x-unknown-linux-gnu"
6063
- os: macOS-13
6164
env:
6265
TARGET: "x86_64-apple-darwin"
@@ -217,6 +220,15 @@ jobs:
217220
asset_name: cargo-bazel-aarch64-unknown-linux-gnu
218221
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel
219222
asset_content_type: application/octet-stream
223+
- name: "Upload s390x-unknown-linux-gnu"
224+
uses: actions/upload-release-asset@v1
225+
env:
226+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227+
with:
228+
upload_url: ${{ steps.rules_rust_release.outputs.upload_url }}
229+
asset_name: cargo-bazel-s390x-unknown-linux-gnu
230+
asset_path: ${{ github.workspace }}/crate_universe/target/artifacts/s390x-unknown-linux-gnu/cargo-bazel
231+
asset_content_type: application/octet-stream
220232
- name: "Upload x86_64-apple-darwin"
221233
uses: actions/upload-release-asset@v1
222234
env:

.pre-commit-config.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ repos:
1212
- id: buildifier-lint
1313
args: [--version, "v8.2.0", --warnings=all]
1414
- repo: https://github.com/crate-ci/typos
15-
rev: v1.35.3
15+
rev: v1.35.5
1616
hooks:
1717
- id: typos
1818
exclude: |
1919
(?x)^(
2020
crate_universe/test_data|
2121
examples|
22-
extensions|
23-
ffi|
24-
rust|
25-
tools|
26-
util
22+
extensions
2723
)
24+
exclude_types:
25+
- diff
2826
- repo: https://github.com/psf/black
2927
rev: 24.10.0
3028
hooks:

crate_universe/extensions.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,7 @@ def _generate_hub_and_spokes(
684684

685685
paths_to_track = json.decode(module_ctx.read(paths_to_track_file))
686686
for path in paths_to_track:
687-
# This read triggers watching the file at this path and invalidates the repository_rule which will get re-run.
688-
# Ideally we'd use module_ctx.watch, but it doesn't support files outside of the workspace, and we need to support that.
689-
module_ctx.read(path)
687+
module_ctx.watch(path)
690688

691689
warnings_output_file = json.decode(module_ctx.read(warnings_output_file))
692690
for warning in warnings_output_file:

crate_universe/private/crates_repository.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def _crates_repository_impl(repository_ctx):
119119

120120
paths_to_track = json.decode(repository_ctx.read(paths_to_track_file))
121121
for path in paths_to_track:
122-
# This read triggers watching the file at this path and invalidates the repository_rule which will get re-run.
123-
# Ideally we'd use repository_ctx.watch, but it doesn't support files outside of the workspace, and we need to support that.
124-
repository_ctx.read(path)
122+
repository_ctx.watch(path)
125123

126124
warnings_output_file = json.decode(repository_ctx.read(warnings_output_file))
127125
for warning in warnings_output_file:

crate_universe/src/cli/generate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub fn generate(opt: GenerateOptions) -> Result<()> {
137137
.values()
138138
.filter_map(|crate_context| crate_context.repository.as_ref()),
139139
context.unused_patches.iter(),
140+
&opt.nonhermetic_root_bazel_workspace_dir,
140141
)?;
141142

142143
return Ok(());
@@ -193,6 +194,7 @@ pub fn generate(opt: GenerateOptions) -> Result<()> {
193194
splicing_manifest.manifests.keys().cloned(),
194195
annotations.lockfile.crates.values(),
195196
cargo_lockfile.patch.unused.iter(),
197+
&opt.nonhermetic_root_bazel_workspace_dir,
196198
)?;
197199

198200
// Generate renderable contexts for each package
@@ -252,6 +254,7 @@ fn write_paths_to_track<
252254
manifests: Paths,
253255
source_annotations: SourceAnnotations,
254256
unused_patches: UnusedPatches,
257+
nonhermetic_root_bazel_workspace_dir: &Utf8PathBuf,
255258
) -> Result<()> {
256259
let source_annotation_manifests: BTreeSet<_> = source_annotations
257260
.filter_map(|v| {
@@ -266,6 +269,8 @@ fn write_paths_to_track<
266269
.iter()
267270
.cloned()
268271
.chain(manifests)
272+
// Paths outside the bazel workspace cannot be `.watch`-ed.
273+
.filter(|p| p.starts_with(nonhermetic_root_bazel_workspace_dir))
269274
.collect();
270275
std::fs::write(
271276
output_file,

extensions/prost/private/prost.bzl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ load("@rules_rust//rust/private:rust_analyzer.bzl", "write_rust_analyzer_spec_fi
1818
load("@rules_rust//rust/private:rustc.bzl", "rustc_compile_action")
1919

2020
# buildifier: disable=bzl-visibility
21-
load("@rules_rust//rust/private:utils.bzl", "can_build_metadata")
21+
load(
22+
"@rules_rust//rust/private:utils.bzl",
23+
"can_build_metadata",
24+
"can_use_metadata_for_pipelining",
25+
"generate_output_diagnostics",
26+
)
2227
load("//:providers.bzl", "ProstProtoInfo")
2328
load(":prost_transform.bzl", "ProstTransformInfo")
2429

@@ -181,6 +186,8 @@ def _compile_rust(
181186

182187
lib = ctx.actions.declare_file(lib_name)
183188
rmeta = None
189+
rustc_rmeta_output = None
190+
metadata_supports_pipelining = False
184191

185192
if can_build_metadata(toolchain, ctx, "rlib"):
186193
rmeta_name = "{prefix}{name}-{lib_hash}{extension}".format(
@@ -190,6 +197,8 @@ def _compile_rust(
190197
extension = ".rmeta",
191198
)
192199
rmeta = ctx.actions.declare_file(rmeta_name)
200+
rustc_rmeta_output = generate_output_diagnostics(ctx, rmeta)
201+
metadata_supports_pipelining = can_use_metadata_for_pipelining(toolchain, "rlib")
193202

194203
providers = rustc_compile_action(
195204
ctx = ctx,
@@ -205,6 +214,8 @@ def _compile_rust(
205214
aliases = {},
206215
output = lib,
207216
metadata = rmeta,
217+
metadata_supports_pipelining = metadata_supports_pipelining,
218+
rustc_rmeta_output = rustc_rmeta_output,
208219
edition = edition,
209220
is_test = False,
210221
rustc_env = {},
@@ -373,7 +384,12 @@ rust_prost_aspect = aspect(
373384
executable = True,
374385
default = Label("//private:protoc_wrapper"),
375386
),
376-
} | RUSTC_ATTRS,
387+
} | RUSTC_ATTRS | {
388+
# Need to override this attribute to explicitly set the workspace.
389+
"_always_enable_metadata_output_groups": attr.label(
390+
default = Label("@rules_rust//rust/settings:always_enable_metadata_output_groups"),
391+
),
392+
},
377393
fragments = ["cpp"],
378394
toolchains = [
379395
TOOLCHAIN_TYPE,

extensions/protobuf/proto.bzl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ load("@rules_proto//proto:defs.bzl", "ProtoInfo")
2020
load("@rules_rust//rust/private:rustc.bzl", "rustc_compile_action")
2121

2222
# buildifier: disable=bzl-visibility
23-
load("@rules_rust//rust/private:utils.bzl", "can_build_metadata", "compute_crate_name", "determine_output_hash", "find_toolchain", "transform_deps")
23+
load(
24+
"@rules_rust//rust/private:utils.bzl",
25+
"can_build_metadata",
26+
"can_use_metadata_for_pipelining",
27+
"compute_crate_name",
28+
"determine_output_hash",
29+
"find_toolchain",
30+
"generate_output_diagnostics",
31+
"transform_deps",
32+
)
2433
load(
2534
"//:toolchain.bzl",
2635
_generate_proto = "rust_generate_proto",
@@ -194,12 +203,16 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
194203
output_hash,
195204
))
196205
rust_metadata = None
206+
rustc_rmeta_output = None
207+
metadata_supports_pipelining = False
197208
if can_build_metadata(toolchain, ctx, "rlib"):
198209
rust_metadata = ctx.actions.declare_file("%s/lib%s-%s.rmeta" % (
199210
output_dir,
200211
crate_name,
201212
output_hash,
202213
))
214+
rustc_rmeta_output = generate_output_diagnostics(ctx, rust_metadata)
215+
metadata_supports_pipelining = can_use_metadata_for_pipelining(toolchain, "rlib")
203216

204217
# Gather all dependencies for compilation
205218
compile_action_deps = depset(
@@ -223,6 +236,8 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
223236
aliases = {},
224237
output = rust_lib,
225238
metadata = rust_metadata,
239+
metadata_supports_pipelining = metadata_supports_pipelining,
240+
rustc_rmeta_output = rustc_rmeta_output,
226241
edition = proto_toolchain.edition,
227242
rustc_env = {},
228243
is_test = False,
@@ -311,6 +326,9 @@ rust_proto_library = rule(
311326
file of arguments to rustc: `@$(location //package:target)`.
312327
""",
313328
),
329+
"_always_enable_metadata_output_groups": attr.label(
330+
default = Label("@rules_rust//rust/settings:always_enable_metadata_output_groups"),
331+
),
314332
"_optional_output_wrapper": attr.label(
315333
executable = True,
316334
cfg = "exec",

rust/platform/triple_mappings.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
282282
}
283283

284284
def cpu_arch_to_constraints(cpu_arch, *, system = None):
285-
"""Returns a list of contraint values which represents a triple's CPU.
285+
"""Returns a list of constraint values which represents a triple's CPU.
286286
287287
Args:
288288
cpu_arch (str): The architecture to match constraints for

rust/private/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bzl_library(
2828
":rules_cc_bzl_lib",
2929
"//rust/platform:bzl_lib",
3030
"@bazel_skylib//lib:paths",
31+
"@bazel_skylib//lib:structs",
3132
"@bazel_skylib//rules:common_settings",
3233
],
3334
)

rust/private/clippy.bzl

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414

1515
"""A module defining clippy rules"""
1616

17+
load("@bazel_skylib//lib:structs.bzl", "structs")
1718
load("//rust/private:common.bzl", "rust_common")
18-
load("//rust/private:providers.bzl", "CaptureClippyOutputInfo", "ClippyInfo", "LintsInfo")
19+
load(
20+
"//rust/private:providers.bzl",
21+
"CaptureClippyOutputInfo",
22+
"ClippyInfo",
23+
"ClippyOutputDiagnosticsInfo",
24+
"LintsInfo",
25+
)
1926
load(
2027
"//rust/private:rustc.bzl",
2128
"collect_deps",
@@ -146,6 +153,13 @@ def _clippy_aspect_impl(target, ctx):
146153
"_clippy_error_format" if use_clippy_error_format else "_error_format",
147154
)
148155

156+
clippy_diagnostics = None
157+
if ctx.attr._clippy_output_diagnostics[ClippyOutputDiagnosticsInfo].output_diagnostics:
158+
clippy_diagnostics = ctx.actions.declare_file(ctx.label.name + ".clippy.diagnostics", sibling = crate_info.output)
159+
crate_info_dict = structs.to_dict(crate_info)
160+
crate_info_dict["rustc_output"] = clippy_diagnostics
161+
crate_info = rust_common.create_crate_info(**crate_info_dict)
162+
149163
args, env = construct_arguments(
150164
ctx = ctx,
151165
attr = ctx.rule.attr,
@@ -165,6 +179,7 @@ def _clippy_aspect_impl(target, ctx):
165179
build_flags_files = build_flags_files,
166180
emit = ["dep-info", "metadata"],
167181
skip_expanding_rustc_env = True,
182+
use_json_output = bool(clippy_diagnostics),
168183
error_format = error_format,
169184
)
170185

@@ -217,7 +232,7 @@ def _clippy_aspect_impl(target, ctx):
217232
ctx.actions.run(
218233
executable = ctx.executable._process_wrapper,
219234
inputs = compile_inputs,
220-
outputs = [clippy_out],
235+
outputs = [clippy_out] + [x for x in [clippy_diagnostics] if x],
221236
env = env,
222237
tools = [toolchain.clippy_driver],
223238
arguments = args.all,
@@ -226,8 +241,12 @@ def _clippy_aspect_impl(target, ctx):
226241
toolchain = "@rules_rust//rust:toolchain_type",
227242
)
228243

244+
output_group_info = {"clippy_checks": depset([clippy_out])}
245+
if clippy_diagnostics:
246+
output_group_info["clippy_output"] = depset([clippy_diagnostics])
247+
229248
return [
230-
OutputGroupInfo(clippy_checks = depset([clippy_out])),
249+
OutputGroupInfo(**output_group_info),
231250
ClippyInfo(output = depset([clippy_out])),
232251
]
233252

@@ -255,6 +274,10 @@ rust_clippy_aspect = aspect(
255274
doc = "Arguments to pass to clippy",
256275
default = Label("//rust/settings:clippy_flags"),
257276
),
277+
"_clippy_output_diagnostics": attr.label(
278+
doc = "Value of the `clippy_output_diagnostics` build setting",
279+
default = "//rust/settings:clippy_output_diagnostics",
280+
),
258281
"_config": attr.label(
259282
doc = "The `clippy.toml` file used for configuration",
260283
allow_single_file = True,
@@ -395,3 +418,25 @@ capture_clippy_output = rule(
395418
implementation = _capture_clippy_output_impl,
396419
build_setting = config.bool(flag = True),
397420
)
421+
422+
def _clippy_output_diagnostics_impl(ctx):
423+
"""Implementation of the `clippy_output_diagnostics` rule
424+
425+
Args:
426+
ctx (ctx): The rule's context object
427+
428+
Returns:
429+
list: A list containing the CaptureClippyOutputInfo provider
430+
"""
431+
return [ClippyOutputDiagnosticsInfo(output_diagnostics = ctx.build_setting_value)]
432+
433+
clippy_output_diagnostics = rule(
434+
doc = (
435+
"Setting this flag from the command line with `--@rules_rust//rust/settings:clippy_output_diagnostics` " +
436+
"makes rules_rust save lippy json output (suitable for consumption by rust-analyzer) in a file, " +
437+
"available from the `clippy_output` output group. This is the clippy equivalent of " +
438+
"`@rules_rust//settings:rustc_output_diagnostics`."
439+
),
440+
implementation = _clippy_output_diagnostics_impl,
441+
build_setting = config.bool(flag = True),
442+
)

0 commit comments

Comments
 (0)