Skip to content

Commit 1d6a0b0

Browse files
committed
Auto merge of #78486 - pietroalbini:manifest-artifacts, r=Mark-Simulacrum
Include non-rustup artifacts in the manifest This PR fixes rust-lang/promote-release#22 by including all the files we ship in the generated manifests, even the ones that are not installable through rustup. In practice this adds the following "artifacts": * `source-code`: the tarball containing the full source code used to build the release (`rustc-{channel}-src.tar.xz`) * `installer-msi`: the MSI installer for Windows systems (`rust-{channel}-{target}.msi`) * `installer-pkg`: the PKG installer for macOS systems (`rust-{channel}-{target}.pkg`) These files are included in a new `artifacts` table of the manifest, like so: ```toml [[artifacts.installer-msi.target.aarch64-pc-windows-msvc]] url = "https://example.com/2020-10-28/rust-nightly-aarch64-pc-windows-msvc.msi" hash-sha256 = "6b41d5b829d20834c5d93628d008ec618f8914ee79303363bd13a86fd5f305dd" [[artifacts.installer-msi.target.i686-pc-windows-gnu]] url = "https://example.com/2020-10-28/rust-nightly-i686-pc-windows-gnu.msi" hash-sha256 = "83f020de6e180c155add9fce1cea2ac6e5f744edbd6dc1581e24de8f56b2ca7a" [[artifacts.installer-msi.target.i686-pc-windows-msvc]] url = "https://example.com/2020-10-28/rust-nightly-i686-pc-windows-msvc.msi" hash-sha256 = "dbc80c24e9d5df01616c6f216114b4351f51a94218e2368b5cebe4165b270702" [[artifacts.installer-msi.target.x86_64-pc-windows-gnu]] url = "https://example.com/2020-10-28/rust-nightly-x86_64-pc-windows-gnu.msi" hash-sha256 = "8196eca3f02d72d4c8776ad4fcc72897125e2cf6404ae933e31c07e197e3c9fa" [[artifacts.installer-msi.target.x86_64-pc-windows-msvc]] url = "https://example.com/2020-10-28/rust-nightly-x86_64-pc-windows-msvc.msi" hash-sha256 = "b2e7fd6463790732fcf9c726b9448068712341943199cb40fc11d1138b8a207b" [[artifacts.installer-pkg.target.aarch64-apple-darwin]] url = "https://example.com/2020-10-28/rust-nightly-aarch64-apple-darwin.pkg" hash-sha256 = "70421c191752fb33886f8033b029e634bcc993b72308cef52a38405840e91f5c" [[artifacts.installer-pkg.target.x86_64-apple-darwin]] url = "https://example.com/2020-10-28/rust-nightly-x86_64-apple-darwin.pkg" hash-sha256 = "ebd7a5acb61e82d85e855146cc9bd856f32228ee7f40dd94c659b00614ed4f1f" [[artifacts.source-code.target."*"]] url = "https://example.com/2020-10-28/rustc-nightly-src.tar.gz" hash-sha256 = "5fcc487ee4c15c689de8ddf7daac7ff6a65c80498197b9aea58622dc2b3bca10" [[artifacts.source-code.target."*"]] url = "https://example.com/2020-10-28/rustc-nightly-src.tar.xz" hash-sha256 = "0c618ef0ec5f64da1801e9d0df6c755f6ed1a8780ec5c8ee75e55614be51d42c" ``` Each artifact can be available for multiple targets, and each target can have multiple versions of the same file (for example, a `gz`-compressed one and a `xz`-compressed one). In the future rustup might add functionality to let users retrieve the artifacts, but that's not needed to land this PR, and whether to do the implementation is up to the rustup maintainers. r? `@kinnison` cc `@Mark-Simulacrum`
2 parents 49720d2 + 92fc1f8 commit 1d6a0b0

File tree

3 files changed

+125
-22
lines changed

3 files changed

+125
-22
lines changed

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

+33
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ static DOCS_TARGETS: &[&str] = &[
168168
"x86_64-unknown-linux-musl",
169169
];
170170

171+
static MSI_INSTALLERS: &[&str] = &[
172+
"aarch64-pc-windows-msvc",
173+
"i686-pc-windows-gnu",
174+
"i686-pc-windows-msvc",
175+
"x86_64-pc-windows-gnu",
176+
"x86_64-pc-windows-msvc",
177+
];
178+
179+
static PKG_INSTALLERS: &[&str] = &["x86_64-apple-darwin", "aarch64-apple-darwin"];
180+
171181
static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];
172182

173183
static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview", "rust-analyzer-preview"];
@@ -314,10 +324,12 @@ impl Builder {
314324
manifest_version: "2".to_string(),
315325
date: self.date.to_string(),
316326
pkg: BTreeMap::new(),
327+
artifacts: BTreeMap::new(),
317328
renames: BTreeMap::new(),
318329
profiles: BTreeMap::new(),
319330
};
320331
self.add_packages_to(&mut manifest);
332+
self.add_artifacts_to(&mut manifest);
321333
self.add_profiles_to(&mut manifest);
322334
self.add_renames_to(&mut manifest);
323335
manifest.pkg.insert("rust".to_string(), self.rust_package(&manifest));
@@ -346,6 +358,27 @@ impl Builder {
346358
package("llvm-tools-preview", TARGETS);
347359
}
348360

361+
fn add_artifacts_to(&mut self, manifest: &mut Manifest) {
362+
manifest.add_artifact("source-code", |artifact| {
363+
let tarball = self.versions.tarball_name(&PkgType::Rustc, "src").unwrap();
364+
artifact.add_tarball(self, "*", &tarball);
365+
});
366+
367+
manifest.add_artifact("installer-msi", |artifact| {
368+
for target in MSI_INSTALLERS {
369+
let msi = self.versions.archive_name(&PkgType::Rust, target, "msi").unwrap();
370+
artifact.add_file(self, target, &msi);
371+
}
372+
});
373+
374+
manifest.add_artifact("installer-pkg", |artifact| {
375+
for target in PKG_INSTALLERS {
376+
let pkg = self.versions.archive_name(&PkgType::Rust, target, "pkg").unwrap();
377+
artifact.add_file(self, target, &pkg);
378+
}
379+
});
380+
}
381+
349382
fn add_profiles_to(&mut self, manifest: &mut Manifest) {
350383
let mut profile = |name, pkgs| self.profile(name, &mut manifest.profiles, pkgs);
351384
profile("minimal", &["rustc", "cargo", "rust-std", "rust-mingw"]);

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

+76-19
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ pub(crate) struct Manifest {
99
pub(crate) manifest_version: String,
1010
pub(crate) date: String,
1111
pub(crate) pkg: BTreeMap<String, Package>,
12+
pub(crate) artifacts: BTreeMap<String, Artifact>,
1213
pub(crate) renames: BTreeMap<String, Rename>,
1314
pub(crate) profiles: BTreeMap<String, Vec<String>>,
1415
}
1516

17+
impl Manifest {
18+
pub(crate) fn add_artifact(&mut self, name: &str, f: impl FnOnce(&mut Artifact)) {
19+
let mut artifact = Artifact { target: BTreeMap::new() };
20+
f(&mut artifact);
21+
self.artifacts.insert(name.to_string(), artifact);
22+
}
23+
}
24+
1625
#[derive(Serialize)]
1726
pub(crate) struct Package {
1827
pub(crate) version: String,
@@ -25,6 +34,42 @@ pub(crate) struct Rename {
2534
pub(crate) to: String,
2635
}
2736

37+
#[derive(Serialize)]
38+
pub(crate) struct Artifact {
39+
pub(crate) target: BTreeMap<String, Vec<ArtifactFile>>,
40+
}
41+
42+
impl Artifact {
43+
pub(crate) fn add_file(&mut self, builder: &mut Builder, target: &str, path: &str) {
44+
if let Some(path) = record_shipped_file(builder, builder.input.join(path)) {
45+
self.target.entry(target.into()).or_insert_with(Vec::new).push(ArtifactFile {
46+
url: builder.url(&path),
47+
hash_sha256: FileHash::Missing(path),
48+
});
49+
}
50+
}
51+
52+
pub(crate) fn add_tarball(&mut self, builder: &mut Builder, target: &str, base_path: &str) {
53+
let files = self.target.entry(target.into()).or_insert_with(Vec::new);
54+
let base_path = builder.input.join(base_path);
55+
for compression in &["gz", "xz"] {
56+
if let Some(tarball) = tarball_variant(builder, &base_path, compression) {
57+
files.push(ArtifactFile {
58+
url: builder.url(&tarball),
59+
hash_sha256: FileHash::Missing(tarball),
60+
});
61+
}
62+
}
63+
}
64+
}
65+
66+
#[derive(Serialize)]
67+
#[serde(rename_all = "kebab-case")]
68+
pub(crate) struct ArtifactFile {
69+
pub(crate) url: String,
70+
pub(crate) hash_sha256: FileHash,
71+
}
72+
2873
#[derive(Serialize, Default)]
2974
pub(crate) struct Target {
3075
pub(crate) available: bool,
@@ -39,8 +84,8 @@ pub(crate) struct Target {
3984
impl Target {
4085
pub(crate) fn from_compressed_tar(builder: &mut Builder, base_path: &str) -> Self {
4186
let base_path = builder.input.join(base_path);
42-
let gz = Self::tarball_variant(builder, &base_path, "gz");
43-
let xz = Self::tarball_variant(builder, &base_path, "xz");
87+
let gz = tarball_variant(builder, &base_path, "gz");
88+
let xz = tarball_variant(builder, &base_path, "xz");
4489

4590
if gz.is_none() {
4691
return Self::unavailable();
@@ -59,23 +104,6 @@ impl Target {
59104
}
60105
}
61106

62-
fn tarball_variant(builder: &mut Builder, base: &Path, ext: &str) -> Option<PathBuf> {
63-
let mut path = base.to_path_buf();
64-
path.set_extension(ext);
65-
if path.is_file() {
66-
builder.shipped_files.insert(
67-
path.file_name()
68-
.expect("missing filename")
69-
.to_str()
70-
.expect("non-utf-8 filename")
71-
.to_string(),
72-
);
73-
Some(path)
74-
} else {
75-
None
76-
}
77-
}
78-
79107
pub(crate) fn unavailable() -> Self {
80108
Self::default()
81109
}
@@ -111,6 +139,27 @@ impl Serialize for FileHash {
111139
}
112140
}
113141

142+
fn tarball_variant(builder: &mut Builder, base: &Path, ext: &str) -> Option<PathBuf> {
143+
let mut path = base.to_path_buf();
144+
path.set_extension(ext);
145+
record_shipped_file(builder, path)
146+
}
147+
148+
fn record_shipped_file(builder: &mut Builder, path: PathBuf) -> Option<PathBuf> {
149+
if path.is_file() {
150+
builder.shipped_files.insert(
151+
path.file_name()
152+
.expect("missing filename")
153+
.to_str()
154+
.expect("non-utf-8 filename")
155+
.to_string(),
156+
);
157+
Some(path)
158+
} else {
159+
None
160+
}
161+
}
162+
114163
pub(crate) fn visit_file_hashes(manifest: &mut Manifest, mut f: impl FnMut(&mut FileHash)) {
115164
for pkg in manifest.pkg.values_mut() {
116165
for target in pkg.target.values_mut() {
@@ -122,4 +171,12 @@ pub(crate) fn visit_file_hashes(manifest: &mut Manifest, mut f: impl FnMut(&mut
122171
}
123172
}
124173
}
174+
175+
for artifact in manifest.artifacts.values_mut() {
176+
for target in artifact.target.values_mut() {
177+
for file in target {
178+
f(&mut file.hash_sha256);
179+
}
180+
}
181+
}
125182
}

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const RUSTC_VERSION: &str = include_str!("../../../version");
1313
pub(crate) enum PkgType {
1414
Rust,
1515
RustSrc,
16+
Rustc,
1617
Cargo,
1718
Rls,
1819
RustAnalyzer,
@@ -28,6 +29,7 @@ impl PkgType {
2829
match component {
2930
"rust" => PkgType::Rust,
3031
"rust-src" => PkgType::RustSrc,
32+
"rustc" => PkgType::Rustc,
3133
"cargo" => PkgType::Cargo,
3234
"rls" | "rls-preview" => PkgType::Rls,
3335
"rust-analyzer" | "rust-analyzer-preview" => PkgType::RustAnalyzer,
@@ -44,6 +46,7 @@ impl PkgType {
4446
match self {
4547
PkgType::Rust => "rust",
4648
PkgType::RustSrc => "rust-src",
49+
PkgType::Rustc => "rustc",
4750
PkgType::Cargo => "cargo",
4851
PkgType::Rls => "rls",
4952
PkgType::RustAnalyzer => "rust-analyzer",
@@ -69,6 +72,7 @@ impl PkgType {
6972

7073
PkgType::Rust => true,
7174
PkgType::RustSrc => true,
75+
PkgType::Rustc => true,
7276
PkgType::Other(_) => true,
7377
}
7478
}
@@ -165,10 +169,11 @@ impl Versions {
165169
}
166170
}
167171

168-
pub(crate) fn tarball_name(
172+
pub(crate) fn archive_name(
169173
&mut self,
170174
package: &PkgType,
171175
target: &str,
176+
extension: &str,
172177
) -> Result<String, Error> {
173178
let component_name = package.tarball_component_name();
174179
let version = match self.channel.as_str() {
@@ -179,12 +184,20 @@ impl Versions {
179184
};
180185

181186
if package.target_independent() {
182-
Ok(format!("{}-{}.tar.gz", component_name, version))
187+
Ok(format!("{}-{}.{}", component_name, version, extension))
183188
} else {
184-
Ok(format!("{}-{}-{}.tar.gz", component_name, version, target))
189+
Ok(format!("{}-{}-{}.{}", component_name, version, target, extension))
185190
}
186191
}
187192

193+
pub(crate) fn tarball_name(
194+
&mut self,
195+
package: &PkgType,
196+
target: &str,
197+
) -> Result<String, Error> {
198+
self.archive_name(package, target, "tar.gz")
199+
}
200+
188201
pub(crate) fn rustc_version(&self) -> &str {
189202
RUSTC_VERSION
190203
}

0 commit comments

Comments
 (0)