Skip to content

Commit 4568240

Browse files
authored
Merge branch 'main' into rust-analyzer-discover-config
2 parents 4261a1b + b13b15f commit 4568240

186 files changed

Lines changed: 8800 additions & 13137 deletions

File tree

Some content is hidden

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

.bazelci/presubmit.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,3 @@ tasks:
11081108
- "//..."
11091109
test_targets:
11101110
- "//..."
1111-
1112-
buildifier:
1113-
version: latest
1114-
warnings: "all"

.github/workflows/formatting.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17+
- name: Buildifier
18+
run: |
19+
wget "https://github.com/bazelbuild/buildtools/releases/download/v${BUILDIFIER_VERSION}/buildifier-linux-amd64" -O buildifier
20+
chmod +x ./buildifier
21+
./buildifier -lint=warn -mode=check -warnings=all -r ${{ github.workspace }}
22+
rm ./buildifier
23+
env:
24+
BUILDIFIER_VERSION: 8.0.2
1725
- uses: DoozyX/clang-format-lint-action@v0.14
1826
with:
1927
source: '.'

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use_repo(
9191
"libc",
9292
"rtra",
9393
"rtra__serde-1.0.217",
94-
"rtra__serde_json-1.0.137",
94+
"rtra__serde_json-1.0.138",
9595
"rules_rust_test_load_arbitrary_tool",
9696
"rules_rust_toolchain_test_target_json",
9797
)

cargo/private/cargo_build_script.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
load("@bazel_skylib//lib:paths.bzl", "paths")
44
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
5-
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
65
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
6+
load("@rules_cc//cc:find_cc_toolchain.bzl", find_cpp_toolchain = "find_cc_toolchain")
7+
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
78
load("//rust:defs.bzl", "rust_common")
89
load("//rust:rust_common.bzl", "BuildInfo")
910

@@ -361,6 +362,7 @@ def _cargo_build_script_impl(ctx):
361362
env.update(ctx.configuration.default_shell_env)
362363

363364
env.update({
365+
"CARGO": "${{pwd}}/{}".format(toolchain.cargo.path),
364366
"CARGO_CRATE_NAME": name_to_crate_name(pkg_name),
365367
"CARGO_MANIFEST_DIR": manifest_dir,
366368
"CARGO_PKG_NAME": pkg_name,

cargo/private/internal_extensions.bzl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Bzlmod module extensions that are only used internally"""
22

3+
load("@bazel_features//:features.bzl", "bazel_features")
34
load("//cargo:deps.bzl", "cargo_dependencies")
45

56
def _internal_deps_impl(module_ctx):
@@ -12,10 +13,15 @@ def _internal_deps_impl(module_ctx):
1213
# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
1314
# dependencies are only relevant for module extensions that can be used
1415
# by other MODULES.
15-
return module_ctx.extension_metadata(
16-
root_module_direct_deps = [repo.repo for repo in direct_deps],
17-
root_module_direct_dev_deps = [],
18-
)
16+
metadata_kwargs = {
17+
"root_module_direct_deps": [repo.repo for repo in direct_deps],
18+
"root_module_direct_dev_deps": [],
19+
}
20+
21+
if bazel_features.external_deps.extension_metadata_has_reproducible:
22+
metadata_kwargs["reproducible"] = True
23+
24+
return module_ctx.extension_metadata(**metadata_kwargs)
1925

2026
# This is named a single character to reduce the size of path names when running build scripts, to reduce the chance
2127
# of hitting the 260 character windows path name limit.

crate_universe/extensions.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ load(
373373
"//crate_universe/private:common_utils.bzl",
374374
"new_cargo_bazel_fn",
375375
)
376+
load("//crate_universe/private:crates_repository.bzl", "SUPPORTED_PLATFORM_TRIPLES")
376377
load(
377378
"//crate_universe/private:crates_vendor.bzl",
378379
"CRATES_VENDOR_ATTRS",
@@ -1031,7 +1032,10 @@ _FROM_COMMON_ATTRS = {
10311032
"If set, this file must exist within the workspace (but can be empty) before this rule will work."
10321033
),
10331034
),
1034-
"supported_platform_triples": CRATES_VENDOR_ATTRS["supported_platform_triples"],
1035+
"supported_platform_triples": attr.string_list(
1036+
doc = "A set of all platform triples to consider when generating dependencies.",
1037+
default = SUPPORTED_PLATFORM_TRIPLES,
1038+
),
10351039
}
10361040

10371041
_from_cargo = tag_class(

crate_universe/private/crates_repository.bzl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@ load(
2222
load("//crate_universe/private:urls.bzl", "CARGO_BAZEL_SHA256S", "CARGO_BAZEL_URLS")
2323
load("//rust:defs.bzl", "rust_common")
2424
load("//rust/platform:triple.bzl", "get_host_triple")
25-
load("//rust/platform:triple_mappings.bzl", "SUPPORTED_PLATFORM_TRIPLES")
25+
26+
# A reduced subset of platform triples that cover a wide range of known users.
27+
# The reduced set is intended to speed up the splciing step which has `O(N^2)`
28+
# complexity for each platform triple added.
29+
SUPPORTED_PLATFORM_TRIPLES = [
30+
"aarch64-apple-darwin",
31+
"aarch64-unknown-linux-gnu",
32+
"wasm32-unknown-unknown",
33+
"wasm32-wasip1",
34+
"x86_64-pc-windows-msvc",
35+
"x86_64-unknown-linux-gnu",
36+
"x86_64-unknown-nixos-gnu",
37+
]
2638

2739
def _crates_repository_impl(repository_ctx):
2840
# Determine the current host's platform triple

crate_universe/src/cli.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ mod splice;
77
mod vendor;
88

99
use clap::Parser;
10-
use tracing::{Level, Subscriber};
10+
use tracing::Subscriber;
1111
use tracing_subscriber::fmt::format::{Format, Full};
1212
use tracing_subscriber::fmt::time::SystemTime;
1313
use tracing_subscriber::fmt::{FormatEvent, FormatFields};
1414
use tracing_subscriber::registry::LookupSpan;
1515
use tracing_subscriber::FmtSubscriber;
1616

17+
pub use tracing::Level as LogLevel;
18+
1719
pub use self::generate::GenerateOptions;
1820
pub use self::query::QueryOptions;
1921
pub use self::render::RenderOptions;
@@ -92,21 +94,17 @@ impl LoggingFormatEvent {
9294
}
9395

9496
/// Initialize logging for one of the cli options.
95-
pub fn init_logging(name: &str, verbose: bool) {
97+
pub fn init_logging(name: &str, level: LogLevel) {
9698
if !EXPECTED_LOGGER_NAMES.contains(&name) {
9799
panic!(
98100
"Unexpected logger name {}, use of one of {:?}",
99101
name, EXPECTED_LOGGER_NAMES
100102
);
101103
}
102104

103-
// a builder for `FmtSubscriber`.
104105
let subscriber = FmtSubscriber::builder()
105-
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
106-
// will be written to stdout.
107-
.with_max_level(if verbose { Level::DEBUG } else { Level::INFO })
106+
.with_max_level(level)
108107
.event_format(LoggingFormatEvent::new(name))
109-
// completes the builder.
110108
.finish();
111109

112110
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

crate_universe/src/main.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,36 @@ fn main() -> cli::Result<()> {
66
// Parse arguments
77
let opt = cli::parse_args();
88

9-
let verbose_logging = std::env::var("CARGO_BAZEL_DEBUG").is_ok();
9+
let level = match std::env::var("CARGO_BAZEL_DEBUG") {
10+
Ok(var) => {
11+
if var == "TRACE" {
12+
crate::cli::LogLevel::TRACE
13+
} else {
14+
crate::cli::LogLevel::DEBUG
15+
}
16+
}
17+
Err(_) => crate::cli::LogLevel::INFO,
18+
};
1019

1120
match opt {
1221
cli::Options::Generate(opt) => {
13-
cli::init_logging("Generate", verbose_logging);
22+
cli::init_logging("Generate", level);
1423
cli::generate(opt)
1524
}
1625
cli::Options::Splice(opt) => {
17-
cli::init_logging("Splice", verbose_logging);
26+
cli::init_logging("Splice", level);
1827
cli::splice(opt)
1928
}
2029
cli::Options::Query(opt) => {
21-
cli::init_logging("Query", verbose_logging);
30+
cli::init_logging("Query", level);
2231
cli::query(opt)
2332
}
2433
cli::Options::Vendor(opt) => {
25-
cli::init_logging("Vendor", verbose_logging);
34+
cli::init_logging("Vendor", level);
2635
cli::vendor(opt)
2736
}
2837
cli::Options::Render(opt) => {
29-
cli::init_logging("Render", verbose_logging);
38+
cli::init_logging("Render", level);
3039
cli::render(opt)
3140
}
3241
}

crate_universe/src/metadata/cargo_tree_resolver.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use anyhow::{anyhow, bail, Context, Result};
99
use camino::Utf8Path;
1010
use semver::Version;
1111
use serde::{Deserialize, Serialize};
12-
use tracing::debug;
12+
use tracing::{debug, trace};
1313
use url::Url;
1414

1515
use crate::config::CrateId;
@@ -137,6 +137,12 @@ impl TreeResolver {
137137
// number of processes (which can be +400 and hit operating system limitations).
138138
let mut target_triple_to_child = BTreeMap::<String, Child>::new();
139139

140+
debug!(
141+
"Spawning `cargo tree` processes for host `{}`: {}",
142+
host_triple,
143+
cargo_target_triples.keys().len(),
144+
);
145+
140146
for target_triple in cargo_target_triples.keys() {
141147
// We use `cargo tree` here because `cargo metadata` doesn't report
142148
// back target-specific features (enabled with `resolver = "2"`).
@@ -178,12 +184,6 @@ impl TreeResolver {
178184
target_triple_to_child.insert(target_triple.clone(), child);
179185
}
180186

181-
debug!(
182-
"Spawned `cargo tree` processes for host `{}`: {}",
183-
host_triple,
184-
target_triple_to_child.len(),
185-
);
186-
187187
for (target_triple, child) in target_triple_to_child.into_iter() {
188188
let output = child.wait_with_output().with_context(|| {
189189
format!(
@@ -194,11 +194,13 @@ impl TreeResolver {
194194
)
195195
})?;
196196
if !output.status.success() {
197-
eprintln!("{}", String::from_utf8_lossy(&output.stdout));
198-
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
197+
tracing::error!("{}", String::from_utf8_lossy(&output.stdout));
198+
tracing::error!("{}", String::from_utf8_lossy(&output.stderr));
199199
bail!(format!("Failed to run cargo tree: {}", output.status))
200200
}
201201

202+
tracing::trace!("`cargo tree --target={}` completed.", target_triple);
203+
202204
// Replicate outputs for any de-duplicated platforms
203205
for host_plat in cargo_host_triples[host_triple].iter() {
204206
for target_plat in cargo_target_triples[&target_triple].iter() {
@@ -348,7 +350,7 @@ impl TreeResolver {
348350

349351
for (host_triple, target_streams) in deps_tree_streams.into_iter() {
350352
for (target_triple, stdout) in target_streams.into_iter() {
351-
debug!(
353+
trace!(
352354
"Parsing (host={}) `cargo tree --target {}` output:\n```\n{}\n```",
353355
host_triple,
354356
target_triple,

0 commit comments

Comments
 (0)