Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,15 @@
#
#rust.parallel-frontend-threads = 1

# Baseline commit SHA for comparing semver breakages in the Rust standard library.
# The in-tree stdlib API will be evaluated for semver breakages against this commit.
# Used for the `./x test std-semver-check` command.
# If unset, the first upstream parent commit will be used.
#
# The SHA must point to a merge commit merged into the mainline rust-lang/rust `main` branch,
# because bootstrap will attempt to download the JSON docs data for this commit from its CI.
#rust.stdlib-semver-baseline = "<commit-sha>"

# =============================================================================
# Distribution options
#
Expand Down
68 changes: 54 additions & 14 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4630,6 +4630,9 @@ fn check_if_cargo_semver_checks_is_installed(builder: &Builder<'_>) -> bool {
/// Run cargo-semver-checks on the standard library and compare its API
/// versus a previous baseline, using rustdoc JSON data.
///
/// The baseline commit can be configured using `rust.stdlib-semver-baseline`.
/// If unset, the first upstream parent commit will be used.
///
/// Fails if a semver-breaking change is detected.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StdSemverCheck {
Expand All @@ -4651,19 +4654,22 @@ impl CommandLineStep for StdSemverCheck {
panic!("cargo-semver-checks was not found, please install it");
}

let baseline_commit = match get_closest_upstream_commit(
Some(&run.builder.config.src),
&run.builder.config.git_config(),
run.builder.config.ci_env,
) {
Ok(Some(commit)) => commit,
Ok(None) => {
panic!("No baseline parent commit found for std-semver-check");
}
Err(error) => {
panic!("Cannot get baseline parent commit for std-semver-check: {error:?}");
}
};
let baseline_commit =
run.builder.config.stdlib_semver_baseline.clone().unwrap_or_else(|| {
match get_closest_upstream_commit(
Some(&run.builder.config.src),
&run.builder.config.git_config(),
run.builder.config.ci_env,
) {
Ok(Some(commit)) => commit,
Ok(None) => {
panic!("No baseline parent commit found for std-semver-check");
}
Err(error) => {
panic!("Cannot get baseline parent commit for std-semver-check: {error:?}");
}
}
});

run.builder.ensure(Self {
build_compiler: run.builder.compiler_for_std(run.builder.top_stage),
Expand Down Expand Up @@ -4698,7 +4704,41 @@ impl CommandLineStep for StdSemverCheck {
.arg(directory.join(format!("{library}.json")))
.arg("--baseline-rustdoc")
.arg(baseline_dir.join(format!("{library}.json")));
cmd.run(builder);

// We use run_capture to get the exit status
let res = cmd.allow_failure().run_capture(builder);
match res.status() {
Some(status) if status.success() => {
println!("{}\n{}", res.stdout(), res.stderr());
}
// 101 marks that csc was unable to parse the JSON data, but it did not fail with a
// semver breakage.
Some(status) if status.code() == Some(101) => {
eprintln!(
"cargo-semver-checks was unable to process {library} (this is not a fatal error)\n{}\n{}",
res.stderr(),
res.stdout()
);
}
Comment thread
jieyouxu marked this conversation as resolved.
// 100 marks semver breakage
Some(status) if status.code() == Some(100) => {
let error = format!(
"cargo-semver-checks found semver breakage in {library}\n{}\n{}",
res.stderr(),
res.stdout()
);
if builder.fail_fast {
eprintln!("{error}",);
exit!(1);
} else {
builder.config.exec_ctx().add_to_delay_failure(error);
}
}
_ => {
eprintln!("cargo-semver-checks failed.\n{}\n{}", res.stderr(), res.stdout());
exit!(1);
}
}
}
}
}
4 changes: 4 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ pub struct Config {
pub rustdoc_pgo: PgoConfig,
pub cargo_pgo: PgoConfig,

pub stdlib_semver_baseline: Option<String>,

pub llvm_libunwind_default: Option<LlvmLibunwind>,
pub enable_bolt_settings: bool,

Expand Down Expand Up @@ -610,6 +612,7 @@ impl Config {
std_features: rust_std_features,
break_on_ice: rust_break_on_ice,
rustflags: rust_rustflags,
stdlib_semver_baseline: rust_stdlib_semver_baseline,
} = toml_rust.unwrap_or_default();

let Llvm {
Expand Down Expand Up @@ -1594,6 +1597,7 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
.or(rust_rustc_debug_assertions)
.unwrap_or(rust_debug == Some(true)),
stderr_is_tty: std::io::stderr().is_terminal(),
stdlib_semver_baseline: rust_stdlib_semver_baseline,
stdout_is_tty: std::io::stdout().is_terminal(),
submodules: build_submodules,
sysconfdir: install_sysconfdir.map(PathBuf::from),
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/config/toml/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ define_config! {
std_features: Option<BTreeSet<String>> = "std-features",
break_on_ice: Option<bool> = "break-on-ice",
parallel_frontend_threads: Option<u32> = "parallel-frontend-threads",
stdlib_semver_baseline: Option<String> = "stdlib-semver-baseline",
}
}

Expand Down Expand Up @@ -384,6 +385,7 @@ pub fn check_incompatible_options_for_ci_rustc(
parallel_frontend_threads: _,
bootstrap_override_lld: _,
rustflags: _,
stdlib_semver_baseline: _,
} = ci_rust_config;

// There are two kinds of checks for CI rustc incompatible options:
Expand Down