Skip to content

Commit eb171a2

Browse files
committed
Auto merge of #147372 - jieyouxu:rust-analyzer-main-tests, r=Kobzol
Run main rust-analyzer tests in rust-lang/rust CI Part of #147370. MCP: rust-lang/compiler-team#923 This PR prepares `rust-analyzer` crates with `in-rust-tree` cargo featues where needed, and and updates bootstrap to run the main `rust-analyzer` tests in rust-lang/rust CI, not just the `proc-macro-srv` crate tests. This supersedes the earlier attempt at #136779. I was honestly expecting more failures in this PR, but looking back at the previous attempt, that makes sense because we no longer run `i686-mingw` (32-bit windows-gnu) which had a _bunch_ of these failures. In the earlier attempt I also disabled the `i686-mingw`-related failures for `i686-msvc` since I didn't feel like digging into 32-bit msvc at the time. Try results from this PR shows that it's most likely limited to 32-bit windows-gnu specifically. ### `rust-analyzer` test remarks - I actually had to _remove_ the `CARGO_WORKSPACE_DIR` `expect-test`-hack in order for `expect-test` to be able to find the test expectation HTML files (for `syntax_highlighting` tests in `ide`). When I added the hack, ironically, it made `expect-test` unable to find the expectation files. I think this was because previously the path was of the `proc-macro-srv` crate specifically, now we point to the root r-a workspace? - The `cfg`-related differences on `aarch64-apple-darwin` might've been fixed? I can't tell, but we don't seem to be observing the differences now. - I'm not sure why `config::{generate_config_documentation, generate_package_json_config}` no longer fails. Perhaps they were fixed to no longer try to write to source directory? ### Review remarks - Commit 1 updates r-a crates that are involved in tests needing artifacts from `rustc_private` compiler crates to use the `in-rust-tree` cargo feature. I briefly tried to use a plain `--cfg=in_rust_tree`, but quickly realized it was very hacky, and needed invasive bootstrap changes. The cargo feature approach seems most "natural"/well-supported to both bootstrap and cargo. - Commit 2 updates bootstrap to not only run the `proc-macro-srv` tests, but the whole r-a tests. - Commit 3 restricts r-a main tests to non-32-bit targets we test in CI, since (1) r-a repo does not run tests against 32-bit platforms, and (2) there are some target pointer width sensitive hash differences causing tests to fail. Notably, this means that we also no longer run r-a `proc-macro-srv` tests against 32-bit targets, but we don't expect that crate to be have target pointer width differences. Discussed this in [#t-compiler/rust-analyzer > 32-bit tests?](https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/32-bit.20tests.3F/with/563145736). --- // try-job: aarch64-gnu // try-job: aarch64-apple // try-job: x86_64-mingw-1 // try-job: i686-msvc-1 // try-job: x86_64-msvc-1 // try-job: aarch64-msvc-1
2 parents ce63e5d + 15e4969 commit eb171a2

File tree

31 files changed

+179
-18
lines changed

31 files changed

+179
-18
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -465,35 +465,73 @@ impl Step for RustAnalyzer {
465465

466466
/// Runs `cargo test` for rust-analyzer
467467
fn run(self, builder: &Builder<'_>) {
468-
let host = self.compilers.target();
468+
let build_compiler = self.compilers.build_compiler();
469+
let target = self.compilers.target();
470+
471+
// NOTE: rust-analyzer repo currently (as of 2025-12-11) does not run tests against 32-bit
472+
// targets, so we also don't run them in rust-lang/rust CI (because that will just mean that
473+
// subtree syncs will keep getting 32-bit-specific failures that are not observed in
474+
// rust-analyzer repo CI).
475+
//
476+
// Some 32-bit specific failures include e.g. target pointer width specific hashes.
477+
478+
// FIXME: eventually, we should probably reduce the amount of target tuple substring
479+
// matching in bootstrap.
480+
if target.starts_with("i686") {
481+
return;
482+
}
469483

470-
let workspace_path = "src/tools/rust-analyzer";
471-
// until the whole RA test suite runs on `i686`, we only run
472-
// `proc-macro-srv` tests
473-
let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
474484
let mut cargo = tool::prepare_tool_cargo(
475485
builder,
476-
self.compilers.build_compiler(),
486+
build_compiler,
477487
Mode::ToolRustcPrivate,
478-
host,
488+
target,
479489
Kind::Test,
480-
crate_path,
490+
"src/tools/rust-analyzer",
481491
SourceType::InTree,
482492
&["in-rust-tree".to_owned()],
483493
);
484494
cargo.allow_features(tool::RustAnalyzer::ALLOW_FEATURES);
485495

486-
let dir = builder.src.join(workspace_path);
487-
// needed by rust-analyzer to find its own text fixtures, cf.
488-
// https://github.com/rust-analyzer/expect-test/issues/33
489-
cargo.env("CARGO_WORKSPACE_DIR", &dir);
496+
// N.B. it turns out _setting_ `CARGO_WORKSPACE_DIR` actually somehow breaks `expect-test`,
497+
// even though previously we actually needed to set that hack to allow `expect-test` to
498+
// correctly discover the r-a workspace instead of the outer r-l/r workspace.
490499

491-
// RA's test suite tries to write to the source directory, that can't
492-
// work in Rust CI
500+
// FIXME: RA's test suite tries to write to the source directory, that can't work in Rust CI
501+
// without properly wiring up the writable test dir.
493502
cargo.env("SKIP_SLOW_TESTS", "1");
494503

504+
// NOTE: we need to skip `src/tools/rust-analyzer/xtask` as they seem to exercise rustup /
505+
// stable rustfmt.
506+
//
507+
// NOTE: you can only skip a specific workspace package via `--exclude=...` if you *also*
508+
// specify `--workspace`.
509+
cargo.arg("--workspace");
510+
cargo.arg("--exclude=xtask");
511+
512+
let mut skip_tests = vec![];
513+
514+
// NOTE: the following test skips is a bit cheeky in that it assumes there are no
515+
// identically named tests across different r-a packages, where we want to run the
516+
// identically named test in one package but not another. If we want to support that use
517+
// case, we'd have to run the r-a tests in two batches (with one excluding the package that
518+
// we *don't* want to run the test for, and the other batch including).
519+
520+
// Across all platforms.
521+
skip_tests.extend_from_slice(&[
522+
// FIXME: this test wants to find a `rustc`. We need to provide it with a path to staged
523+
// in-tree `rustc`, but setting `RUSTC` env var requires some reworking of bootstrap.
524+
"tests::smoke_test_real_sysroot_cargo",
525+
// NOTE: part of `smol-str` test suite; this tries to access a stable rustfmt from the
526+
// environment, which is not something we want to do.
527+
"check_code_formatting",
528+
]);
529+
530+
let skip_tests = skip_tests.iter().map(|name| format!("--skip={name}")).collect::<Vec<_>>();
531+
let skip_tests = skip_tests.iter().map(|s| s.as_str()).collect::<Vec<_>>();
532+
495533
cargo.add_rustc_lib_path(builder);
496-
run_cargo_test(cargo, &[], &[], "rust-analyzer", host, builder);
534+
run_cargo_test(cargo, skip_tests.as_slice(), &[], "rust-analyzer", target, builder);
497535
}
498536

499537
fn metadata(&self) -> Option<StepMetadata> {

src/tools/rust-analyzer/crates/base-db/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ vfs.workspace = true
3131
span.workspace = true
3232
intern.workspace = true
3333

34+
[features]
35+
default = []
36+
in-rust-tree = []
37+
3438
[lints]
3539
workspace = true

src/tools/rust-analyzer/crates/base-db/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! base_db defines basic database traits. The concrete DB is defined by ide.
22
3+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4+
5+
#[cfg(feature = "in-rust-tree")]
6+
extern crate rustc_driver as _;
7+
38
pub use salsa;
49
pub use salsa_macros;
510

src/tools/rust-analyzer/crates/cfg/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ syntax.workspace = true
3333
# tt is needed for testing
3434
cfg = { path = ".", default-features = false, features = ["tt"] }
3535

36+
[features]
37+
default = []
38+
in-rust-tree = []
39+
3640
[lints]
3741
workspace = true

src/tools/rust-analyzer/crates/cfg/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! cfg defines conditional compiling options, `cfg` attribute parser and evaluator
22
3+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4+
5+
#[cfg(feature = "in-rust-tree")]
6+
extern crate rustc_driver as _;
7+
38
mod cfg_expr;
49
mod dnf;
510
#[cfg(test)]

src/tools/rust-analyzer/crates/ide-completion/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,9 @@ expect-test = "1.5.1"
3737
test-utils.workspace = true
3838
test-fixture.workspace = true
3939

40+
[features]
41+
default = []
42+
in-rust-tree = []
43+
4044
[lints]
4145
workspace = true

src/tools/rust-analyzer/crates/ide-completion/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// It's useful to refer to code that is private in doc comments.
44
#![allow(rustdoc::private_intra_doc_links)]
55

6+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
7+
8+
#[cfg(feature = "in-rust-tree")]
9+
extern crate rustc_driver as _;
10+
611
mod completions;
712
mod config;
813
mod context;

src/tools/rust-analyzer/crates/ide-db/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,9 @@ line-index.workspace = true
5252
[dev-dependencies]
5353
expect-test = "1.5.1"
5454

55+
[features]
56+
default = []
57+
in-rust-tree = []
58+
5559
[lints]
5660
workspace = true

src/tools/rust-analyzer/crates/ide-db/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
//!
33
//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
44
5+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
6+
7+
#[cfg(feature = "in-rust-tree")]
8+
extern crate rustc_driver as _;
9+
510
extern crate self as ide_db;
611

712
mod apply_change;

src/tools/rust-analyzer/crates/ide-diagnostics/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ expect-test = "1.5.1"
3434
test-utils.workspace = true
3535
test-fixture.workspace = true
3636

37+
[features]
38+
default = []
39+
in-rust-tree = []
40+
3741
[lints]
3842
workspace = true

0 commit comments

Comments
 (0)