Skip to content

Commit

Permalink
Rollup merge of #101873 - WaffleLapkin:x-build-proc-macro-srv, r=jyn514
Browse files Browse the repository at this point in the history
Allow building `rust-analyzer-proc-macro-srv` as a standalone tool

This PR allows building `rust-analyzer-proc-macro-srv` as a standalone tool via `x b proc-macro-srv-cli` (I thought that `x b rust-analyzer-proc-macro-srv` should work, but it doesn't for some reason...). Also this PR adds a copy of `rust-analyzer-proc-macro-srv` binary to `build/{triple}/{stage}/libexec/` when building `rust-analyzer-proc-macro-srv`, so that r-a can pick it up.

This is useful to make r-a (and I assume Intellij IDEA) to expand macros when using a custom, build from source toolchain.

r? ``@jyn514``
[_zulip thread_](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/How.20to.20fix.20.60UnsupportedABI.60.20for.20custom.20toolchains.3F/near/299040175)
  • Loading branch information
matthiaskrgr authored Sep 17, 2022
2 parents 92d8bf9 + 9c3c88c commit 179fd13
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,14 +746,18 @@ impl Step for RustAnalyzerProcMacroSrv {

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
run.path("src/tools/rust-analyzer").default_condition(
builder.config.extended
&& builder
.config
.tools
.as_ref()
.map_or(true, |tools| tools.iter().any(|tool| tool == "rust-analyzer")),
)

// Allow building `rust-analyzer-proc-macro-srv` both as part of the `rust-analyzer` and as a stand-alone tool.
run.path("src/tools/rust-analyzer")
.path("src/tools/rust-analyzer/crates/proc-macro-srv-cli")
.default_condition(
builder.config.extended
&& builder.config.tools.as_ref().map_or(true, |tools| {
tools.iter().any(|tool| {
tool == "rust-analyzer" || tool == "rust-analyzer-proc-macro-srv"
})
}),
)
}

fn make_run(run: RunConfig<'_>) {
Expand All @@ -764,7 +768,7 @@ impl Step for RustAnalyzerProcMacroSrv {
}

fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
builder.ensure(ToolBuild {
let path = builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.target,
tool: "rust-analyzer-proc-macro-srv",
Expand All @@ -773,7 +777,15 @@ impl Step for RustAnalyzerProcMacroSrv {
extra_features: vec!["proc-macro-srv/sysroot-abi".to_owned()],
is_optional_tool: false,
source_type: SourceType::InTree,
})
})?;

// Copy `rust-analyzer-proc-macro-srv` to `<sysroot>/libexec/`
// so that r-a can use it.
let libexec_path = builder.sysroot(self.compiler).join("libexec");
t!(fs::create_dir_all(&libexec_path));
builder.copy(&path, &libexec_path.join("rust-analyzer-proc-macro-srv"));

Some(path)
}
}

Expand Down

0 comments on commit 179fd13

Please sign in to comment.