@@ -9,6 +9,8 @@ use std::path::{Path, PathBuf};
99use std:: { env, fs, iter} ;
1010
1111use clap_complete:: shells;
12+ #[ cfg( feature = "tracing" ) ]
13+ use tracing:: instrument;
1214
1315use crate :: core:: build_steps:: compile:: run_cargo;
1416use 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} ;
3032use 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
3335const 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) ) ) ;
0 commit comments