Skip to content

Commit e21df80

Browse files
committed
Auto merge of #45903 - nrc:rustfmt-dist, r=alexcrichton
Distribute Rustfmt r? @alexcrichton
2 parents 8efbf7a + 97d21e2 commit e21df80

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

src/bootstrap/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ impl<'a> Builder<'a> {
261261
doc::Reference, doc::Rustdoc, doc::CargoBook),
262262
Kind::Dist => describe!(dist::Docs, dist::Mingw, dist::Rustc, dist::DebuggerScripts,
263263
dist::Std, dist::Analysis, dist::Src, dist::PlainSourceTarball, dist::Cargo,
264-
dist::Rls, dist::Extended, dist::HashSign, dist::DontDistWithMiriEnabled),
264+
dist::Rls, dist::Rustfmt, dist::Extended, dist::HashSign,
265+
dist::DontDistWithMiriEnabled),
265266
Kind::Install => describe!(install::Docs, install::Std, install::Cargo, install::Rls,
266267
install::Analysis, install::Src, install::Rustc),
267268
}

src/bootstrap/dist.rs

+89
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub fn pkgname(build: &Build, component: &str) -> String {
3939
format!("{}-{}", component, build.cargo_package_vers())
4040
} else if component == "rls" {
4141
format!("{}-{}", component, build.rls_package_vers())
42+
} else if component == "rustfmt" {
43+
format!("{}-{}", component, build.rustfmt_package_vers())
4244
} else {
4345
assert!(component.starts_with("rust"));
4446
format!("{}-{}", component, build.rust_package_vers())
@@ -1112,6 +1114,92 @@ impl Step for Rls {
11121114
}
11131115

11141116

1117+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1118+
pub struct Rustfmt {
1119+
pub stage: u32,
1120+
pub target: Interned<String>,
1121+
}
1122+
1123+
impl Step for Rustfmt {
1124+
type Output = Option<PathBuf>;
1125+
const ONLY_BUILD_TARGETS: bool = true;
1126+
const ONLY_HOSTS: bool = true;
1127+
1128+
fn should_run(run: ShouldRun) -> ShouldRun {
1129+
run.path("rustfmt")
1130+
}
1131+
1132+
fn make_run(run: RunConfig) {
1133+
run.builder.ensure(Rustfmt {
1134+
stage: run.builder.top_stage,
1135+
target: run.target,
1136+
});
1137+
}
1138+
1139+
fn run(self, builder: &Builder) -> Option<PathBuf> {
1140+
let build = builder.build;
1141+
let stage = self.stage;
1142+
let target = self.target;
1143+
assert!(build.config.extended);
1144+
1145+
if !builder.config.toolstate.rustfmt.testing() {
1146+
println!("skipping Dist Rustfmt stage{} ({})", stage, target);
1147+
return None
1148+
}
1149+
1150+
println!("Dist Rustfmt stage{} ({})", stage, target);
1151+
let src = build.src.join("src/tools/rustfmt");
1152+
let release_num = build.release_num("rustfmt");
1153+
let name = pkgname(build, "rustfmt");
1154+
let version = build.rustfmt_info.version(build, &release_num);
1155+
1156+
let tmp = tmpdir(build);
1157+
let image = tmp.join("rustfmt-image");
1158+
drop(fs::remove_dir_all(&image));
1159+
t!(fs::create_dir_all(&image));
1160+
1161+
// Prepare the image directory
1162+
// We expect RLS to build, because we've exited this step above if tool
1163+
// state for RLS isn't testing.
1164+
let rustfmt = builder.ensure(tool::Rustfmt {
1165+
compiler: builder.compiler(stage, build.build),
1166+
target
1167+
}).expect("Rustfmt to build: toolstate is testing");
1168+
install(&rustfmt, &image.join("bin"), 0o755);
1169+
let doc = image.join("share/doc/rustfmt");
1170+
install(&src.join("README.md"), &doc, 0o644);
1171+
install(&src.join("LICENSE-MIT"), &doc, 0o644);
1172+
install(&src.join("LICENSE-APACHE"), &doc, 0o644);
1173+
1174+
// Prepare the overlay
1175+
let overlay = tmp.join("rustfmt-overlay");
1176+
drop(fs::remove_dir_all(&overlay));
1177+
t!(fs::create_dir_all(&overlay));
1178+
install(&src.join("README.md"), &overlay, 0o644);
1179+
install(&src.join("LICENSE-MIT"), &overlay, 0o644);
1180+
install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
1181+
t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
1182+
1183+
// Generate the installer tarball
1184+
let mut cmd = rust_installer(builder);
1185+
cmd.arg("generate")
1186+
.arg("--product-name=Rust")
1187+
.arg("--rel-manifest-dir=rustlib")
1188+
.arg("--success-message=rustfmt-ready-to-fmt.")
1189+
.arg("--image-dir").arg(&image)
1190+
.arg("--work-dir").arg(&tmpdir(build))
1191+
.arg("--output-dir").arg(&distdir(build))
1192+
.arg("--non-installed-overlay").arg(&overlay)
1193+
.arg(format!("--package-name={}-{}", name, target))
1194+
.arg("--legacy-manifest-dirs=rustlib,cargo")
1195+
.arg("--component-name=rustfmt-preview");
1196+
1197+
build.run(&mut cmd);
1198+
Some(distdir(build).join(format!("{}-{}.tar.gz", name, target)))
1199+
}
1200+
}
1201+
1202+
11151203
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
11161204
pub struct DontDistWithMiriEnabled;
11171205

@@ -1606,6 +1694,7 @@ impl Step for HashSign {
16061694
cmd.arg(build.rust_package_vers());
16071695
cmd.arg(build.package_vers(&build.release_num("cargo")));
16081696
cmd.arg(build.package_vers(&build.release_num("rls")));
1697+
cmd.arg(build.package_vers(&build.release_num("rustfmt")));
16091698
cmd.arg(addr);
16101699

16111700
t!(fs::create_dir_all(distdir(build)));

src/bootstrap/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub struct Build {
222222
rust_info: channel::GitInfo,
223223
cargo_info: channel::GitInfo,
224224
rls_info: channel::GitInfo,
225+
rustfmt_info: channel::GitInfo,
225226
local_rebuild: bool,
226227
fail_fast: bool,
227228
verbosity: usize,
@@ -304,6 +305,7 @@ impl Build {
304305
let rust_info = channel::GitInfo::new(&config, &src);
305306
let cargo_info = channel::GitInfo::new(&config, &src.join("src/tools/cargo"));
306307
let rls_info = channel::GitInfo::new(&config, &src.join("src/tools/rls"));
308+
let rustfmt_info = channel::GitInfo::new(&config, &src.join("src/tools/rustfmt"));
307309

308310
Build {
309311
initial_rustc: config.initial_rustc.clone(),
@@ -323,6 +325,7 @@ impl Build {
323325
rust_info,
324326
cargo_info,
325327
rls_info,
328+
rustfmt_info,
326329
cc: HashMap::new(),
327330
cxx: HashMap::new(),
328331
ar: HashMap::new(),
@@ -814,6 +817,11 @@ impl Build {
814817
self.package_vers(&self.release_num("rls"))
815818
}
816819

820+
/// Returns the value of `package_vers` above for rustfmt
821+
fn rustfmt_package_vers(&self) -> String {
822+
self.package_vers(&self.release_num("rustfmt"))
823+
}
824+
817825
/// Returns the `version` string associated with this compiler for Rust
818826
/// itself.
819827
///

src/tools/build-manifest/src/main.rs

+30
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,24 @@ struct Builder {
168168
rust_release: String,
169169
cargo_release: String,
170170
rls_release: String,
171+
rustfmt_release: String,
172+
171173
input: PathBuf,
172174
output: PathBuf,
173175
gpg_passphrase: String,
174176
digests: BTreeMap<String, String>,
175177
s3_address: String,
176178
date: String,
179+
177180
rust_version: Option<String>,
178181
cargo_version: Option<String>,
179182
rls_version: Option<String>,
183+
rustfmt_version: Option<String>,
184+
180185
rust_git_commit_hash: Option<String>,
181186
cargo_git_commit_hash: Option<String>,
182187
rls_git_commit_hash: Option<String>,
188+
rustfmt_git_commit_hash: Option<String>,
183189
}
184190

185191
fn main() {
@@ -190,6 +196,7 @@ fn main() {
190196
let rust_release = args.next().unwrap();
191197
let cargo_release = args.next().unwrap();
192198
let rls_release = args.next().unwrap();
199+
let rustfmt_release = args.next().unwrap();
193200
let s3_address = args.next().unwrap();
194201
let mut passphrase = String::new();
195202
t!(io::stdin().read_to_string(&mut passphrase));
@@ -198,18 +205,24 @@ fn main() {
198205
rust_release,
199206
cargo_release,
200207
rls_release,
208+
rustfmt_release,
209+
201210
input,
202211
output,
203212
gpg_passphrase: passphrase,
204213
digests: BTreeMap::new(),
205214
s3_address,
206215
date,
216+
207217
rust_version: None,
208218
cargo_version: None,
209219
rls_version: None,
220+
rustfmt_version: None,
221+
210222
rust_git_commit_hash: None,
211223
cargo_git_commit_hash: None,
212224
rls_git_commit_hash: None,
225+
rustfmt_git_commit_hash: None,
213226
}.build();
214227
}
215228

@@ -218,9 +231,12 @@ impl Builder {
218231
self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
219232
self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
220233
self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
234+
self.rustfmt_version = self.version("rustfmt", "x86_64-unknown-linux-gnu");
235+
221236
self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
222237
self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
223238
self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
239+
self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu");
224240

225241
self.digest_and_sign();
226242
let manifest = self.build_manifest();
@@ -255,9 +271,11 @@ impl Builder {
255271
self.package("rust-docs", &mut manifest.pkg, TARGETS);
256272
self.package("rust-src", &mut manifest.pkg, &["*"]);
257273
self.package("rls-preview", &mut manifest.pkg, HOSTS);
274+
self.package("rustfmt-preview", &mut manifest.pkg, HOSTS);
258275
self.package("rust-analysis", &mut manifest.pkg, TARGETS);
259276

260277
let rls_present = manifest.pkg.contains_key("rls-preview");
278+
let rustfmt_present = manifest.pkg.contains_key("rustfmt-preview");
261279

262280
if rls_present {
263281
manifest.renames.insert("rls".to_owned(), Rename { to: "rls-preview".to_owned() });
@@ -306,6 +324,12 @@ impl Builder {
306324
target: host.to_string(),
307325
});
308326
}
327+
if rustfmt_present {
328+
extensions.push(Component {
329+
pkg: "rustfmt-preview".to_string(),
330+
target: host.to_string(),
331+
});
332+
}
309333
extensions.push(Component {
310334
pkg: "rust-analysis".to_string(),
311335
target: host.to_string(),
@@ -391,6 +415,8 @@ impl Builder {
391415
format!("cargo-{}-{}.tar.gz", self.cargo_release, target)
392416
} else if component == "rls" || component == "rls-preview" {
393417
format!("rls-{}-{}.tar.gz", self.rls_release, target)
418+
} else if component == "rustfmt" || component == "rustfmt-preview" {
419+
format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target)
394420
} else {
395421
format!("{}-{}-{}.tar.gz", component, self.rust_release, target)
396422
}
@@ -401,6 +427,8 @@ impl Builder {
401427
&self.cargo_version
402428
} else if component == "rls" || component == "rls-preview" {
403429
&self.rls_version
430+
} else if component == "rustfmt" || component == "rustfmt-preview" {
431+
&self.rustfmt_version
404432
} else {
405433
&self.rust_version
406434
}
@@ -411,6 +439,8 @@ impl Builder {
411439
&self.cargo_git_commit_hash
412440
} else if component == "rls" || component == "rls-preview" {
413441
&self.rls_git_commit_hash
442+
} else if component == "rustfmt" || component == "rustfmt-preview" {
443+
&self.rustfmt_git_commit_hash
414444
} else {
415445
&self.rust_git_commit_hash
416446
}

0 commit comments

Comments
 (0)