Skip to content

Commit 92fc1f8

Browse files
committed
build-manifest: include artifacts in a new table
This commit adds to the generated manifest all files we ship that are not rustup components, namely: * Source code tarballs (rustc-{channel}-src.tar.xz) * Windows installers (rust-{channel}-{target}.msi) * macOS installers (rust-{channel}-{target}.pkg) Those files are included in a new "artifacts" table of the manifest, to avoid interfering with existing rustup installations.
1 parent 2eb4fc8 commit 92fc1f8

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
@@ -171,6 +171,16 @@ static DOCS_TARGETS: &[&str] = &[
171171
"x86_64-unknown-linux-musl",
172172
];
173173

174+
static MSI_INSTALLERS: &[&str] = &[
175+
"aarch64-pc-windows-msvc",
176+
"i686-pc-windows-gnu",
177+
"i686-pc-windows-msvc",
178+
"x86_64-pc-windows-gnu",
179+
"x86_64-pc-windows-msvc",
180+
];
181+
182+
static PKG_INSTALLERS: &[&str] = &["x86_64-apple-darwin", "aarch64-apple-darwin"];
183+
174184
static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];
175185

176186
static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview", "rust-analyzer-preview"];
@@ -313,10 +323,12 @@ impl Builder {
313323
manifest_version: "2".to_string(),
314324
date: self.date.to_string(),
315325
pkg: BTreeMap::new(),
326+
artifacts: BTreeMap::new(),
316327
renames: BTreeMap::new(),
317328
profiles: BTreeMap::new(),
318329
};
319330
self.add_packages_to(&mut manifest);
331+
self.add_artifacts_to(&mut manifest);
320332
self.add_profiles_to(&mut manifest);
321333
self.add_renames_to(&mut manifest);
322334
manifest.pkg.insert("rust".to_string(), self.rust_package(&manifest));
@@ -345,6 +357,27 @@ impl Builder {
345357
package("llvm-tools-preview", TARGETS);
346358
}
347359

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