Skip to content

Commit

Permalink
Fetch target info from Cargo even if target is set
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 22, 2024
1 parent bf83639 commit c665211
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,9 @@ impl Build {
/// `rustc +nightly --print target-list`. The list will be updated
/// periodically.
///
/// You should avoid setting this in build scripts, as that allows `cc`
/// to instead retrieve the desired target information from the
/// environment variables that Cargo sets.
/// You should avoid setting this in build scripts, target information
/// will instead be retrieved from the environment variables `TARGET` and
/// `CARGO_CFG_TARGET_*` that Cargo sets.
///
/// # Example
///
Expand Down Expand Up @@ -3417,8 +3417,11 @@ impl Build {

fn get_target(&self) -> Result<TargetInfo<'_>, Error> {
match &self.target {
Some(t) => t.parse(),
None => self
Some(t) if Some(&**t) != self.getenv_unwrap_str("TARGET").ok().as_deref() => t.parse(),
// Fetch target information from environment if not set, or if the
// target was the same as the TARGET environment variable, in
// case the user did `build.target(&env::var("TARGET").unwrap())`.
_ => self
.build_cache
.target_info_parser
.parse_from_cargo_environment_variables(),
Expand Down

0 comments on commit c665211

Please sign in to comment.