Skip to content
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

Fix linked objctive-C symbols on old macOS versions #46

Merged
merged 2 commits into from
Aug 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
extern crate cc;
use std::env;

const DEPLOYMENT_TARGET_VAR: &str = "MACOSX_DEPLOYMENT_TARGET";

fn main() {
if cfg!(target_os = "macos") {
let min_version = match env::var(DEPLOYMENT_TARGET_VAR) {
Ok(ver) => ver,
Err(_) => String::from(match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"x86_64" => "10.8", // NSUserNotificationCenter first showed up here.
"aarch64" => "11.0", // Apple silicon started here.
BlackHoleFox marked this conversation as resolved.
Show resolved Hide resolved
arch => panic!("unknown arch: {}", arch),
}),
};

cc::Build::new()
.file("objc/notify.m")
.flag("-fmodules")
.warnings(false)
.flag("-Wno-deprecated-declarations")
// `cc` doesn't try to pick up on this automatically, but `clang` needs it to
// generate a "correct" Objective-C symbol table which better matches XCode.
// See https://github.com/h4llow3En/mac-notification-sys/issues/45.
.flag(&format!("-mmacos-version-min={}", min_version))
.compile("notify");

println!("cargo:rerun-if-env-changed={}", DEPLOYMENT_TARGET_VAR);
}
}