Skip to content

Commit

Permalink
Fix: Fetch target info from Cargo even if Build::target is manually…
Browse files Browse the repository at this point in the history
… set (#1299)
  • Loading branch information
madsmtm authored Nov 22, 2024
1 parent a8f0611 commit 6a1def4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,16 @@ impl Build {
self
}

/// Configures the target this configuration will be compiling for.
/// Configures the `rustc` target this configuration will be compiling
/// for.
///
/// This option is automatically scraped from the `TARGET` environment
/// variable by build scripts, so it's not required to call this function.
/// This will fail if using a target not in a pre-compiled list taken from
/// `rustc +nightly --print target-list`. The list will be updated
/// periodically.
///
/// 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 @@ -3411,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 6a1def4

Please sign in to comment.