-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Rebuild on changes to the deployment target when compiling Apple targets #129342
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
Open
madsmtm
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
madsmtm:track-deployment-target
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+227
−49
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fn main() {} |
madsmtm marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
//! Test codegen when setting deployment targets on Apple platforms. | ||
//! | ||
//! This is important since its a compatibility hazard. The linker will | ||
//! generate load commands differently based on what minimum OS it can assume. | ||
//! | ||
//! See https://github.com/rust-lang/rust/pull/105123. | ||
|
||
//@ only-apple | ||
|
||
use run_make_support::{apple_os, cmd, run_in_tmpdir, rustc, target}; | ||
|
||
/// Run vtool to check the `minos` field in LC_BUILD_VERSION. | ||
/// | ||
/// On lower deployment targets, LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS and similar | ||
/// are used instead of LC_BUILD_VERSION - these have a `version` field, so also check that. | ||
#[track_caller] | ||
fn minos(file: &str, version: &str) { | ||
cmd("vtool") | ||
.arg("-show-build") | ||
.arg(file) | ||
.run() | ||
.assert_stdout_contains_regex(format!("(minos|version) {version}")); | ||
} | ||
|
||
fn main() { | ||
// These versions should generally be higher than the default versions | ||
let (env_var, example_version, higher_example_version) = match apple_os() { | ||
"macos" => ("MACOSX_DEPLOYMENT_TARGET", "12.0", "13.0"), | ||
// armv7s-apple-ios and i386-apple-ios only supports iOS 10.0 | ||
"ios" if target() == "armv7s-apple-ios" || target() == "i386-apple-ios" => { | ||
("IPHONEOS_DEPLOYMENT_TARGET", "10.0", "10.0") | ||
} | ||
"ios" => ("IPHONEOS_DEPLOYMENT_TARGET", "15.0", "16.0"), | ||
"watchos" => ("WATCHOS_DEPLOYMENT_TARGET", "7.0", "9.0"), | ||
"tvos" => ("TVOS_DEPLOYMENT_TARGET", "14.0", "15.0"), | ||
"visionos" => ("XROS_DEPLOYMENT_TARGET", "1.1", "1.2"), | ||
_ => unreachable!(), | ||
}; | ||
let default_version = | ||
rustc().target(target()).env_remove(env_var).print("deployment-target").run().stdout_utf8(); | ||
let default_version = default_version.strip_prefix("deployment_target=").unwrap().trim(); | ||
|
||
// Test that version makes it to the object file. | ||
run_in_tmpdir(|| { | ||
let rustc = || { | ||
let mut rustc = rustc(); | ||
rustc.target(target()); | ||
rustc.crate_type("lib"); | ||
rustc.emit("obj"); | ||
rustc.input("foo.rs"); | ||
rustc.output("foo.o"); | ||
rustc | ||
}; | ||
|
||
rustc().env(env_var, example_version).run(); | ||
minos("foo.o", example_version); | ||
|
||
// FIXME(madsmtm): Doesn't work on Mac Catalyst and the simulator. | ||
if !target().contains("macabi") && !target().contains("sim") { | ||
rustc().env_remove(env_var).run(); | ||
minos("foo.o", default_version); | ||
} | ||
}); | ||
|
||
// Test that version makes it to the linker when linking dylibs. | ||
run_in_tmpdir(|| { | ||
// Certain watchOS targets don't support dynamic linking, so we disable the test on those. | ||
if apple_os() == "watchos" { | ||
return; | ||
} | ||
|
||
let rustc = || { | ||
let mut rustc = rustc(); | ||
rustc.target(target()); | ||
rustc.crate_type("dylib"); | ||
rustc.input("foo.rs"); | ||
rustc.output("libfoo.dylib"); | ||
rustc | ||
}; | ||
|
||
rustc().env(env_var, example_version).run(); | ||
minos("libfoo.dylib", example_version); | ||
|
||
// FIXME(madsmtm): Deployment target is not currently passed properly to linker | ||
// rustc().env_remove(env_var).run(); | ||
// minos("libfoo.dylib", default_version); | ||
|
||
// Test with ld64 instead | ||
|
||
rustc().arg("-Clinker-flavor=ld").env(env_var, example_version).run(); | ||
minos("libfoo.dylib", example_version); | ||
|
||
rustc().arg("-Clinker-flavor=ld").env_remove(env_var).run(); | ||
minos("libfoo.dylib", default_version); | ||
}); | ||
|
||
// Test that version makes it to the linker when linking executables. | ||
run_in_tmpdir(|| { | ||
let rustc = || { | ||
let mut rustc = rustc(); | ||
rustc.target(target()); | ||
rustc.crate_type("bin"); | ||
rustc.input("foo.rs"); | ||
rustc.output("foo"); | ||
rustc | ||
}; | ||
|
||
// FIXME(madsmtm): Doesn't work on watchOS for some reason? | ||
if !target().contains("watchos") { | ||
rustc().env(env_var, example_version).run(); | ||
minos("foo", example_version); | ||
|
||
// FIXME(madsmtm): Deployment target is not currently passed properly to linker | ||
// rustc().env_remove(env_var).run(); | ||
// minos("foo", default_version); | ||
} | ||
|
||
// Test with ld64 instead | ||
|
||
rustc().arg("-Clinker-flavor=ld").env(env_var, example_version).run(); | ||
minos("foo", example_version); | ||
|
||
rustc().arg("-Clinker-flavor=ld").env_remove(env_var).run(); | ||
minos("foo", default_version); | ||
}); | ||
|
||
// Test that changing the deployment target busts the incremental cache. | ||
run_in_tmpdir(|| { | ||
let rustc = || { | ||
let mut rustc = rustc(); | ||
rustc.target(target()); | ||
rustc.incremental("incremental"); | ||
rustc.crate_type("lib"); | ||
rustc.emit("obj"); | ||
rustc.input("foo.rs"); | ||
rustc.output("foo.o"); | ||
rustc | ||
}; | ||
|
||
rustc().env(env_var, example_version).run(); | ||
minos("foo.o", example_version); | ||
|
||
rustc().env(env_var, higher_example_version).run(); | ||
minos("foo.o", higher_example_version); | ||
|
||
// FIXME(madsmtm): Doesn't work on Mac Catalyst and the simulator. | ||
if !target().contains("macabi") && !target().contains("sim") { | ||
rustc().env_remove(env_var).run(); | ||
minos("foo.o", default_version); | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
tests/run-make/macos-deployment-target/with_deployment_target.rs
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.