Skip to content

Commit 95839b1

Browse files
committed
Auto merge of #39284 - alexcrichton:manifesting, r=brson
rustbuild: Add manifest generation in-tree This commit adds a new tool, `build-manifest`, which is used to generate a distribution manifest of all produced artifacts. This tool is intended to replace the `build-rust-manifest.py` script that's currently located on the buildmaster. The intention is that we'll have a builder which periodically: * Downloads all artifacts for a commit * Runs `./x.py dist hash-and-sign`. This will generate `sha256` and `asc` files as well as TOML manifests. * Upload all generated hashes and manifests to the directory the artifacts came from. * Upload *all* artifacts (tarballs and hashes and manifests) to an archived location. * If necessary, upload all artifacts to the main location. This script is intended to just be the second step here where orchestrating uploads and such will all happen externally from the build system itself. cc #38531
2 parents 463affe + 9e8785f commit 95839b1

File tree

8 files changed

+512
-1
lines changed

8 files changed

+512
-1
lines changed

src/Cargo.lock

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"tools/linkchecker",
1111
"tools/rustbook",
1212
"tools/tidy",
13+
"tools/build-manifest",
1314
]
1415

1516
# Curiously, compiletest will segfault if compiled with opt-level=3 on 64-bit

src/bootstrap/config.rs

+19
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ pub struct Config {
7878
pub cargo: Option<PathBuf>,
7979
pub local_rebuild: bool,
8080

81+
// dist misc
82+
pub dist_sign_folder: Option<PathBuf>,
83+
pub dist_upload_addr: Option<String>,
84+
pub dist_gpg_password_file: Option<PathBuf>,
85+
8186
// libstd features
8287
pub debug_jemalloc: bool,
8388
pub use_jemalloc: bool,
@@ -123,6 +128,7 @@ struct TomlConfig {
123128
llvm: Option<Llvm>,
124129
rust: Option<Rust>,
125130
target: Option<HashMap<String, TomlTarget>>,
131+
dist: Option<Dist>,
126132
}
127133

128134
/// TOML representation of various global build decisions.
@@ -166,6 +172,13 @@ struct Llvm {
166172
targets: Option<String>,
167173
}
168174

175+
#[derive(RustcDecodable, Default, Clone)]
176+
struct Dist {
177+
sign_folder: Option<String>,
178+
gpg_password_file: Option<String>,
179+
upload_addr: Option<String>,
180+
}
181+
169182
#[derive(RustcDecodable)]
170183
enum StringOrBool {
171184
String(String),
@@ -352,6 +365,12 @@ impl Config {
352365
}
353366
}
354367

368+
if let Some(ref t) = toml.dist {
369+
config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
370+
config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
371+
config.dist_upload_addr = t.upload_addr.clone();
372+
}
373+
355374
return config
356375
}
357376

src/bootstrap/config.toml.example

+30
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,33 @@
242242
# that this option only makes sense for MUSL targets that produce statically
243243
# linked binaries
244244
#musl-root = "..."
245+
246+
# =============================================================================
247+
# Distribution options
248+
#
249+
# These options are related to distribution, mostly for the Rust project itself.
250+
# You probably won't need to concern yourself with any of these options
251+
# =============================================================================
252+
[dist]
253+
254+
# This is the folder of artifacts that the build system will sign. All files in
255+
# this directory will be signed with the default gpg key using the system `gpg`
256+
# binary. The `asc` and `sha256` files will all be output into the standard dist
257+
# output folder (currently `build/dist`)
258+
#
259+
# This folder should be populated ahead of time before the build system is
260+
# invoked.
261+
#sign-folder = "path/to/folder/to/sign"
262+
263+
# This is a file which contains the password of the default gpg key. This will
264+
# be passed to `gpg` down the road when signing all files in `sign-folder`
265+
# above. This should be stored in plaintext.
266+
#gpg-password-file = "path/to/gpg/password"
267+
268+
# The remote address that all artifacts will eventually be uploaded to. The
269+
# build system generates manifests which will point to these urls, and for the
270+
# manifests to be correct they'll have to have the right URLs encoded.
271+
#
272+
# Note that this address should not contain a trailing slash as file names will
273+
# be appended to it.
274+
#upload-addr = "https://example.com/folder"

src/bootstrap/dist.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::env;
2222
use std::fs::{self, File};
2323
use std::io::{Read, Write};
2424
use std::path::{PathBuf, Path};
25-
use std::process::Command;
25+
use std::process::{Command, Stdio};
2626

2727
use build_helper::output;
2828

@@ -876,3 +876,34 @@ fn add_env(build: &Build, cmd: &mut Command, target: &str) {
876876
cmd.env("CFG_PLATFORM", "x86");
877877
}
878878
}
879+
880+
pub fn hash_and_sign(build: &Build) {
881+
let compiler = Compiler::new(0, &build.config.build);
882+
let mut cmd = build.tool_cmd(&compiler, "build-manifest");
883+
let sign = build.config.dist_sign_folder.as_ref().unwrap_or_else(|| {
884+
panic!("\n\nfailed to specify `dist.sign-folder` in `config.toml`\n\n")
885+
});
886+
let addr = build.config.dist_upload_addr.as_ref().unwrap_or_else(|| {
887+
panic!("\n\nfailed to specify `dist.upload-addr` in `config.toml`\n\n")
888+
});
889+
let file = build.config.dist_gpg_password_file.as_ref().unwrap_or_else(|| {
890+
panic!("\n\nfailed to specify `dist.gpg-password-file` in `config.toml`\n\n")
891+
});
892+
let mut pass = String::new();
893+
t!(t!(File::open(&file)).read_to_string(&mut pass));
894+
895+
let today = output(Command::new("date").arg("+%Y-%m-%d"));
896+
897+
cmd.arg(sign);
898+
cmd.arg(distdir(build));
899+
cmd.arg(today.trim());
900+
cmd.arg(package_vers(build));
901+
cmd.arg(addr);
902+
903+
t!(fs::create_dir_all(distdir(build)));
904+
905+
let mut child = t!(cmd.stdin(Stdio::piped()).spawn());
906+
t!(child.stdin.take().unwrap().write_all(pass.as_bytes()));
907+
let status = t!(child.wait());
908+
assert!(status.success());
909+
}

src/bootstrap/step.rs

+10
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
513513
rules.build("tool-compiletest", "src/tools/compiletest")
514514
.dep(|s| s.name("libtest"))
515515
.run(move |s| compile::tool(build, s.stage, s.target, "compiletest"));
516+
rules.build("tool-build-manifest", "src/tools/build-manifest")
517+
.dep(|s| s.name("libstd"))
518+
.run(move |s| compile::tool(build, s.stage, s.target, "build-manifest"));
516519

517520
// ========================================================================
518521
// Documentation targets
@@ -633,6 +636,13 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
633636
.dep(|d| d.name("dist-cargo"))
634637
.run(move |s| dist::extended(build, s.stage, s.target));
635638

639+
rules.dist("dist-sign", "hash-and-sign")
640+
.host(true)
641+
.only_build(true)
642+
.only_host_build(true)
643+
.dep(move |s| s.name("tool-build-manifest").target(&build.config.build).stage(0))
644+
.run(move |_| dist::hash_and_sign(build));
645+
636646
rules.verify();
637647
return rules;
638648
}

src/tools/build-manifest/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "build-manifest"
3+
version = "0.1.0"
4+
authors = ["Alex Crichton <[email protected]>"]
5+
6+
[dependencies]
7+
toml = "0.1"
8+
rustc-serialize = "0.3"

0 commit comments

Comments
 (0)