Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inform build scripts of rustc compiler context #9601

Merged
merged 19 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Remove RUSTC_VERSION envvar
  • Loading branch information
Jon Gjengset committed Jul 16, 2021
commit 1cbce4705131b6d3a18afcaa6a7b18ddad540ea4
8 changes: 0 additions & 8 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,14 +1041,6 @@ pub fn is_nightly() -> bool {
&& (vv.contains("-nightly") || vv.contains("-dev"))
}

pub fn rustc_release() -> &'static str {
RUSTC_INFO
.verbose_version
.lines()
.find_map(|line| line.strip_prefix("release: "))
.expect("verbose version has release: field")
}

pub fn process<T: AsRef<OsStr>>(t: T) -> ProcessBuilder {
_process(t.as_ref())
}
Expand Down
8 changes: 0 additions & 8 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,6 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
bcx.rustflags_args(unit).join("\x1f"),
);
cmd.env_remove("RUSTFLAGS");
let version = &bcx.rustc().version;
cmd.env(
"RUSTC_VERSION",
format!("{}.{}.{}", version.major, version.minor, version.patch),
);
cmd.env("RUSTC_VERSION_MAJOR", version.major.to_string());
cmd.env("RUSTC_VERSION_MINOR", version.minor.to_string());
cmd.env("RUSTC_VERSION_PATCH", version.patch.to_string());

// Gather the set of native dependencies that this package has along with
// some other variables to close over.
Expand Down
4 changes: 0 additions & 4 deletions src/doc/src/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,6 @@ let out_dir = env::var("OUT_DIR").unwrap();
(ASCII Unit Separator). See
[`build.rustflags`].
* `CARGO_PKG_<var>` - The package information variables, with the same names and values as are [provided during crate building][variables set for crates].
* `RUSTC_VERSION` - The version of rustc used by the cargo that invokes
the build script. Its constituent parts are also
available as `RUSTC_VERSION_MAJOR`, `_MINOR`, and
`_PATCH`.

[unix-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows
[windows-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows
Expand Down
17 changes: 1 addition & 16 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::tools;
use cargo_test_support::{basic_manifest, cross_compile, is_coarse_mtime, project};
use cargo_test_support::{
rustc_host, rustc_release, sleep_ms, slow_cpu_multiplier, symlink_supported,
};
use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported};
use cargo_util::paths::remove_dir_all;
use std::env;
use std::fs;
Expand Down Expand Up @@ -82,7 +80,6 @@ fn custom_build_env_vars() {
)
.file("bar/src/lib.rs", "pub fn hello() {}");

let rustc_version = semver::Version::parse(rustc_release()).unwrap();
let file_content = format!(
r#"
use std::env;
Expand Down Expand Up @@ -126,25 +123,13 @@ fn custom_build_env_vars() {
assert!(env::var("RUSTFLAGS").is_err());
let rustflags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();
assert_eq!(rustflags, "");

let version = env::var("RUSTC_VERSION").unwrap();
assert_eq!(version, "{1}.{2}.{3}", "bad rust version");
let version = env::var("RUSTC_VERSION_MAJOR").unwrap();
assert_eq!(version, "{1}");
let version = env::var("RUSTC_VERSION_MINOR").unwrap();
assert_eq!(version, "{2}");
let version = env::var("RUSTC_VERSION_PATCH").unwrap();
assert_eq!(version, "{3}");
}}
"#,
p.root()
.join("target")
.join("debug")
.join("build")
.display(),
rustc_version.major,
rustc_version.minor,
rustc_version.patch,
);

let p = p.file("bar/build.rs", &file_content).build();
Expand Down