Skip to content

Commit 44a01b8

Browse files
committed
rustbuild: Add support for compiling Cargo
This commit adds support to rustbuild for compiling Cargo as part of the release process. Previously rustbuild would simply download a Cargo snapshot and repackage it. With this change we should be able to turn off artifacts from the rust-lang/cargo repository and purely rely on the artifacts Cargo produces here. The infrastructure added here is intended to be extensible to other components, such as the RLS. It won't exactly be a one-line addition, but the addition of Cargo didn't require too much hooplah anyway. The process for release Cargo will now look like: * The rust-lang/rust repository has a Cargo submodule which is used to build a Cargo to pair with the rust-lang/rust release * Periodically we'll update the cargo submodule as necessary on rust-lang/rust's master branch * When branching beta we'll create a new branch of Cargo (as we do today), and the first commit to the beta branch will be to update the Cargo submodule to this exact revision. * When branching stable, we'll ensure that the Cargo submodule is updated and then make a stable release. Backports to Cargo will look like: * Send a PR to cargo's master branch * Send a PR to cargo's release branch (e.g. rust-1.16.0) * Send a PR to rust-lang/rust's beta branch updating the submodule * Eventually send a PR to rust-lang/rust's master branch updating the submodule For reference, the process to add a new component to the rust-lang/rust release would look like: * Add `$foo` as a submodule in `src/tools` * Add a `tool-$foo` step which compiles `$foo` with the specified compiler, likely mirroring what Cargo does. * Add a `dist-$foo` step which uses `src/tools/$foo` and the `tool-$foo` output to create a rust-installer package for `$foo` likely mirroring what Cargo does. * Update the `dist-extended` step with a new dependency on `dist-$foo` * Update `src/tools/build-manifest` for the new component.
1 parent f6304e1 commit 44a01b8

File tree

20 files changed

+511
-166
lines changed

20 files changed

+511
-166
lines changed

Diff for: configure

+1
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ opt locked-deps 0 "force Cargo.lock to be up to date"
651651
opt vendor 0 "enable usage of vendored Rust crates"
652652
opt sanitizers 0 "build the sanitizer runtimes (asan, lsan, msan, tsan)"
653653
opt dist-src 1 "when building tarballs enables building a source tarball"
654+
opt cargo-openssl-static 0 "static openssl in cargo"
654655

655656
# Optimization and debugging options. These may be overridden by the release channel, etc.
656657
opt_nosave optimize 1 "build optimized rust code"

Diff for: src/Cargo.lock

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

Diff for: src/bootstrap/channel.rs

+50-45
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,77 @@
1515
//! `package_vers`, and otherwise indicating to the compiler what it should
1616
//! print out as part of its version information.
1717
18+
use std::path::Path;
1819
use std::process::Command;
1920

2021
use build_helper::output;
2122

2223
use Build;
2324

2425
// The version number
25-
const CFG_RELEASE_NUM: &'static str = "1.17.0";
26+
pub const CFG_RELEASE_NUM: &'static str = "1.17.0";
2627

2728
// An optional number to put after the label, e.g. '.2' -> '-beta.2'
2829
// Be sure to make this starts with a dot to conform to semver pre-release
2930
// versions (section 9)
30-
const CFG_PRERELEASE_VERSION: &'static str = ".1";
31+
pub const CFG_PRERELEASE_VERSION: &'static str = ".1";
3132

32-
pub fn collect(build: &mut Build) {
33-
build.release_num = CFG_RELEASE_NUM.to_string();
34-
build.prerelease_version = CFG_RELEASE_NUM.to_string();
33+
pub struct GitInfo {
34+
inner: Option<Info>,
35+
}
3536

36-
// Depending on the channel, passed in `./configure --release-channel`,
37-
// determine various properties of the build.
38-
match &build.config.channel[..] {
39-
"stable" => {
40-
build.release = CFG_RELEASE_NUM.to_string();
41-
build.package_vers = build.release.clone();
42-
build.unstable_features = false;
43-
}
44-
"beta" => {
45-
build.release = format!("{}-beta{}", CFG_RELEASE_NUM,
46-
CFG_PRERELEASE_VERSION);
47-
build.package_vers = "beta".to_string();
48-
build.unstable_features = false;
49-
}
50-
"nightly" => {
51-
build.release = format!("{}-nightly", CFG_RELEASE_NUM);
52-
build.package_vers = "nightly".to_string();
53-
build.unstable_features = true;
54-
}
55-
_ => {
56-
build.release = format!("{}-dev", CFG_RELEASE_NUM);
57-
build.package_vers = build.release.clone();
58-
build.unstable_features = true;
59-
}
60-
}
61-
build.version = build.release.clone();
37+
struct Info {
38+
commit_date: String,
39+
sha: String,
40+
short_sha: String,
41+
}
6242

63-
// If we have a git directory, add in some various SHA information of what
64-
// commit this compiler was compiled from.
65-
if build.src.join(".git").is_dir() {
66-
let ver_date = output(Command::new("git").current_dir(&build.src)
43+
impl GitInfo {
44+
pub fn new(dir: &Path) -> GitInfo {
45+
if !dir.join(".git").is_dir() {
46+
return GitInfo { inner: None }
47+
}
48+
let ver_date = output(Command::new("git").current_dir(dir)
6749
.arg("log").arg("-1")
6850
.arg("--date=short")
6951
.arg("--pretty=format:%cd"));
70-
let ver_hash = output(Command::new("git").current_dir(&build.src)
52+
let ver_hash = output(Command::new("git").current_dir(dir)
7153
.arg("rev-parse").arg("HEAD"));
7254
let short_ver_hash = output(Command::new("git")
73-
.current_dir(&build.src)
55+
.current_dir(dir)
7456
.arg("rev-parse")
7557
.arg("--short=9")
7658
.arg("HEAD"));
77-
let ver_date = ver_date.trim().to_string();
78-
let ver_hash = ver_hash.trim().to_string();
79-
let short_ver_hash = short_ver_hash.trim().to_string();
80-
build.version.push_str(&format!(" ({} {})", short_ver_hash,
81-
ver_date));
82-
build.ver_date = Some(ver_date.to_string());
83-
build.ver_hash = Some(ver_hash);
84-
build.short_ver_hash = Some(short_ver_hash);
59+
GitInfo {
60+
inner: Some(Info {
61+
commit_date: ver_date.trim().to_string(),
62+
sha: ver_hash.trim().to_string(),
63+
short_sha: short_ver_hash.trim().to_string(),
64+
}),
65+
}
66+
}
67+
68+
pub fn sha(&self) -> Option<&str> {
69+
self.inner.as_ref().map(|s| &s.sha[..])
70+
}
71+
72+
pub fn sha_short(&self) -> Option<&str> {
73+
self.inner.as_ref().map(|s| &s.short_sha[..])
74+
}
75+
76+
pub fn commit_date(&self) -> Option<&str> {
77+
self.inner.as_ref().map(|s| &s.commit_date[..])
78+
}
79+
80+
pub fn version(&self, build: &Build, num: &str) -> String {
81+
let mut version = build.release(num);
82+
if let Some(ref inner) = self.inner {
83+
version.push_str(" (");
84+
version.push_str(&inner.short_sha);
85+
version.push_str(" ");
86+
version.push_str(&inner.commit_date);
87+
version.push_str(")");
88+
}
89+
return version
8590
}
8691
}

Diff for: src/bootstrap/compile.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::process::Command;
2424
use build_helper::{output, mtime, up_to_date};
2525
use filetime::FileTime;
2626

27+
use channel::GitInfo;
2728
use util::{exe, libdir, is_dylib, copy};
2829
use {Build, Compiler, Mode};
2930

@@ -210,9 +211,9 @@ pub fn rustc(build: &Build, target: &str, compiler: &Compiler) {
210211

211212
// Set some configuration variables picked up by build scripts and
212213
// the compiler alike
213-
cargo.env("CFG_RELEASE", &build.release)
214+
cargo.env("CFG_RELEASE", build.rust_release())
214215
.env("CFG_RELEASE_CHANNEL", &build.config.channel)
215-
.env("CFG_VERSION", &build.version)
216+
.env("CFG_VERSION", build.rust_version())
216217
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or(PathBuf::new()));
217218

218219
if compiler.stage == 0 {
@@ -229,13 +230,13 @@ pub fn rustc(build: &Build, target: &str, compiler: &Compiler) {
229230
cargo.env_remove("RUSTC_DEBUGINFO_LINES");
230231
}
231232

232-
if let Some(ref ver_date) = build.ver_date {
233+
if let Some(ref ver_date) = build.rust_info.commit_date() {
233234
cargo.env("CFG_VER_DATE", ver_date);
234235
}
235-
if let Some(ref ver_hash) = build.ver_hash {
236+
if let Some(ref ver_hash) = build.rust_info.sha() {
236237
cargo.env("CFG_VER_HASH", ver_hash);
237238
}
238-
if !build.unstable_features {
239+
if !build.unstable_features() {
239240
cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
240241
}
241242
// Flag that rust llvm is in use
@@ -416,13 +417,32 @@ pub fn tool(build: &Build, stage: u32, target: &str, tool: &str) {
416417
// build.clear_if_dirty(&out_dir, &libstd_stamp(build, stage, &host, target));
417418

418419
let mut cargo = build.cargo(&compiler, Mode::Tool, target, "build");
419-
cargo.arg("--manifest-path")
420-
.arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool)));
420+
let dir = build.src.join("src/tools").join(tool);
421+
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
421422

422423
// We don't want to build tools dynamically as they'll be running across
423424
// stages and such and it's just easier if they're not dynamically linked.
424425
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
425426

427+
if let Some(dir) = build.openssl_install_dir(target) {
428+
cargo.env("OPENSSL_STATIC", "1");
429+
cargo.env("OPENSSL_DIR", dir);
430+
cargo.env("LIBZ_SYS_STATIC", "1");
431+
}
432+
433+
cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel);
434+
435+
let info = GitInfo::new(&dir);
436+
if let Some(sha) = info.sha() {
437+
cargo.env("CFG_COMMIT_HASH", sha);
438+
}
439+
if let Some(sha_short) = info.sha_short() {
440+
cargo.env("CFG_SHORT_COMMIT_HASH", sha_short);
441+
}
442+
if let Some(date) = info.commit_date() {
443+
cargo.env("CFG_COMMIT_DATE", date);
444+
}
445+
426446
build.run(&mut cargo);
427447
}
428448

0 commit comments

Comments
 (0)