Skip to content

Commit 0cd7ff7

Browse files
committed
Auto merge of #72978 - matklad:ship-rust-analyzer, r=Mark-Simulacrum
ship rust analyzer This successfully builds rust-analyzer as a part of rust repo. I haven't yet added required changes to dist.rs -- seems like I just have to copy-paste quite a bit of code I don't really understand :-)
2 parents dbf3ae7 + 058c1b6 commit 0cd7ff7

File tree

10 files changed

+155
-3
lines changed

10 files changed

+155
-3
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@
4141
[submodule "src/doc/embedded-book"]
4242
path = src/doc/embedded-book
4343
url = https://github.com/rust-embedded/book.git
44+
[submodule "src/tools/rust-analyzer"]
45+
path = src/tools/rust-analyzer
46+
url = https://github.com/rust-analyzer/rust-analyzer.git

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ignore = [
2727
"src/tools/clippy",
2828
"src/tools/miri",
2929
"src/tools/rls",
30+
"src/tools/rust-analyzer",
3031
"src/tools/rust-installer",
3132
"src/tools/rustfmt",
3233

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def ensure_vendored(self):
869869
# the rust git repository is updated. Normal development usually does
870870
# not use vendoring, so hopefully this isn't too much of a problem.
871871
if self.use_vendored_sources and not os.path.exists(vendor_dir):
872-
run([self.cargo(), "vendor"],
872+
run([self.cargo(), "vendor", "--sync=./src/tools/rust-analyzer/Cargo.toml"],
873873
verbose=self.verbose, cwd=self.rust_root)
874874

875875

src/bootstrap/builder.rs

+3
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ impl<'a> Builder<'a> {
368368
tool::RustInstaller,
369369
tool::Cargo,
370370
tool::Rls,
371+
tool::RustAnalyzer,
371372
tool::Rustdoc,
372373
tool::Clippy,
373374
tool::CargoClippy,
@@ -462,6 +463,7 @@ impl<'a> Builder<'a> {
462463
dist::PlainSourceTarball,
463464
dist::Cargo,
464465
dist::Rls,
466+
dist::RustAnalyzer,
465467
dist::Rustfmt,
466468
dist::Clippy,
467469
dist::Miri,
@@ -474,6 +476,7 @@ impl<'a> Builder<'a> {
474476
install::Std,
475477
install::Cargo,
476478
install::Rls,
479+
install::RustAnalyzer,
477480
install::Rustfmt,
478481
install::Clippy,
479482
install::Miri,

src/bootstrap/dist.rs

+121-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub fn pkgname(builder: &Builder<'_>, component: &str) -> String {
3030
format!("{}-{}", component, builder.cargo_package_vers())
3131
} else if component == "rls" {
3232
format!("{}-{}", component, builder.rls_package_vers())
33+
} else if component == "rust-analyzer" {
34+
format!("{}-{}", component, builder.rust_analyzer_package_vers())
3335
} else if component == "clippy" {
3436
format!("{}-{}", component, builder.clippy_package_vers())
3537
} else if component == "miri" {
@@ -1107,7 +1109,10 @@ impl Step for PlainSourceTarball {
11071109
if builder.rust_info.is_git() {
11081110
// Vendor all Cargo dependencies
11091111
let mut cmd = Command::new(&builder.initial_cargo);
1110-
cmd.arg("vendor").current_dir(&plain_dst_src);
1112+
cmd.arg("vendor")
1113+
.arg("--sync")
1114+
.arg(builder.src.join("./src/tools/rust-analyzer/Cargo.toml"))
1115+
.current_dir(&plain_dst_src);
11111116
builder.run(&mut cmd);
11121117
}
11131118

@@ -1337,6 +1342,93 @@ impl Step for Rls {
13371342
}
13381343
}
13391344

1345+
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1346+
pub struct RustAnalyzer {
1347+
pub compiler: Compiler,
1348+
pub target: Interned<String>,
1349+
}
1350+
1351+
impl Step for RustAnalyzer {
1352+
type Output = PathBuf;
1353+
const ONLY_HOSTS: bool = true;
1354+
1355+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1356+
run.path("rust-analyzer")
1357+
}
1358+
1359+
fn make_run(run: RunConfig<'_>) {
1360+
run.builder.ensure(RustAnalyzer {
1361+
compiler: run.builder.compiler_for(
1362+
run.builder.top_stage,
1363+
run.builder.config.build,
1364+
run.target,
1365+
),
1366+
target: run.target,
1367+
});
1368+
}
1369+
1370+
fn run(self, builder: &Builder<'_>) -> PathBuf {
1371+
let compiler = self.compiler;
1372+
let target = self.target;
1373+
assert!(builder.config.extended);
1374+
1375+
let src = builder.src.join("src/tools/rust-analyzer");
1376+
let release_num = builder.release_num("rust-analyzer/crates/rust-analyzer");
1377+
let name = pkgname(builder, "rust-analyzer");
1378+
let version = builder.rust_analyzer_info.version(builder, &release_num);
1379+
1380+
let tmp = tmpdir(builder);
1381+
let image = tmp.join("rust-analyzer-image");
1382+
drop(fs::remove_dir_all(&image));
1383+
builder.create_dir(&image);
1384+
1385+
// Prepare the image directory
1386+
// We expect rust-analyer to always build, as it doesn't depend on rustc internals
1387+
// and doesn't have associated toolstate.
1388+
let rust_analyzer = builder
1389+
.ensure(tool::RustAnalyzer { compiler, target, extra_features: Vec::new() })
1390+
.expect("rust-analyzer always builds");
1391+
1392+
builder.install(&rust_analyzer, &image.join("bin"), 0o755);
1393+
let doc = image.join("share/doc/rust-analyzer");
1394+
builder.install(&src.join("README.md"), &doc, 0o644);
1395+
builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1396+
builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1397+
1398+
// Prepare the overlay
1399+
let overlay = tmp.join("rust-analyzer-overlay");
1400+
drop(fs::remove_dir_all(&overlay));
1401+
t!(fs::create_dir_all(&overlay));
1402+
builder.install(&src.join("README.md"), &overlay, 0o644);
1403+
builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1404+
builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
1405+
builder.create(&overlay.join("version"), &version);
1406+
1407+
// Generate the installer tarball
1408+
let mut cmd = rust_installer(builder);
1409+
cmd.arg("generate")
1410+
.arg("--product-name=Rust")
1411+
.arg("--rel-manifest-dir=rustlib")
1412+
.arg("--success-message=rust-analyzer-ready-to-serve.")
1413+
.arg("--image-dir")
1414+
.arg(&image)
1415+
.arg("--work-dir")
1416+
.arg(&tmpdir(builder))
1417+
.arg("--output-dir")
1418+
.arg(&distdir(builder))
1419+
.arg("--non-installed-overlay")
1420+
.arg(&overlay)
1421+
.arg(format!("--package-name={}-{}", name, target))
1422+
.arg("--legacy-manifest-dirs=rustlib,cargo")
1423+
.arg("--component-name=rust-analyzer-preview");
1424+
1425+
builder.info(&format!("Dist rust-analyzer stage{} ({})", compiler.stage, target));
1426+
let _time = timeit(builder);
1427+
builder.run(&mut cmd);
1428+
distdir(builder).join(format!("{}-{}.tar.gz", name, target))
1429+
}
1430+
}
1431+
13401432
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
13411433
pub struct Clippy {
13421434
pub compiler: Compiler,
@@ -1656,6 +1748,7 @@ impl Step for Extended {
16561748
let cargo_installer = builder.ensure(Cargo { compiler, target });
16571749
let rustfmt_installer = builder.ensure(Rustfmt { compiler, target });
16581750
let rls_installer = builder.ensure(Rls { compiler, target });
1751+
let rust_analyzer_installer = builder.ensure(RustAnalyzer { compiler, target });
16591752
let llvm_tools_installer = builder.ensure(LlvmTools { target });
16601753
let clippy_installer = builder.ensure(Clippy { compiler, target });
16611754
let miri_installer = builder.ensure(Miri { compiler, target });
@@ -1690,6 +1783,7 @@ impl Step for Extended {
16901783
tarballs.push(rustc_installer);
16911784
tarballs.push(cargo_installer);
16921785
tarballs.extend(rls_installer.clone());
1786+
tarballs.push(rust_analyzer_installer.clone());
16931787
tarballs.push(clippy_installer);
16941788
tarballs.extend(miri_installer.clone());
16951789
tarballs.extend(rustfmt_installer.clone());
@@ -1767,6 +1861,7 @@ impl Step for Extended {
17671861
if rls_installer.is_none() {
17681862
contents = filter(&contents, "rls");
17691863
}
1864+
contents = filter(&contents, "rust-analyzer");
17701865
if miri_installer.is_none() {
17711866
contents = filter(&contents, "miri");
17721867
}
@@ -1813,6 +1908,7 @@ impl Step for Extended {
18131908
if rls_installer.is_some() {
18141909
prepare("rls");
18151910
}
1911+
prepare("rust-analyzer");
18161912
if miri_installer.is_some() {
18171913
prepare("miri");
18181914
}
@@ -1846,6 +1942,8 @@ impl Step for Extended {
18461942
format!("{}-{}", name, target)
18471943
} else if name == "rls" {
18481944
"rls-preview".to_string()
1945+
} else if name == "rust-analyzer" {
1946+
"rust-analyzer-preview".to_string()
18491947
} else if name == "clippy" {
18501948
"clippy-preview".to_string()
18511949
} else if name == "miri" {
@@ -1868,6 +1966,7 @@ impl Step for Extended {
18681966
if rls_installer.is_some() {
18691967
prepare("rls");
18701968
}
1969+
prepare("rust-analyzer");
18711970
if miri_installer.is_some() {
18721971
prepare("miri");
18731972
}
@@ -1967,6 +2066,23 @@ impl Step for Extended {
19672066
.arg(etc.join("msi/remove-duplicates.xsl")),
19682067
);
19692068
}
2069+
builder.run(
2070+
Command::new(&heat)
2071+
.current_dir(&exe)
2072+
.arg("dir")
2073+
.arg("rust-analyzer")
2074+
.args(&heat_flags)
2075+
.arg("-cg")
2076+
.arg("RustAnalyzerGroup")
2077+
.arg("-dr")
2078+
.arg("RustAnalyzer")
2079+
.arg("-var")
2080+
.arg("var.RustAnalyzerDir")
2081+
.arg("-out")
2082+
.arg(exe.join("RustAnalyzerGroup.wxs"))
2083+
.arg("-t")
2084+
.arg(etc.join("msi/remove-duplicates.xsl")),
2085+
);
19702086
builder.run(
19712087
Command::new(&heat)
19722088
.current_dir(&exe)
@@ -2060,6 +2176,7 @@ impl Step for Extended {
20602176
if rls_installer.is_some() {
20612177
cmd.arg("-dRlsDir=rls");
20622178
}
2179+
cmd.arg("-dRustAnalyzerDir=rust-analyzer");
20632180
if miri_installer.is_some() {
20642181
cmd.arg("-dMiriDir=miri");
20652182
}
@@ -2079,6 +2196,7 @@ impl Step for Extended {
20792196
if rls_installer.is_some() {
20802197
candle("RlsGroup.wxs".as_ref());
20812198
}
2199+
candle("RustAnalyzerGroup.wxs".as_ref());
20822200
if miri_installer.is_some() {
20832201
candle("MiriGroup.wxs".as_ref());
20842202
}
@@ -2116,6 +2234,7 @@ impl Step for Extended {
21162234
if rls_installer.is_some() {
21172235
cmd.arg("RlsGroup.wixobj");
21182236
}
2237+
cmd.arg("RustAnalyzerGroup.wixobj");
21192238
if miri_installer.is_some() {
21202239
cmd.arg("MiriGroup.wixobj");
21212240
}
@@ -2209,6 +2328,7 @@ impl Step for HashSign {
22092328
cmd.arg(addr);
22102329
cmd.arg(builder.package_vers(&builder.release_num("cargo")));
22112330
cmd.arg(builder.package_vers(&builder.release_num("rls")));
2331+
cmd.arg(builder.package_vers(&builder.release_num("rust-analyzer/crates/rust-analyzer")));
22122332
cmd.arg(builder.package_vers(&builder.release_num("clippy")));
22132333
cmd.arg(builder.package_vers(&builder.release_num("miri")));
22142334
cmd.arg(builder.package_vers(&builder.release_num("rustfmt")));

src/bootstrap/install.rs

+13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub fn install_cargo(builder: &Builder<'_>, stage: u32, host: Interned<String>)
3232
pub fn install_rls(builder: &Builder<'_>, stage: u32, host: Interned<String>) {
3333
install_sh(builder, "rls", "rls", stage, Some(host));
3434
}
35+
pub fn install_rust_analyzer(builder: &Builder<'_>, stage: u32, host: Interned<String>) {
36+
install_sh(builder, "rust-analyzer", "rust-analyzer", stage, Some(host));
37+
}
3538
pub fn install_clippy(builder: &Builder<'_>, stage: u32, host: Interned<String>) {
3639
install_sh(builder, "clippy", "clippy", stage, Some(host));
3740
}
@@ -216,6 +219,16 @@ install!((self, builder, _config),
216219
);
217220
}
218221
};
222+
RustAnalyzer, "rust-analyzer", Self::should_build(_config), only_hosts: true, {
223+
builder.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target });
224+
if Self::should_install(builder) {
225+
install_rust_analyzer(builder, self.compiler.stage, self.target);
226+
} else {
227+
builder.info(
228+
&format!("skipping Install rust-analyzer stage{} ({})", self.compiler.stage, self.target),
229+
);
230+
}
231+
};
219232
Clippy, "clippy", Self::should_build(_config), only_hosts: true, {
220233
builder.ensure(dist::Clippy { compiler: self.compiler, target: self.target });
221234
if Self::should_install(builder) {

src/bootstrap/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ pub struct Build {
225225
rust_info: channel::GitInfo,
226226
cargo_info: channel::GitInfo,
227227
rls_info: channel::GitInfo,
228+
rust_analyzer_info: channel::GitInfo,
228229
clippy_info: channel::GitInfo,
229230
miri_info: channel::GitInfo,
230231
rustfmt_info: channel::GitInfo,
@@ -349,6 +350,8 @@ impl Build {
349350
let rust_info = channel::GitInfo::new(ignore_git, &src);
350351
let cargo_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/cargo"));
351352
let rls_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/rls"));
353+
let rust_analyzer_info =
354+
channel::GitInfo::new(ignore_git, &src.join("src/tools/rust-analyzer"));
352355
let clippy_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/clippy"));
353356
let miri_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/miri"));
354357
let rustfmt_info = channel::GitInfo::new(ignore_git, &src.join("src/tools/rustfmt"));
@@ -405,6 +408,7 @@ impl Build {
405408
rust_info,
406409
cargo_info,
407410
rls_info,
411+
rust_analyzer_info,
408412
clippy_info,
409413
miri_info,
410414
rustfmt_info,
@@ -1034,6 +1038,11 @@ impl Build {
10341038
self.package_vers(&self.release_num("rls"))
10351039
}
10361040

1041+
/// Returns the value of `package_vers` above for rust-analyzer
1042+
fn rust_analyzer_package_vers(&self) -> String {
1043+
self.package_vers(&self.release_num("rust-analyzer/crates/rust-analyzer"))
1044+
}
1045+
10371046
/// Returns the value of `package_vers` above for clippy
10381047
fn clippy_package_vers(&self) -> String {
10391048
self.package_vers(&self.release_num("clippy"))

src/bootstrap/tool.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ macro_rules! tool_extended {
641641
}
642642
}
643643

644-
// Note: tools need to be also added to `Builder::get_step_descriptions` in `build.rs`
644+
// Note: tools need to be also added to `Builder::get_step_descriptions` in `builder.rs`
645645
// to make `./x.py build <tool>` work.
646646
tool_extended!((self, builder),
647647
Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, {};
@@ -658,6 +658,7 @@ tool_extended!((self, builder),
658658
self.extra_features.push("clippy".to_owned());
659659
};
660660
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, {};
661+
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=false, {};
661662
);
662663

663664
impl<'a> Builder<'a> {

src/tools/rust-analyzer

Submodule rust-analyzer added at f5a4a4b

src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fn filter_dirs(path: &Path) -> bool {
5656
"src/tools/clippy",
5757
"src/tools/miri",
5858
"src/tools/rls",
59+
"src/tools/rust-analyzer",
5960
"src/tools/rust-installer",
6061
"src/tools/rustfmt",
6162
"src/doc/book",

0 commit comments

Comments
 (0)