Skip to content

Commit 34d6571

Browse files
committed
Auto merge of rust-lang#136779 - jieyouxu:rahhh, r=<try>
[DO NOT MERGE] `./x test rust-analyzer` I somehow made `./x test rust-analyzer` work on my machine[^machine], **but at what cost?** Not intended for merge but only as a reference. If we do want to land this, I'll need to tidy this up. Notes: - I abused a bunch of cargo features `in-rust-tree`. It probably doesn't need to be, and simply `--cfg` might work. I was trying to get the main rust-analyzer tests to build *at all*. Anything building is already a miracle. - I had to slap a bunch of the following to all the r-a crates to get the tests to build at all. I don't 100% understand why, but otherwise I get a whole ton of ``expected `rustc_lexer` to be available in rlib format`` build failures. ```rs #![cfg_attr(feature = "in-rust-tree", feature(rustc_private))] #[cfg(all(feature = "in-rust-tree", test))] extern crate rustc_driver as _; ``` - Skipped one config test that was fixed on r-a master but not synced here in r-l/r yet. [^machine]: `x86_64-unknown-linux-gnu`, haven't bothered trying this on msvc yet. try-job: aarch64-gnu try-job: x86_64-apple-1 try-job: aarch64-apple try-job: i686-mingw-1 try-job: x86_64-mingw-1 try-job: i686-msvc-1 try-job: x86_64-msvc-1
2 parents 8c04e39 + 5ae6a16 commit 34d6571

File tree

39 files changed

+438
-155
lines changed

39 files changed

+438
-155
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+188-121
Large diffs are not rendered by default.

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

+108-20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::path::{Path, PathBuf};
99
use std::{env, fs, iter};
1010

1111
use clap_complete::shells;
12+
#[cfg(feature = "tracing")]
13+
use tracing::instrument;
1214

1315
use crate::core::build_steps::compile::run_cargo;
1416
use crate::core::build_steps::doc::DocumentationFormat;
@@ -28,7 +30,7 @@ use crate::utils::helpers::{
2830
linker_flags, t, target_supports_cranelift_backend, up_to_date,
2931
};
3032
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
31-
use crate::{CLang, DocTests, GitRepo, Mode, PathSet, envify};
33+
use crate::{CLang, DocTests, GitRepo, Mode, PathSet, debug, envify};
3234

3335
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
3436

@@ -354,50 +356,136 @@ impl Step for RustAnalyzer {
354356
const DEFAULT: bool = true;
355357

356358
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
357-
run.path("src/tools/rust-analyzer")
359+
run.path("src/tools/rust-analyzer").alias("rust-analyzer")
358360
}
359361

360362
fn make_run(run: RunConfig<'_>) {
361363
run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
362364
}
363365

364-
/// Runs `cargo test` for rust-analyzer
366+
#[cfg_attr(
367+
feature = "tracing",
368+
instrument(
369+
level = "debug",
370+
name = "RustAnalyzer::run",
371+
skip_all,
372+
fields(stage = self.stage, host = ?self.host),
373+
),
374+
)]
375+
fn run(self, builder: &Builder<'_>) {
376+
debug!(stage = self.stage, host = ?self.host, "ensuring compiler");
377+
let compiler = builder.compiler(self.stage, self.host);
378+
379+
debug!(stage = self.stage, host = ?self.host, "ensuring std");
380+
builder.ensure(compile::Rustc::new(compiler, self.host));
381+
382+
let mut cargo = tool::prepare_tool_cargo(
383+
builder,
384+
compiler,
385+
Mode::ToolRustc,
386+
self.host,
387+
Kind::Test,
388+
"src/tools/rust-analyzer",
389+
SourceType::InTree,
390+
&["in-rust-tree".to_owned()],
391+
);
392+
cargo.allow_features(tool::RustAnalyzer::ALLOW_FEATURES);
393+
394+
// RA's test suite tries to write to the source directory, that can't work in Rust CI.
395+
cargo.env("SKIP_SLOW_TESTS", "1");
396+
397+
// NOTE: unlike `proc-macro-srv` step, we must **not** set `CARGO_WORKSPACE_DIR` because I
398+
// believe `src/tools/rust-analyzer/.cargo/config.toml`'s relative `CARGO_WORKSPACE_DIR`
399+
// takes effect,
400+
401+
cargo.add_rustc_lib_path(builder);
402+
run_cargo_test(
403+
cargo,
404+
&[
405+
// FIXME: may need a fix from https://github.com/rust-lang/rust-analyzer/pull/19124.
406+
"--skip=config::tests::cargo_target_dir_subdir",
407+
],
408+
&[],
409+
"rust-analyzer",
410+
"rust-analyzer",
411+
self.host,
412+
builder,
413+
);
414+
}
415+
}
416+
417+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
418+
pub struct RustAnalyzerProcMacroSrv {
419+
stage: u32,
420+
host: TargetSelection,
421+
}
422+
423+
impl Step for RustAnalyzerProcMacroSrv {
424+
type Output = ();
425+
const ONLY_HOSTS: bool = true;
426+
const DEFAULT: bool = true;
427+
428+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
429+
run.path("src/tools/rust-analyzer/crates/proc-macro-srv").alias("rust-analyzer")
430+
}
431+
432+
fn make_run(run: RunConfig<'_>) {
433+
run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
434+
}
435+
436+
#[cfg_attr(
437+
feature = "tracing",
438+
instrument(
439+
level = "debug",
440+
name = "RustAnalyzerProcMacroSrv::run",
441+
skip_all,
442+
fields(stage = self.stage, host = ?self.host),
443+
),
444+
)]
365445
fn run(self, builder: &Builder<'_>) {
366446
let stage = self.stage;
367447
let host = self.host;
448+
449+
debug!(stage, ?host, "ensuring compiler");
368450
let compiler = builder.compiler(stage, host);
369451

370452
// We don't need to build the whole Rust Analyzer for the proc-macro-srv test suite,
371453
// but we do need the standard library to be present.
454+
debug!(stage, ?compiler, "ensuring std");
372455
builder.ensure(compile::Rustc::new(compiler, host));
373456

374-
let workspace_path = "src/tools/rust-analyzer";
375-
// until the whole RA test suite runs on `i686`, we only run
376-
// `proc-macro-srv` tests
377-
let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
457+
debug!("running `cargo test` on `src/tools/rust-analyzer/crates/proc-macro-srv`");
458+
378459
let mut cargo = tool::prepare_tool_cargo(
379460
builder,
380461
compiler,
381462
Mode::ToolRustc,
382463
host,
383464
Kind::Test,
384-
crate_path,
465+
"src/tools/rust-analyzer/crates/proc-macro-srv",
385466
SourceType::InTree,
386467
&["in-rust-tree".to_owned()],
387468
);
388469
cargo.allow_features(tool::RustAnalyzer::ALLOW_FEATURES);
389470

390-
let dir = builder.src.join(workspace_path);
391-
// needed by rust-analyzer to find its own text fixtures, cf.
392-
// https://github.com/rust-analyzer/expect-test/issues/33
471+
let dir = builder.src.join("src/tools/rust-analyzer");
472+
// Needed by rust-analyzer to find its own text fixtures, cf.
473+
// https://github.com/rust-analyzer/expect-test/issues/33.
393474
cargo.env("CARGO_WORKSPACE_DIR", &dir);
394475

395-
// RA's test suite tries to write to the source directory, that can't
396-
// work in Rust CI
476+
// RA's test suite tries to write to the source directory, that can't work in Rust CI.
397477
cargo.env("SKIP_SLOW_TESTS", "1");
398478

399479
cargo.add_rustc_lib_path(builder);
400-
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", host, builder);
480+
run_cargo_test(
481+
cargo,
482+
&[],
483+
&[],
484+
"rust-analyzer/crates/proc-macro-srv",
485+
"rust-analyzer proc-macro-srv",
486+
host,
487+
builder,
488+
);
401489
}
402490
}
403491

@@ -2618,14 +2706,14 @@ fn prepare_cargo_test(
26182706
cargo.arg("--quiet");
26192707
}
26202708

2621-
// The tests are going to run with the *target* libraries, so we need to
2622-
// ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2709+
// The tests are going to run with the *target* libraries, so we need to ensure that those
2710+
// libraries show up in the LD_LIBRARY_PATH equivalent.
26232711
//
2624-
// Note that to run the compiler we need to run with the *host* libraries,
2625-
// but our wrapper scripts arrange for that to be the case anyway.
2712+
// Note that to run the compiler we need to run with the *host* libraries, but our wrapper
2713+
// scripts arrange for that to be the case anyway.
26262714
//
2627-
// We skip everything on Miri as then this overwrites the libdir set up
2628-
// by `Cargo::new` and that actually makes things go wrong.
2715+
// We skip everything on Miri as then this overwrites the libdir set up by `Cargo::new` and that
2716+
// actually makes things go wrong.
26292717
if builder.kind != Kind::Miri {
26302718
let mut dylib_path = dylib_path();
26312719
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_target_libdir(compiler, target)));

src/bootstrap/src/core/builder/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::core::config::{DryRun, TargetSelection};
2121
use crate::utils::cache::Cache;
2222
use crate::utils::exec::{BootstrapCommand, command};
2323
use crate::utils::helpers::{self, LldThreads, add_dylib_path, exe, libdir, linker_args, t};
24-
use crate::{Build, Crate};
24+
use crate::{Build, Crate, trace};
2525

2626
mod cargo;
2727

@@ -971,6 +971,7 @@ impl<'a> Builder<'a> {
971971
test::Cargotest,
972972
test::Cargo,
973973
test::RustAnalyzer,
974+
test::RustAnalyzerProcMacroSrv,
974975
test::ErrorIndex,
975976
test::Distcheck,
976977
test::Nomicon,
@@ -1215,7 +1216,7 @@ impl<'a> Builder<'a> {
12151216
/// `Compiler` since all `Compiler` instances are meant to be obtained through this function,
12161217
/// since it ensures that they are valid (i.e., built and assembled).
12171218
pub fn compiler(&self, stage: u32, host: TargetSelection) -> Compiler {
1218-
self.ensure(compile::Assemble { target_compiler: Compiler { stage, host } })
1219+
self.ensure(compile::Assemble { output_compiler: Compiler { stage, host } })
12191220
}
12201221

12211222
/// Similar to `compiler`, except handles the full-bootstrap option to
@@ -1331,6 +1332,8 @@ impl<'a> Builder<'a> {
13311332
return;
13321333
}
13331334

1335+
trace!(rustc_lib_paths = ?self.rustc_lib_paths(compiler));
1336+
13341337
add_dylib_path(self.rustc_lib_paths(compiler), cmd);
13351338
}
13361339

src/bootstrap/src/core/builder/tests.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ mod defaults {
350350
assert_eq!(
351351
first(cache.all::<compile::Assemble>()),
352352
&[
353-
compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
354-
compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
355-
compile::Assemble { target_compiler: Compiler { host: b, stage: 1 } },
353+
compile::Assemble { output_compiler: Compiler { host: a, stage: 0 } },
354+
compile::Assemble { output_compiler: Compiler { host: a, stage: 1 } },
355+
compile::Assemble { output_compiler: Compiler { host: b, stage: 1 } },
356356
]
357357
);
358358
assert_eq!(
@@ -630,10 +630,10 @@ mod dist {
630630
assert_eq!(
631631
first(cache.all::<compile::Assemble>()),
632632
&[
633-
compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
634-
compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
635-
compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
636-
compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
633+
compile::Assemble { output_compiler: Compiler { host: a, stage: 0 } },
634+
compile::Assemble { output_compiler: Compiler { host: a, stage: 1 } },
635+
compile::Assemble { output_compiler: Compiler { host: a, stage: 2 } },
636+
compile::Assemble { output_compiler: Compiler { host: b, stage: 2 } },
637637
]
638638
);
639639
}
@@ -711,9 +711,9 @@ mod dist {
711711
assert_eq!(
712712
first(builder.cache.all::<compile::Assemble>()),
713713
&[
714-
compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
715-
compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
716-
compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
714+
compile::Assemble { output_compiler: Compiler { host: a, stage: 0 } },
715+
compile::Assemble { output_compiler: Compiler { host: a, stage: 1 } },
716+
compile::Assemble { output_compiler: Compiler { host: a, stage: 2 } },
717717
]
718718
);
719719
assert_eq!(

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

+3
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ vfs.workspace = true
3030
span.workspace = true
3131
intern.workspace = true
3232

33+
[features]
34+
in-rust-tree = []
35+
3336
[lints]
3437
workspace = true

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

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//! base_db defines basic database traits. The concrete DB is defined by ide.
2+
3+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4+
#[cfg(all(feature = "in-rust-tree", test))]
5+
extern crate rustc_driver as _;
6+
27
// FIXME: Rename this crate, base db is non descriptive
38
mod change;
49
mod input;

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

+4
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ derive_arbitrary = "1.3.2"
3333
syntax-bridge.workspace = true
3434
syntax.workspace = true
3535

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! cfg defines conditional compiling options, `cfg` attribute parser and evaluator
22
3+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4+
#[cfg(all(feature = "in-rust-tree", test))]
5+
extern crate rustc_driver as _;
6+
37
mod cfg_expr;
48
mod dnf;
59
#[cfg(test)]

src/tools/rust-analyzer/crates/hir-def/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ expect-test.workspace = true
5454
test-utils.workspace = true
5555
test-fixture.workspace = true
5656
syntax-bridge.workspace = true
57+
5758
[features]
5859
in-rust-tree = ["hir-expand/in-rust-tree"]
5960

src/tools/rust-analyzer/crates/hir-def/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
//! actually true.
99
1010
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
11+
#[cfg(all(feature = "in-rust-tree", test))]
12+
extern crate rustc_driver as _;
1113

1214
#[cfg(feature = "in-rust-tree")]
1315
extern crate rustc_parse_format;

src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
//! Specifically, it implements a concept of `MacroFile` -- a file whose syntax
44
//! tree originates not from the text of some `FileId`, but from some macro
55
//! expansion.
6+
67
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
78

9+
#[cfg_attr(all(feature = "in-rust-tree", test), allow(unused_extern_crates))]
10+
#[cfg(all(feature = "in-rust-tree", test))]
11+
extern crate rustc_driver;
12+
813
pub mod attrs;
914
pub mod builtin;
1015
pub mod change;

src/tools/rust-analyzer/crates/hir-ty/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//! information and various assists.
33
44
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
5+
#[cfg(all(feature = "in-rust-tree", test))]
6+
extern crate rustc_driver as _;
57

68
#[cfg(feature = "in-rust-tree")]
79
extern crate rustc_index;

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
//! from the ide with completions, hovers, etc. It is a (soft, internal) boundary:
1818
//! <https://www.tedinski.com/2018/02/06/system-boundaries.html>.
1919
20-
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
2120
#![recursion_limit = "512"]
2221

22+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
23+
#[cfg(all(feature = "in-rust-tree", test))]
24+
extern crate rustc_driver as _;
25+
2326
mod attrs;
2427
mod from_id;
2528
mod has_source;

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

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
//! <https://rust-analyzer.github.io/blog/2020/09/28/how-to-make-a-light-bulb.html>
6060
6161
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
62+
#[cfg(all(feature = "in-rust-tree", test))]
63+
extern crate rustc_driver as _;
6264

6365
mod assist_config;
6466
mod assist_context;

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

+4
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@ expect-test = "1.4.0"
3636
test-utils.workspace = true
3737
test-fixture.workspace = true
3838

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! `completions` crate provides utilities for generating completions of user input.
22
3+
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
4+
#[cfg(all(feature = "in-rust-tree", test))]
5+
extern crate rustc_driver as _;
6+
37
mod completions;
48
mod config;
59
mod context;

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

+4
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,9 @@ expect-test = "1.4.0"
4949
test-utils.workspace = true
5050
test-fixture.workspace = true
5151

52+
[features]
53+
default = []
54+
in-rust-tree = []
55+
5256
[lints]
5357
workspace = true

0 commit comments

Comments
 (0)