authorbors <bors@rust-lang.org> 2025-12-13 10:11:41 UTC
committerbors <bors@rust-lang.org> 2025-12-13 10:11:41 UTC
logeb171a227f9e5de5d376b6edb56b174bc8235fb3
treeec18d0e33aa5efed7861c819706a33608c46c594
parentce63e5d9ea20f15a70c6fdc4d4de7aee352fd965
parent15e49699cab6d00fe626bff14c32e90860b99d21

Auto merge of #147372 - jieyouxu:rust-analyzer-main-tests, r=Kobzol

Run main rust-analyzer tests in rust-lang/rust CI Part of rust-lang/rust#147370. MCP: https://github.com/rust-lang/compiler-team/issues/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 https://github.com/rust-lang/rust/pull/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

31 files changed, 179 insertions(+), 18 deletions(-)

src/bootstrap/src/core/build_steps/test.rs+53-15
......@@ -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+4
......@@ -31,5 +31,9 @@ vfs.workspace = true
3131span.workspace = true
3232intern.workspace = true
3333
34[features]
35default = []
36in-rust-tree = []
37
3438[lints]
3539workspace = true
src/tools/rust-analyzer/crates/base-db/src/lib.rs+5
......@@ -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")]
6extern crate rustc_driver as _;
7
38pub use salsa;
49pub use salsa_macros;
510
src/tools/rust-analyzer/crates/cfg/Cargo.toml+4
......@@ -33,5 +33,9 @@ syntax.workspace = true
3333# tt is needed for testing
3434cfg = { path = ".", default-features = false, features = ["tt"] }
3535
36[features]
37default = []
38in-rust-tree = []
39
3640[lints]
3741workspace = true
src/tools/rust-analyzer/crates/cfg/src/lib.rs+5
......@@ -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")]
6extern crate rustc_driver as _;
7
38mod cfg_expr;
49mod dnf;
510#[cfg(test)]
src/tools/rust-analyzer/crates/ide-completion/Cargo.toml+4
......@@ -37,5 +37,9 @@ expect-test = "1.5.1"
3737test-utils.workspace = true
3838test-fixture.workspace = true
3939
40[features]
41default = []
42in-rust-tree = []
43
4044[lints]
4145workspace = true
src/tools/rust-analyzer/crates/ide-completion/src/lib.rs+5
......@@ -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")]
9extern crate rustc_driver as _;
10
611mod completions;
712mod config;
813mod context;
src/tools/rust-analyzer/crates/ide-db/Cargo.toml+4
......@@ -52,5 +52,9 @@ line-index.workspace = true
5252[dev-dependencies]
5353expect-test = "1.5.1"
5454
55[features]
56default = []
57in-rust-tree = []
58
5559[lints]
5660workspace = true
src/tools/rust-analyzer/crates/ide-db/src/lib.rs+5
......@@ -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")]
8extern crate rustc_driver as _;
9
510extern crate self as ide_db;
611
712mod apply_change;
src/tools/rust-analyzer/crates/ide-diagnostics/Cargo.toml+4
......@@ -34,5 +34,9 @@ expect-test = "1.5.1"
3434test-utils.workspace = true
3535test-fixture.workspace = true
3636
37[features]
38default = []
39in-rust-tree = []
40
3741[lints]
3842workspace = true
src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs+5
......@@ -23,6 +23,11 @@
2323//! There are also a couple of ad-hoc diagnostics implemented directly here, we
2424//! don't yet have a great pattern for how to do them properly.
2525
26#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
27
28#[cfg(feature = "in-rust-tree")]
29extern crate rustc_driver as _;
30
2631mod handlers {
2732 pub(crate) mod await_outside_of_async;
2833 pub(crate) mod bad_rtn;
src/tools/rust-analyzer/crates/ide-ssr/Cargo.toml+4
......@@ -30,5 +30,9 @@ triomphe.workspace = true
3030test-utils.workspace = true
3131test-fixture.workspace = true
3232
33[features]
34default = []
35in-rust-tree = []
36
3337[lints]
3438workspace = true
src/tools/rust-analyzer/crates/ide-ssr/src/lib.rs+5
......@@ -63,6 +63,11 @@
6363// // foo($a, $b) ==>> ($a).foo($b)
6464// ```
6565
66#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
67
68#[cfg(feature = "in-rust-tree")]
69extern crate rustc_driver as _;
70
6671mod fragments;
6772mod from_comment;
6873mod matching;
src/tools/rust-analyzer/crates/load-cargo/src/lib.rs+6
......@@ -2,6 +2,12 @@
22//! for incorporating changes.
33// Note, don't remove any public api from this. This API is consumed by external tools
44// to run rust-analyzer as a library.
5
6#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
7
8#[cfg(feature = "in-rust-tree")]
9extern crate rustc_driver as _;
10
511use std::{any::Any, collections::hash_map::Entry, mem, path::Path, sync};
612
713use crossbeam_channel::{Receiver, unbounded};
src/tools/rust-analyzer/crates/parser/src/lib.rs+2
......@@ -25,6 +25,8 @@
2525extern crate ra_ap_rustc_lexer as rustc_lexer;
2626#[cfg(feature = "in-rust-tree")]
2727extern crate rustc_lexer;
28#[cfg(feature = "in-rust-tree")]
29extern crate rustc_driver as _;
2830
2931mod event;
3032mod frontmatter;
src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml+2
......@@ -34,6 +34,8 @@ semver.workspace = true
3434
3535[features]
3636sysroot-abi = ["proc-macro-srv", "proc-macro-srv/sysroot-abi"]
37default = []
38in-rust-tree = []
3739
3840[lints]
3941workspace = true
src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs+5
......@@ -12,6 +12,11 @@
1212)]
1313#![allow(internal_features)]
1414
15#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
16
17#[cfg(feature = "in-rust-tree")]
18extern crate rustc_driver as _;
19
1520mod codec;
1621mod framing;
1722pub mod legacy_protocol;
src/tools/rust-analyzer/crates/project-model/Cargo.toml+4
......@@ -39,5 +39,9 @@ toolchain.workspace = true
3939[dev-dependencies]
4040expect-test = "1.5.1"
4141
42[features]
43default = []
44in-rust-tree = []
45
4246[lints]
4347workspace = true
src/tools/rust-analyzer/crates/project-model/src/lib.rs+5
......@@ -18,6 +18,11 @@
1818// It's useful to refer to code that is private in doc comments.
1919#![allow(rustdoc::private_intra_doc_links)]
2020
21#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
22
23#[cfg(feature = "in-rust-tree")]
24extern crate rustc_driver as _;
25
2126pub mod project_json;
2227pub mod toolchain_info {
2328 pub mod rustc_cfg;
src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml+7-3
......@@ -98,12 +98,16 @@ syntax-bridge.workspace = true
9898jemalloc = ["jemallocator", "profile/jemalloc"]
9999force-always-assert = ["stdx/force-always-assert"]
100100in-rust-tree = [
101 "syntax/in-rust-tree",
102 "parser/in-rust-tree",
103 "hir/in-rust-tree",
101 "cfg/in-rust-tree",
104102 "hir-def/in-rust-tree",
105103 "hir-ty/in-rust-tree",
104 "hir/in-rust-tree",
105 "ide-ssr/in-rust-tree",
106 "ide/in-rust-tree",
106107 "load-cargo/in-rust-tree",
108 "parser/in-rust-tree",
109 "proc-macro-api/in-rust-tree",
110 "syntax/in-rust-tree",
107111]
108112dhat = ["dep:dhat"]
109113
src/tools/rust-analyzer/crates/rust-analyzer/src/lib.rs+5
......@@ -9,6 +9,11 @@
99//! The `cli` submodule implements some batch-processing analysis, primarily as
1010//! a debugging aid.
1111
12#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
13
14#[cfg(feature = "in-rust-tree")]
15extern crate rustc_driver as _;
16
1217extern crate ra_ap_rustc_type_ir as rustc_type_ir;
1318
1419/// Any toolchain less than this version will likely not work with rust-analyzer built from this revision.
src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs+4
......@@ -9,6 +9,10 @@
99//! be sure without a real client anyway.
1010
1111#![allow(clippy::disallowed_types)]
12#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
13
14#[cfg(feature = "in-rust-tree")]
15extern crate rustc_driver as _;
1216
1317mod cli;
1418mod ratoml;
src/tools/rust-analyzer/crates/span/Cargo.toml+1
......@@ -27,6 +27,7 @@ syntax.workspace = true
2727
2828[features]
2929default = ["salsa"]
30in-rust-tree = []
3031
3132[lints]
3233workspace = true
src/tools/rust-analyzer/crates/span/src/lib.rs+6
......@@ -1,4 +1,10 @@
11//! File and span related types.
2
3#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4
5#[cfg(feature = "in-rust-tree")]
6extern crate rustc_driver as _;
7
28use std::fmt::{self, Write};
39
410mod ast_id;
src/tools/rust-analyzer/crates/syntax-bridge/src/lib.rs+5
......@@ -1,5 +1,10 @@
11//! Conversions between [`SyntaxNode`] and [`tt::TokenTree`].
22
3#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4
5#[cfg(feature = "in-rust-tree")]
6extern crate rustc_driver as _;
7
38use std::{collections::VecDeque, fmt, hash::Hash};
49
510use intern::Symbol;
src/tools/rust-analyzer/crates/syntax/Cargo.toml+1
......@@ -33,6 +33,7 @@ rustc_apfloat = "0.2.3"
3333test-utils.workspace = true
3434
3535[features]
36default = []
3637in-rust-tree = []
3738
3839[lints]
src/tools/rust-analyzer/crates/syntax/src/lib.rs+5
......@@ -19,6 +19,11 @@
1919//! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
2020//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md>
2121
22#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
23
24#[cfg(feature = "in-rust-tree")]
25extern crate rustc_driver as _;
26
2227mod parsing;
2328mod ptr;
2429mod syntax_error;
src/tools/rust-analyzer/crates/test-fixture/Cargo.toml+4
......@@ -21,5 +21,9 @@ intern.workspace = true
2121triomphe.workspace = true
2222paths.workspace = true
2323
24[features]
25default = []
26in-rust-tree = []
27
2428[lints]
2529workspace = true
src/tools/rust-analyzer/crates/test-fixture/src/lib.rs+6
......@@ -1,4 +1,10 @@
11//! A set of high-level utility fixture methods to use in tests.
2
3#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4
5#[cfg(feature = "in-rust-tree")]
6extern crate rustc_driver as _;
7
28use std::{any::TypeId, mem, str::FromStr, sync};
39
410use base_db::target::TargetData;
src/tools/rust-analyzer/crates/tt/Cargo.toml+1
......@@ -21,6 +21,7 @@ intern.workspace = true
2121ra-ap-rustc_lexer.workspace = true
2222
2323[features]
24default = []
2425in-rust-tree = []
2526
2627[lints]
src/tools/rust-analyzer/crates/tt/src/lib.rs+3
......@@ -5,6 +5,9 @@
55
66#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
77
8#[cfg(feature = "in-rust-tree")]
9extern crate rustc_driver as _;
10
811#[cfg(not(feature = "in-rust-tree"))]
912extern crate ra_ap_rustc_lexer as rustc_lexer;
1013#[cfg(feature = "in-rust-tree")]