Skip to content

Commit c55325e

Browse files
committed
Build an RLS package as part of the dist target
1 parent 7da12c8 commit c55325e

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

src/bootstrap/dist.rs

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ pub fn rust_src(build: &Build) {
393393
"man",
394394
"src",
395395
"cargo",
396+
"rls",
396397
];
397398

398399
let filter_fn = move |path: &Path| {
@@ -593,6 +594,43 @@ pub fn cargo(build: &Build, stage: u32, target: &str) {
593594
build.run(&mut cmd);
594595
}
595596

597+
pub fn rls(build: &Build, stage: u32, target: &str) {
598+
println!("Dist RLS stage{} ({})", stage, target);
599+
let compiler = Compiler::new(stage, &build.config.build);
600+
601+
let src = build.src.join("rls");
602+
let release_num = build.rls_release_num();
603+
let name = format!("rls-{}", build.package_vers(&release_num));
604+
605+
let tmp = tmpdir(build);
606+
let image = tmp.join("rls-image");
607+
drop(fs::remove_dir_all(&image));
608+
t!(fs::create_dir_all(&image));
609+
610+
// Prepare the image directory
611+
let rls = build.cargo_out(&compiler, Mode::Tool, target)
612+
.join(exe("rls", target));
613+
install(&rls, &image.join("bin"), 0o755);
614+
let doc = image.join("share/doc/rls");
615+
install(&src.join("README.md"), &doc, 0o644);
616+
install(&src.join("LICENSE-MIT"), &doc, 0o644);
617+
install(&src.join("LICENSE-APACHE"), &doc, 0o644);
618+
619+
// Generate the installer tarball
620+
let mut cmd = Command::new("sh");
621+
cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
622+
.arg("--product-name=Rust")
623+
.arg("--rel-manifest-dir=rustlib")
624+
.arg("--success-message=RLS-ready-to-serve.")
625+
.arg(format!("--image-dir={}", sanitize_sh(&image)))
626+
.arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
627+
.arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
628+
.arg(format!("--package-name={}-{}", name, target))
629+
.arg("--component-name=rls")
630+
.arg("--legacy-manifest-dirs=rustlib,cargo");
631+
build.run(&mut cmd);
632+
}
633+
596634
/// Creates a combined installer for the specified target in the provided stage.
597635
pub fn extended(build: &Build, stage: u32, target: &str) {
598636
println!("Dist extended stage{} ({})", stage, target);
@@ -604,6 +642,11 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
604642
let cargo_installer = dist.join(format!("{}-{}.tar.gz",
605643
pkgname(build, "cargo"),
606644
target));
645+
let rls_installer = dist.join(format!("{}.tar.gz",
646+
pkgname(build, "rls")));
647+
let analysis_installer = dist.join(format!("{}-{}.tar.gz",
648+
pkgname(build, "rust-analysis"),
649+
target));
607650
let docs_installer = dist.join(format!("{}-{}.tar.gz",
608651
pkgname(build, "rust-docs"),
609652
target));
@@ -631,9 +674,11 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
631674
// upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
632675
// the std files during uninstall. To do this ensure that rustc comes
633676
// before rust-std in the list below.
634-
let mut input_tarballs = format!("{},{},{},{}",
677+
let mut input_tarballs = format!("{},{},{},{},{},{}",
635678
sanitize_sh(&rustc_installer),
636679
sanitize_sh(&cargo_installer),
680+
sanitize_sh(&rls_installer),
681+
sanitize_sh(&analysis_installer),
637682
sanitize_sh(&docs_installer),
638683
sanitize_sh(&std_installer));
639684
if target.contains("pc-windows-gnu") {
@@ -675,20 +720,28 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
675720
let _ = fs::remove_dir_all(&pkg);
676721
t!(fs::create_dir_all(pkg.join("rustc")));
677722
t!(fs::create_dir_all(pkg.join("cargo")));
723+
t!(fs::create_dir_all(pkg.join("rls")));
724+
t!(fs::create_dir_all(pkg.join("rust-analysis")));
678725
t!(fs::create_dir_all(pkg.join("rust-docs")));
679726
t!(fs::create_dir_all(pkg.join("rust-std")));
680727

681728
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rustc"), target)),
682729
&pkg.join("rustc"));
683730
cp_r(&work.join(&format!("{}-{}", pkgname(build, "cargo"), target)),
684731
&pkg.join("cargo"));
732+
cp_r(&work.join(pkgname(build, "rls")),
733+
&pkg.join("rls"));
734+
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-analysis"), target)),
735+
&pkg.join("rust-analysis"));
685736
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-docs"), target)),
686737
&pkg.join("rust-docs"));
687738
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-std"), target)),
688739
&pkg.join("rust-std"));
689740

690741
install(&etc.join("pkg/postinstall"), &pkg.join("rustc"), 0o755);
691742
install(&etc.join("pkg/postinstall"), &pkg.join("cargo"), 0o755);
743+
install(&etc.join("pkg/postinstall"), &pkg.join("rls"), 0o755);
744+
install(&etc.join("pkg/postinstall"), &pkg.join("rust-analysis"), 0o755);
692745
install(&etc.join("pkg/postinstall"), &pkg.join("rust-docs"), 0o755);
693746
install(&etc.join("pkg/postinstall"), &pkg.join("rust-std"), 0o755);
694747

@@ -702,6 +755,8 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
702755
};
703756
pkgbuild("rustc");
704757
pkgbuild("cargo");
758+
pkgbuild("rls");
759+
pkgbuild("rust-analysis");
705760
pkgbuild("rust-docs");
706761
pkgbuild("rust-std");
707762

@@ -727,6 +782,8 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
727782
let _ = fs::remove_dir_all(&exe);
728783
t!(fs::create_dir_all(exe.join("rustc")));
729784
t!(fs::create_dir_all(exe.join("cargo")));
785+
t!(fs::create_dir_all(exe.join("rls")));
786+
t!(fs::create_dir_all(exe.join("rust-analysis")));
730787
t!(fs::create_dir_all(exe.join("rust-docs")));
731788
t!(fs::create_dir_all(exe.join("rust-std")));
732789
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rustc"), target))
@@ -735,6 +792,12 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
735792
cp_r(&work.join(&format!("{}-{}", pkgname(build, "cargo"), target))
736793
.join("cargo"),
737794
&exe.join("cargo"));
795+
cp_r(&work.join(pkgname(build, "rls"))
796+
.join("rls"),
797+
&exe.join("rls"));
798+
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-analysis"), target))
799+
.join("rust-analysis"),
800+
&exe.join("rust-analysis"));
738801
cp_r(&work.join(&format!("{}-{}", pkgname(build, "rust-docs"), target))
739802
.join("rust-docs"),
740803
&exe.join("rust-docs"));
@@ -744,6 +807,8 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
744807

745808
t!(fs::remove_file(exe.join("rustc/manifest.in")));
746809
t!(fs::remove_file(exe.join("cargo/manifest.in")));
810+
t!(fs::remove_file(exe.join("rls/manifest.in")));
811+
t!(fs::remove_file(exe.join("rust-analysis/manifest.in")));
747812
t!(fs::remove_file(exe.join("rust-docs/manifest.in")));
748813
t!(fs::remove_file(exe.join("rust-std/manifest.in")));
749814

@@ -800,6 +865,26 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
800865
.arg("-var").arg("var.DocsDir")
801866
.arg("-out").arg(exe.join("DocsGroup.wxs"))
802867
.arg("-t").arg(etc.join("msi/squash-components.xsl")));
868+
build.run(Command::new(&heat)
869+
.current_dir(&exe)
870+
.arg("dir")
871+
.arg("rls")
872+
.args(&heat_flags)
873+
.arg("-cg").arg("RlsGroup")
874+
.arg("-dr").arg("Rls")
875+
.arg("-var").arg("var.RlsDir")
876+
.arg("-out").arg(exe.join("RlsGroup.wxs"))
877+
.arg("-t").arg(etc.join("msi/squash-components.xsl")));
878+
build.run(Command::new(&heat)
879+
.current_dir(&exe)
880+
.arg("dir")
881+
.arg("rust-analysis")
882+
.args(&heat_flags)
883+
.arg("-cg").arg("AnalysisGroup")
884+
.arg("-dr").arg("Analysis")
885+
.arg("-var").arg("var.AnalysisDir")
886+
.arg("-out").arg(exe.join("AnalysisGroup.wxs"))
887+
.arg("-t").arg(etc.join("msi/squash-components.xsl")));
803888
build.run(Command::new(&heat)
804889
.current_dir(&exe)
805890
.arg("dir")
@@ -840,6 +925,8 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
840925
.arg("-nologo")
841926
.arg("-dRustcDir=rustc")
842927
.arg("-dDocsDir=rust-docs")
928+
.arg("-dRlsDir=rls")
929+
.arg("-dAnalysisDir=rust-analysis")
843930
.arg("-dCargoDir=cargo")
844931
.arg("-dStdDir=rust-std")
845932
.arg("-arch").arg(&arch)
@@ -857,6 +944,8 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
857944
candle(&etc.join("msi/rustwelcomedlg.wxs"));
858945
candle("RustcGroup.wxs".as_ref());
859946
candle("DocsGroup.wxs".as_ref());
947+
candle("RlsGroup.wxs".as_ref());
948+
candle("AnalysisGroup.wxs".as_ref());
860949
candle("CargoGroup.wxs".as_ref());
861950
candle("StdGroup.wxs".as_ref());
862951

@@ -879,6 +968,8 @@ pub fn extended(build: &Build, stage: u32, target: &str) {
879968
.arg("rustwelcomedlg.wixobj")
880969
.arg("RustcGroup.wixobj")
881970
.arg("DocsGroup.wixobj")
971+
.arg("RlsGroup.wixobj")
972+
.arg("AnalysisGroup.wixobj")
882973
.arg("CargoGroup.wixobj")
883974
.arg("StdGroup.wixobj")
884975
.current_dir(&exe);

src/bootstrap/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,21 @@ impl Build {
10441044
panic!("failed to find version in cargo's Cargo.toml")
10451045
}
10461046

1047+
/// Returns the `a.b.c` version that the RLS is at.
1048+
fn rls_release_num(&self) -> String {
1049+
let mut toml = String::new();
1050+
t!(t!(File::open(self.src.join("rls/Cargo.toml"))).read_to_string(&mut toml));
1051+
for line in toml.lines() {
1052+
let prefix = "version = \"";
1053+
let suffix = "\"";
1054+
if line.starts_with(prefix) && line.ends_with(suffix) {
1055+
return line[prefix.len()..line.len() - suffix.len()].to_string()
1056+
}
1057+
}
1058+
1059+
panic!("failed to find version in the RLS's Cargo.toml")
1060+
}
1061+
10471062
/// Returns whether unstable features should be enabled for the compiler
10481063
/// we're building.
10491064
fn unstable_features(&self) -> bool {

src/bootstrap/step.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
570570
.host(&build.config.build)
571571
})
572572
.run(move |s| compile::tool(build, s.stage, s.target, "cargo"));
573+
rules.build("tool-rls", "rls")
574+
.host(true)
575+
.dep(|s| s.name("libstd"))
576+
.run(move |s| compile::tool(build, s.stage, s.target, "rls"));
573577

574578
// ========================================================================
575579
// Documentation targets
@@ -694,6 +698,11 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
694698
.default(true)
695699
.only_host_build(true)
696700
.run(move |s| dist::analysis(build, &s.compiler(), s.target));
701+
rules.dist("dist-rls", "rls")
702+
.host(true)
703+
.only_host_build(true)
704+
.dep(|s| s.name("tool-rls"))
705+
.run(move |s| dist::rls(build, s.stage, s.target));
697706
rules.dist("install", "path/to/nowhere")
698707
.dep(|s| s.name("default:dist"))
699708
.run(move |s| install::install(build, s.stage, s.target));
@@ -711,6 +720,8 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
711720
.dep(|d| d.name("dist-mingw"))
712721
.dep(|d| d.name("dist-docs"))
713722
.dep(|d| d.name("dist-cargo"))
723+
.dep(|d| d.name("dist-rls"))
724+
.dep(|d| d.name("dist-analysis"))
714725
.run(move |s| dist::extended(build, s.stage, s.target));
715726

716727
rules.dist("dist-sign", "hash-and-sign")

0 commit comments

Comments
 (0)