From 7b41008ee03cf805ea888e5d3063de7b093eb302 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 4 Jan 2024 11:02:20 +0100 Subject: [PATCH 1/5] Set the `in-rust-tree`` feature for all rust-analyzer{-proc-macro-srv} steps --- src/bootstrap/src/core/build_steps/check.rs | 2 +- src/bootstrap/src/core/build_steps/test.rs | 2 +- src/bootstrap/src/core/build_steps/tool.rs | 6 +++--- src/tools/rust-analyzer/crates/mbe/Cargo.toml | 5 ++++- .../rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml | 2 ++ src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml | 5 +++-- src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs | 3 ++- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index ecaaf91aec12f..f1f2f28909dee 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -386,7 +386,7 @@ impl Step for RustAnalyzer { cargo_subcommand(builder.kind), "src/tools/rust-analyzer", SourceType::InTree, - &["rust-analyzer/in-rust-tree".to_owned()], + &["in-rust-tree".to_owned()], ); cargo.allow_features(crate::core::build_steps::tool::RustAnalyzer::ALLOW_FEATURES); diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 92140b00da843..0f5ed1ceabdaa 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -385,7 +385,7 @@ impl Step for RustAnalyzer { "test", crate_path, SourceType::InTree, - &["sysroot-abi".to_owned()], + &["sysroot-abi".to_owned(), "in-rust-tree".to_owned()], ); cargo.allow_features(tool::RustAnalyzer::ALLOW_FEATURES); diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 8a9197d75d7b9..6c3f1b359c05c 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -628,7 +628,7 @@ impl Step for RustAnalyzer { tool: "rust-analyzer", mode: Mode::ToolRustc, path: "src/tools/rust-analyzer", - extra_features: vec!["rust-analyzer/in-rust-tree".to_owned()], + extra_features: vec!["in-rust-tree".to_owned()], source_type: SourceType::InTree, allow_features: RustAnalyzer::ALLOW_FEATURES, }) @@ -673,9 +673,9 @@ impl Step for RustAnalyzerProcMacroSrv { compiler: self.compiler, target: self.target, tool: "rust-analyzer-proc-macro-srv", - mode: Mode::ToolStd, + mode: Mode::ToolRustc, path: "src/tools/rust-analyzer/crates/proc-macro-srv-cli", - extra_features: vec!["sysroot-abi".to_owned()], + extra_features: vec!["sysroot-abi".to_owned(), "in-rust-tree".to_owned()], source_type: SourceType::InTree, allow_features: RustAnalyzer::ALLOW_FEATURES, }); diff --git a/src/tools/rust-analyzer/crates/mbe/Cargo.toml b/src/tools/rust-analyzer/crates/mbe/Cargo.toml index f50d796e139f1..2046fa943a8a1 100644 --- a/src/tools/rust-analyzer/crates/mbe/Cargo.toml +++ b/src/tools/rust-analyzer/crates/mbe/Cargo.toml @@ -27,5 +27,8 @@ span.workspace = true [dev-dependencies] test-utils.workspace = true +[features] +in-rust-tree = ["parser/in-rust-tree", "syntax/in-rust-tree"] + [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml index 980eab2696bfa..b9e4e534924b4 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml +++ b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml @@ -14,6 +14,8 @@ proc-macro-api.workspace = true [features] sysroot-abi = ["proc-macro-srv/sysroot-abi"] +in-rust-tree = ["proc-macro-srv/in-rust-tree"] + [[bin]] name = "rust-analyzer-proc-macro-srv" diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml index b6686fa5b65d3..54dae4eba9652 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml @@ -37,7 +37,8 @@ expect-test = "1.4.0" proc-macro-test.path = "./proc-macro-test" [features] -sysroot-abi = ["proc-macro-test/sysroot-abi"] +sysroot-abi = [] +in-rust-tree = ["mbe/in-rust-tree"] [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs index 7cd6df2df86d0..f1575a5b0bd83 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs @@ -11,11 +11,12 @@ //! rustc rather than `unstable`. (Although in general ABI compatibility is still an issue)… #![cfg(any(feature = "sysroot-abi", rust_analyzer))] -#![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span)] +#![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span, rustc_private)] #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(unreachable_pub, internal_features)] extern crate proc_macro; +extern crate rustc_driver as _; mod dylib; mod server; From 9a9ba92b2882ad00c8391a41196c80368c68cfdc Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 1 Jan 2024 14:37:33 +0100 Subject: [PATCH 2/5] Imply sysroot-abi feature when in-rust-tree is set --- src/bootstrap/src/core/build_steps/test.rs | 2 +- src/bootstrap/src/core/build_steps/tool.rs | 2 +- src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 0f5ed1ceabdaa..f9d401b44cee0 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -385,7 +385,7 @@ impl Step for RustAnalyzer { "test", crate_path, SourceType::InTree, - &["sysroot-abi".to_owned(), "in-rust-tree".to_owned()], + &["in-rust-tree".to_owned()], ); cargo.allow_features(tool::RustAnalyzer::ALLOW_FEATURES); diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 6c3f1b359c05c..5d8d10a7debc3 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -675,7 +675,7 @@ impl Step for RustAnalyzerProcMacroSrv { tool: "rust-analyzer-proc-macro-srv", mode: Mode::ToolRustc, path: "src/tools/rust-analyzer/crates/proc-macro-srv-cli", - extra_features: vec!["sysroot-abi".to_owned(), "in-rust-tree".to_owned()], + extra_features: vec!["in-rust-tree".to_owned()], source_type: SourceType::InTree, allow_features: RustAnalyzer::ALLOW_FEATURES, }); diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml index 54dae4eba9652..ba17ea6f7b439 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml @@ -38,7 +38,7 @@ proc-macro-test.path = "./proc-macro-test" [features] sysroot-abi = [] -in-rust-tree = ["mbe/in-rust-tree"] +in-rust-tree = ["mbe/in-rust-tree", "sysroot-abi"] [lints] workspace = true From 80095aac61abbf167a63bffb595ec438a163e14e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 1 Jan 2024 14:58:26 +0100 Subject: [PATCH 3/5] Add extern crate rustc_driver to proc-macro-srv-cli --- src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml | 2 +- src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs | 4 ++++ src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs | 3 +-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml index b9e4e534924b4..2caa24b703282 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml +++ b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml @@ -22,4 +22,4 @@ name = "rust-analyzer-proc-macro-srv" path = "src/main.rs" [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs index 000a526e9f99d..87f7555b02ce4 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/src/main.rs @@ -1,5 +1,9 @@ //! A standalone binary for `proc-macro-srv`. //! Driver for proc macro server +#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))] +#[cfg(feature = "in-rust-tree")] +extern crate rustc_driver as _; + use std::io; fn main() -> std::io::Result<()> { diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs index 6f40a4c88ed84..7432f0f7a7ce1 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs @@ -5,8 +5,7 @@ #![warn(rust_2018_idioms, unused_lifetimes)] #![cfg_attr(feature = "in-rust-tree", feature(rustc_private))] #[cfg(feature = "in-rust-tree")] -#[allow(unused_extern_crates)] -extern crate rustc_driver; +extern crate rustc_driver as _; mod logger; mod rustc_wrapper; From 3e3d08c843c5a84f30d884ad3bee5af17027af4d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 4 Jan 2024 10:44:18 +0100 Subject: [PATCH 4/5] Set sysroot-abi flag for proc-macro-cli when in-rust-tree is set --- src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml index 2caa24b703282..a559ba0175565 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml +++ b/src/tools/rust-analyzer/crates/proc-macro-srv-cli/Cargo.toml @@ -14,7 +14,7 @@ proc-macro-api.workspace = true [features] sysroot-abi = ["proc-macro-srv/sysroot-abi"] -in-rust-tree = ["proc-macro-srv/in-rust-tree"] +in-rust-tree = ["proc-macro-srv/in-rust-tree", "sysroot-abi"] [[bin]] From abf08229aefc2105a9570274b556189a176d3b58 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 4 Jan 2024 15:12:57 +0100 Subject: [PATCH 5/5] Set proc-macro-test/sysroot-abi with proc-macro-srv/sysroot-abi --- src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml index ba17ea6f7b439..9c4375559c11b 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml @@ -37,7 +37,7 @@ expect-test = "1.4.0" proc-macro-test.path = "./proc-macro-test" [features] -sysroot-abi = [] +sysroot-abi = ["proc-macro-test/sysroot-abi"] in-rust-tree = ["mbe/in-rust-tree", "sysroot-abi"] [lints]