Skip to content

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Jul 23, 2022

Fixes #266.

Useful for various optimizations and feature-gating functionality depending on OS version.

The expansion is roughly:

#[cfg_available(macOS(10.9), ...)]
fn my_fn() {}

// MACOSX_DEPLOYMENT_TARGET=10.9
#[cfg(any(target_os = "macos"))]
fn my_fn() {}

// MACOSX_DEPLOYMENT_TARGET=10.7
#[cfg(any(__not_available))]
fn my_fn() {}

// MACOSX_DEPLOYMENT_TARGET not set
// Available on Aarch64, since that has a higher default deployment target
#[cfg(any(not(all(target_os = "macos", not(target_arch = "aarch64")))))]
fn my_fn() {}

Further improvement would be an available! macro that checks the runtime version if the deployment target is not high enough, like this:

if available!(macOS(10.9)) {
    // Do something
} else {
    // Fallback
}

// MACOSX_DEPLOYMENT_TARGET=10.9
if cfg!(any(target_os = "macos")) {
    // Do something
} else {
    // Fallback
}

// MACOSX_DEPLOYMENT_TARGET=10.7
if runtime::check_version(10, 9, 0) {
    // Do something
} else {
    // Fallback
}

@madsmtm madsmtm added enhancement New feature or request A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates labels Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How do we handle availability?
1 participant