Skip to content

Commit c49ba05

Browse files
committed
Create tar balls of save-analysis-api metadata for the standard libraries as part of make dist.
1 parent bd148d2 commit c49ba05

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

src/bootstrap/bin/rustc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ fn main() {
125125
cmd.arg("-C").arg(format!("codegen-units={}", s));
126126
}
127127

128+
// Emit save-analysis info.
129+
if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {
130+
cmd.arg("-Zsave-analysis-api");
131+
}
132+
128133
// Dealing with rpath here is a little special, so let's go into some
129134
// detail. First off, `-rpath` is a linker option on Unix platforms
130135
// which adds to the runtime dynamic loader path when looking for

src/bootstrap/dist.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::io::Write;
2323
use std::path::{PathBuf, Path};
2424
use std::process::Command;
2525

26-
use {Build, Compiler};
26+
use {Build, Compiler, Mode};
2727
use util::{cp_r, libdir, is_dylib, cp_filtered, copy};
2828

2929
pub fn package_vers(build: &Build) -> &str {
@@ -289,6 +289,50 @@ pub fn rust_src_location(build: &Build) -> PathBuf {
289289
distdir(build).join(&format!("{}.tar.gz", plain_name))
290290
}
291291

292+
/// Creates a tarball of save-analysis metadata, if available.
293+
pub fn analysis(build: &Build, compiler: &Compiler, target: &str) {
294+
println!("Dist analysis");
295+
296+
if build.config.channel != "nightly" {
297+
println!("Skipping dist-analysis - not on nightly channel");
298+
return;
299+
}
300+
if compiler.stage != 2 {
301+
return
302+
}
303+
304+
let name = format!("rust-analysis-{}", package_vers(build));
305+
let image = tmpdir(build).join(format!("{}-{}-image", name, target));
306+
307+
let src = build.stage_out(compiler, Mode::Libstd).join(target).join("release").join("deps");
308+
309+
let image_src = src.join("save-analysis");
310+
let dst = image.join("lib/rustlib").join(target).join("analysis");
311+
t!(fs::create_dir_all(&dst));
312+
cp_r(&image_src, &dst);
313+
314+
let mut cmd = Command::new("sh");
315+
cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
316+
.arg("--product-name=Rust")
317+
.arg("--rel-manifest-dir=rustlib")
318+
.arg("--success-message=save-analysis-saved.")
319+
.arg(format!("--image-dir={}", sanitize_sh(&image)))
320+
.arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
321+
.arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
322+
.arg(format!("--package-name={}-{}", name, target))
323+
.arg(format!("--component-name=rust-analysis-{}", target))
324+
.arg("--legacy-manifest-dirs=rustlib,cargo");
325+
build.run(&mut cmd);
326+
t!(fs::remove_dir_all(&image));
327+
328+
// Create plain source tarball
329+
let mut cmd = Command::new("tar");
330+
cmd.arg("-czf").arg(sanitize_sh(&distdir(build).join(&format!("{}.tar.gz", name))))
331+
.arg("analysis")
332+
.current_dir(&src);
333+
build.run(&mut cmd);
334+
}
335+
292336
/// Creates the `rust-src` installer component and the plain source tarball
293337
pub fn rust_src(build: &Build) {
294338
println!("Dist src");

src/bootstrap/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ impl Build {
507507
.env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
508508
}
509509

510+
if self.config.channel == "nightly" && compiler.stage == 2 {
511+
cargo.env("RUSTC_SAVE_ANALYSIS", "api".to_string());
512+
}
513+
510514
// Environment variables *required* needed throughout the build
511515
//
512516
// FIXME: should update code to not require this env var

src/bootstrap/step.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ pub fn build_rules(build: &Build) -> Rules {
499499
.default(true)
500500
.dep(|s| s.name("default:doc"))
501501
.run(move |s| dist::docs(build, s.stage, s.target));
502+
rules.dist("dist-analysis", "src/libstd")
503+
.dep(|s| s.name("dist-std"))
504+
.default(true)
505+
.run(move |s| dist::analysis(build, &s.compiler(), s.target));
502506
rules.dist("install", "src")
503507
.dep(|s| s.name("default:dist"))
504508
.run(move |s| install::install(build, s.stage, s.target));

0 commit comments

Comments
 (0)