-
Notifications
You must be signed in to change notification settings - Fork 472
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
add Build::apple_deployment_target function #938
Closed
Closed
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -88,6 +88,7 @@ use tool::ToolFamily; | |
/// documentation on each method itself. | ||
#[derive(Clone, Debug)] | ||
pub struct Build { | ||
apple_deployment_target: Option<Arc<str>>, | ||
include_directories: Vec<Arc<Path>>, | ||
definitions: Vec<(Arc<str>, Option<Arc<str>>)>, | ||
objects: Vec<Arc<Path>>, | ||
|
@@ -202,6 +203,7 @@ impl Build { | |
/// [`compile`]: struct.Build.html#method.compile | ||
pub fn new() -> Build { | ||
Build { | ||
apple_deployment_target: None, | ||
include_directories: Vec::new(), | ||
definitions: Vec::new(), | ||
objects: Vec::new(), | ||
|
@@ -1727,7 +1729,7 @@ impl Build { | |
map_darwin_target_from_rust_to_compiler_architecture(target) | ||
{ | ||
let deployment_target = | ||
self.apple_deployment_version(AppleOs::Ios, target, None); | ||
self.get_apple_deployment_target(AppleOs::Ios, target, None); | ||
cmd.args.push( | ||
format!( | ||
"--target={}-apple-ios{}-simulator", | ||
|
@@ -1741,7 +1743,7 @@ impl Build { | |
map_darwin_target_from_rust_to_compiler_architecture(target) | ||
{ | ||
let deployment_target = | ||
self.apple_deployment_version(AppleOs::WatchOs, target, None); | ||
self.get_apple_deployment_target(AppleOs::WatchOs, target, None); | ||
cmd.args.push( | ||
format!( | ||
"--target={}-apple-watchos{}-simulator", | ||
|
@@ -1755,7 +1757,7 @@ impl Build { | |
map_darwin_target_from_rust_to_compiler_architecture(target) | ||
{ | ||
let deployment_target = | ||
self.apple_deployment_version(AppleOs::TvOs, target, None); | ||
self.get_apple_deployment_target(AppleOs::TvOs, target, None); | ||
cmd.args.push( | ||
format!( | ||
"--target={}-apple-tvos{}-simulator", | ||
|
@@ -1769,7 +1771,7 @@ impl Build { | |
map_darwin_target_from_rust_to_compiler_architecture(target) | ||
{ | ||
let deployment_target = | ||
self.apple_deployment_version(AppleOs::TvOs, target, None); | ||
self.get_apple_deployment_target(AppleOs::TvOs, target, None); | ||
cmd.args.push( | ||
format!("--target={}-apple-tvos{}", arch, deployment_target).into(), | ||
); | ||
|
@@ -2278,6 +2280,16 @@ impl Build { | |
Ok(()) | ||
} | ||
|
||
/// For Apple targets, set the minimum OS version that the compiled binary could be run on. | ||
/// The environment variable {MACOSX,IPHONEOS,WATCHOS,TVOS}_DEPLOYMENT_TARGET takes | ||
/// precedence over this if it is set. | ||
/// | ||
/// This has no effect on non-Apple targets. | ||
pub fn apple_deployment_target(&mut self, version: &str) -> &mut Self { | ||
self.apple_deployment_target = Some(version.into()); | ||
self | ||
} | ||
|
||
fn apple_flags(&self, cmd: &mut Tool) -> Result<(), Error> { | ||
#[allow(dead_code)] | ||
enum ArchSpec { | ||
|
@@ -2372,7 +2384,7 @@ impl Build { | |
} | ||
}; | ||
|
||
let min_version = self.apple_deployment_version(os, &target, Some(arch_str)); | ||
let min_version = self.get_apple_deployment_target(os, &target, Some(arch_str)); | ||
let (sdk_prefix, sim_prefix) = match os { | ||
AppleOs::MacOs => ("macosx", ""), | ||
AppleOs::Ios => ("iphone", "ios-"), | ||
|
@@ -3321,7 +3333,7 @@ impl Build { | |
Ok(ret) | ||
} | ||
|
||
fn apple_deployment_version( | ||
fn get_apple_deployment_target( | ||
&self, | ||
os: AppleOs, | ||
target: &str, | ||
|
@@ -3415,6 +3427,7 @@ impl Build { | |
// an explicit target | ||
match os { | ||
AppleOs::MacOs => deployment_from_env("MACOSX_DEPLOYMENT_TARGET") | ||
.or_else(|| self.apple_deployment_target.as_ref().map(|a| a.to_string())) | ||
.or_else(|| rustc_provided_target(rustc, target)) | ||
.map(maybe_cpp_version_baseline) | ||
.unwrap_or_else(|| { | ||
|
@@ -3426,15 +3439,18 @@ impl Build { | |
}), | ||
|
||
AppleOs::Ios => deployment_from_env("IPHONEOS_DEPLOYMENT_TARGET") | ||
.or_else(|| self.apple_deployment_target.as_ref().map(|a| a.to_string())) | ||
.or_else(|| rustc_provided_target(rustc, target)) | ||
.map(maybe_cpp_version_baseline) | ||
.unwrap_or_else(|| OLD_IOS_MINIMUM_VERSION.into()), | ||
|
||
AppleOs::WatchOs => deployment_from_env("WATCHOS_DEPLOYMENT_TARGET") | ||
AppleOs::WatchOs => deployment_from_env("_DEPLOYMENT_TARGET") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an error maybe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoops, yeah that was an accident |
||
.or_else(|| self.apple_deployment_target.as_ref().map(|a| a.to_string())) | ||
.or_else(|| rustc_provided_target(rustc, target)) | ||
.unwrap_or_else(|| "5.0".into()), | ||
|
||
AppleOs::TvOs => deployment_from_env("TVOS_DEPLOYMENT_TARGET") | ||
.or_else(|| self.apple_deployment_target.as_ref().map(|a| a.to_string())) | ||
.or_else(|| rustc_provided_target(rustc, target)) | ||
.unwrap_or_else(|| "9.0".into()), | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the return type to
Cow<'_, str>
to avoid cloningstr
?