From 841687a1af2ea48cb49de7ba12760efa7ae7dc6a Mon Sep 17 00:00:00 2001 From: kekeimiku Date: Fri, 5 Apr 2024 21:42:50 +0800 Subject: [PATCH] iOS initial support Usage: IPHONEOS_DEPLOYMENT_TARGET="13.1 cargo build --target aarch64-apple-ios --release codesign -d -s - --entitlements build_tools/ios_entitlements.xml target/aarch64-apple-ios/release/fish Closes #10993 --- build.rs | 9 +- build_tools/ios_entitlements.xml | 392 +++++++++++++++++++++++++++++++ src/bin/fish.rs | 2 +- src/env_dispatch.rs | 2 +- src/env_universal_common.rs | 4 +- src/exec.rs | 2 +- src/fallback.rs | 4 +- src/fd_readable_set.rs | 8 +- src/fds.rs | 4 +- src/fork_exec/postfork.rs | 4 +- src/signal.rs | 4 +- src/topic_monitor.rs | 2 +- src/universal_notifier/mod.rs | 4 +- 13 files changed, 419 insertions(+), 22 deletions(-) create mode 100644 build_tools/ios_entitlements.xml diff --git a/build.rs b/build.rs index c633905e2..1e030c9df 100644 --- a/build.rs +++ b/build.rs @@ -88,6 +88,7 @@ fn detect_cfgs(target: &mut Target) { "", &(|_: &Target| Ok(false)) as &dyn Fn(&Target) -> Result>, ), + ("apple", &detect_apple), ("bsd", &detect_bsd), ("gettext", &have_gettext), ("small_main_stack", &has_small_stack), @@ -123,6 +124,10 @@ fn detect_cfgs(target: &mut Target) { } } +fn detect_apple(_: &Target) -> Result> { + Ok(cfg!(any(target_os = "ios", target_os = "macos"))) +} + /// Detect if we're being compiled for a BSD-derived OS, allowing targeting code conditionally with /// `#[cfg(bsd)]`. /// @@ -199,14 +204,14 @@ fn have_gettext(target: &Target) -> Result> { /// 0.5 MiB is small enough that we'd have to drastically reduce MAX_STACK_DEPTH to less than 10, so /// we instead use a workaround to increase the main thread size. fn has_small_stack(_: &Target) -> Result> { - #[cfg(not(any(target_os = "macos", target_os = "netbsd")))] + #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "netbsd")))] return Ok(false); // NetBSD 10 also needs this but can't find pthread_get_stacksize_np. #[cfg(target_os = "netbsd")] return Ok(true); - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "ios", target_os = "macos"))] { use core::ffi; diff --git a/build_tools/ios_entitlements.xml b/build_tools/ios_entitlements.xml new file mode 100644 index 000000000..7343a8981 --- /dev/null +++ b/build_tools/ios_entitlements.xml @@ -0,0 +1,392 @@ + + + + + platform-application + + com.apple.private.security.no-container + + com.apple.private.security.container-manager + + com.apple.private.skip-library-validation + + com.apple.private.MobileContainerManager.allowed + + com.apple.private.security.storage.adprivacyd + + com.apple.private.security.storage.amfid + + com.apple.private.security.storage.AppBundles + + com.apple.private.security.storage.AppDataContainers + + com.apple.private.security.storage.automation-mode + + com.apple.private.security.storage.Biome + + com.apple.private.security.storage.Calendar + + com.apple.private.security.storage.CallHistory + + com.apple.private.security.storage.CarrierBundles + + com.apple.private.security.storage.chronod + + com.apple.private.security.storage.CloudDocsDB + + com.apple.private.security.storage.CloudKit + + com.apple.private.security.storage.containers + + com.apple.private.security.storage.CoreFollowUp + + com.apple.private.security.storage.CoreKnowledge + + com.apple.private.security.storage.Cryptex + + com.apple.private.security.storage.demo_backup + + com.apple.private.security.storage.DocumentRevisions + + com.apple.private.security.storage.DumpPanic + + com.apple.private.security.storage.ExposureNotification + + com.apple.private.security.storage.FaceTime + + com.apple.private.security.storage.familycircled + + com.apple.private.security.storage.FindMy + + com.apple.private.security.storage.fpsd + + com.apple.private.security.storage.Health + + com.apple.private.security.storage.HomeAI + + com.apple.private.security.storage.HomeKit + + com.apple.private.security.storage.iCloudDrive + + com.apple.private.security.storage.idcredd + + com.apple.private.security.storage.IdentityServices + + com.apple.private.security.storage.kbd + + com.apple.private.security.storage.Keychains + + com.apple.private.security.storage.Lockdown + + com.apple.private.security.storage.Mail + + com.apple.private.security.storage.Messages + + com.apple.private.security.storage.MessagesMetaData + + com.apple.private.security.storage.MobileContainerManager + + com.apple.private.security.storage.MobileDocuments + + com.apple.private.security.storage.MobileIdentityService + + com.apple.private.security.storage.mobilesync + + com.apple.private.security.storage.multimodalsearchd + + com.apple.private.security.storage.NanoTimeKit.FaceSupport + + com.apple.private.security.storage.News + + com.apple.private.security.storage.Notes + + com.apple.private.security.storage.Photos + + com.apple.private.security.storage.PhotosLibraries + + com.apple.private.security.storage.pipelined + + com.apple.private.security.storage.preferences + + com.apple.private.security.storage.PrivacyAccounting + + com.apple.private.security.storage.Safari + + com.apple.private.security.storage.SearchParty + + com.apple.private.security.storage.SecureElementService + + com.apple.private.security.storage.SensorKit + + com.apple.private.security.storage.SFAnalytics + + com.apple.private.security.storage.SiriInference + + com.apple.private.security.storage.SiriReferenceResolution + + com.apple.private.security.storage.SiriVocabulary + + com.apple.private.security.storage.SoC + + com.apple.private.security.storage.SpeechPersonalizedLM + + com.apple.private.security.storage.Spotlight + + com.apple.private.security.storage.StatusKit + + com.apple.private.security.storage.Stocks + + com.apple.private.security.storage.Suggestions + + com.apple.private.security.storage.SymptomFramework + + com.apple.private.security.storage.sysdagnose.ScreenshotServicesService + + com.apple.private.security.storage.TCC + + com.apple.private.security.storage.TimeMachine + + com.apple.private.security.storage.triald + + com.apple.private.security.storage.trustd + + com.apple.private.security.storage.trustd-private + + com.apple.private.security.storage.universalaccess + + com.apple.private.security.storage.Voicemail + + com.apple.private.security.storage.Wireless + + com.apple.private.security.disk-device-access + + com.apple.rootless.storage.ane_model_cache + + com.apple.rootless.storage.apfs_boot_mount + + com.apple.rootless.storage.clientScripter + + com.apple.rootless.storage.com.apple.mediaanalysisd + + com.apple.rootless.storage.com.apple.MobileAsset.CarPlayAppBlacklist + + com.apple.rootless.storage.com.apple.MobileAsset.DeviceCheck + + com.apple.rootless.storage.com.apple.MobileAsset.DictionaryServices.dictionary2 + + com.apple.rootless.storage.com.apple.MobileAsset.DuetExpertCenterAsset + + com.apple.rootless.storage.com.apple.MobileAsset.EmbeddedNL + + com.apple.rootless.storage.com.apple.MobileAsset.Font5 + + com.apple.rootless.storage.com.apple.MobileAsset.Font6 + + com.apple.rootless.storage.com.apple.MobileAsset.HealthKt.FeatureAvailability + + com.apple.rootless.storage.com.apple.MobileAsset.HomeKit + + com.apple.rootless.storage.com.apple.MobileAsset.MacinTalkVoiceAssets + + com.apple.rootless.storage.com.apple.MobileAsset.MailDynamicData + + com.apple.rootless.storage.com.apple.MobileAsset.MXLongFormVideoApps + + com.apple.rootless.storage.com.apple.MobileAsset.network.networknomicon + + com.apple.rootless.storage.com.apple.MobileAsset.PKITrustSupplementals + + com.apple.rootless.storage.com.apple.MobileAsset.SharingDeviceAssets + + com.apple.rootless.storage.com.apple.MobileAsset.SiriShortcutsMobileAsset + + com.apple.rootless.storage.com.apple.MobileAsset.TimeZoneUpdate + + com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.CombinedVocalizerVoices + + com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.CustomVoice + + com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.GryphonVoice + + com.apple.rootless.storage.com.apple.MobileAsset.VoiceServicesVocalizerVoice + + com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.VoiceResources + + com.apple.rootless.storage.com.apple.MobileAsset.VoiceTriggerAssets + + com.apple.rootless.storage.CoreAnalytics + + com.apple.rootless.storage.coreduet_knowledge_store + + com.apple.rootless.storage.coreidvd + + com.apple.rootless.storage.coreknowledge + + com.apple.rootless.storage.CoreRoutine + + com.apple.rootless.storage.CoreSpeech + + com.apple.rootless.storage.dmd + + com.apple.rootless.storage.dprivacyd_storage + + com.apple.rootless.storage.ExtensibleSSO + + com.apple.rootless.storage.facekit + + com.apple.rootless.storage.fpsd + + com.apple.rootless.storage.MobileStorageMounter + + com.apple.rootless.storage.MusicApp + + com.apple.rootless.storage.nsurlsessiond + + com.apple.rootless.storage.pearl-field-diagnostics + + com.apple.rootless.storage.proactivepredictions + + com.apple.rootless.storage.QLThumbnailCache + + com.apple.rootless.storage.remotemanagementd + + com.apple.rootless.storage.RoleAccountStaging + + com.apple.rootless.storage.sensorkit + + com.apple.rootless.storage.shortcuts + + com.apple.rootless.storage.siriremembers + + com.apple.rootless.storage.timezone + + com.apple.rootless.storage.triald + + com.apple.rootless.storage.voiceshortcuts + + com.apple.private.security.storage-exempt.heritable + + com.apple.private.security.storage.AppleMediaServices + + com.apple.private.security.storage.ContactlessReader + + com.apple.private.security.storage.CoreRoutine + + com.apple.private.security.storage.DiagnosticReports + + com.apple.private.security.storage.DiagnosticReports.read-write + + com.apple.private.security.storage.DoNotDisturb + + com.apple.private.security.storage.Home + + com.apple.private.security.storage.IntelligencePlatform + + com.apple.private.security.storage.Location + + com.apple.private.security.storage.ManagedConfiguration + + com.apple.private.security.storage.MapsSync + + com.apple.private.security.storage.MobileBackup + + com.apple.private.security.storage.MobileStorageMounter + + com.apple.private.security.storage.PassKit + + com.apple.private.security.storage.SiriFeatureStore + + com.apple.private.security.storage.SiriSELF + + com.apple.private.security.storage.SoundProfileAsset + + com.apple.private.security.storage.TextUnderstanding + + com.apple.private.security.storage.Weather + + com.apple.private.security.storage.appleaccountd + + com.apple.private.security.storage.ciconia + + com.apple.private.security.storage.clipserviced + + com.apple.private.security.storage.coreduet_knowledge_store + + com.apple.private.security.storage.driverkitd + + com.apple.private.security.storage.geoanalyticsd + + com.apple.private.security.storage.geod + + com.apple.private.security.storage.launchd + + com.apple.private.security.storage.sessionkitd + + com.apple.private.security.storage.sysdiagnose.ScreenshotServicesService + + com.apple.private.security.storage.sysdiagnose.sysdiagnose + + com.apple.private.security.storage.tmp + + com.apple.rootless.critical + + com.apple.rootless.datavault.metadata + + com.apple.rootless.install + + com.apple.rootless.install.heritable + + com.apple.rootless.restricted-block-devices + + com.apple.rootless.storage.MobileAssetDownload + + com.apple.rootless.storage.amsengagementd + + com.apple.rootless.storage.com.apple.MobileAsset.HealthKit.FeatureAvailability + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriDialogAssets + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriExperienceCam + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriFindMyConfigurationFiles + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriInferredHelpfulness + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriTextToSpeech + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAsrAssistant + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAsrHammer + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAsrUaap + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAttentionAssets + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingMorphun + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingNL + + com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingNLOverrides + + com.apple.rootless.storage.coreparsec_feedbacks + + com.apple.rootless.storage.coreparsec_uploadables + + com.apple.rootless.storage.early_boot_mount + + com.apple.rootless.storage.screentime + + com.apple.rootless.volume.ISCRecovery + + com.apple.rootless.volume.Preboot + + com.apple.rootless.volume.Recovery + + com.apple.rootless.volume.Update + + com.apple.rootless.volume.VM + + com.apple.rootless.volume.iSCPreboot + + + diff --git a/src/bin/fish.rs b/src/bin/fish.rs index ddd9f5ae4..5de92bd56 100644 --- a/src/bin/fish.rs +++ b/src/bin/fish.rs @@ -229,7 +229,7 @@ fn tv_to_msec(tv: &libc::timeval) -> i64 { fn print_rusage_self() { let rs = getrusage(RUsage::RSelf); - let rss_kb = if cfg!(target_os = "macos") { + let rss_kb = if cfg!(apple) { // mac use bytes. rs.ru_maxrss / 1024 } else { diff --git a/src/env_dispatch.rs b/src/env_dispatch.rs index f308554f4..a55b36d7c 100644 --- a/src/env_dispatch.rs +++ b/src/env_dispatch.rs @@ -496,7 +496,7 @@ fn update_fish_color_support(vars: &EnvStack) { /// Apply any platform- or environment-specific hacks to our terminfo [`Term`] instance. fn apply_term_hacks(vars: &EnvStack, term: &mut Term) { - if cfg!(target_os = "macos") { + if cfg!(apple) { // Hack in missing italics and dim capabilities omitted from macOS xterm-256color terminfo. // Improves the user experience under Terminal.app and iTerm. let term_prog = vars diff --git a/src/env_universal_common.rs b/src/env_universal_common.rs index 9c8099e0e..a3af99737 100644 --- a/src/env_universal_common.rs +++ b/src/env_universal_common.rs @@ -28,10 +28,10 @@ use std::os::unix::prelude::MetadataExt; // Pull in the O_EXLOCK constant if it is defined, otherwise set it to 0. -#[cfg(any(bsd, target_os = "macos"))] +#[cfg(any(apple, bsd))] const O_EXLOCK: OFlag = OFlag::O_EXLOCK; -#[cfg(not(any(bsd, target_os = "macos")))] +#[cfg(not(any(apple, bsd)))] const O_EXLOCK: OFlag = OFlag::empty(); /// Callback data, reflecting a change in universal variables. diff --git a/src/exec.rs b/src/exec.rs index bf4f86baa..89b8b86f4 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -317,7 +317,7 @@ fn exit_code_from_exec_error(err: libc::c_int) -> libc::c_int { // The file is not executable for various reasons. STATUS_NOT_EXECUTABLE } - #[cfg(target_os = "macos")] + #[cfg(apple)] libc::EBADARCH => { // This is for e.g. running ARM app on Intel Mac. STATUS_NOT_EXECUTABLE diff --git a/src/fallback.rs b/src/fallback.rs index 1af9e6aff..d83d516c2 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -110,12 +110,12 @@ pub fn fish_wcswidth(s: &wstr) -> isize { // otherwise it uses mkstemp followed by fcntl pub fn fish_mkstemp_cloexec(name_template: CString) -> Result<(File, CString), Errno> { let name = name_template.into_raw(); - #[cfg(not(target_os = "macos"))] + #[cfg(not(apple))] let fd = { use libc::O_CLOEXEC; unsafe { libc::mkostemp(name, O_CLOEXEC) } }; - #[cfg(target_os = "macos")] + #[cfg(apple)] let fd = { use libc::{FD_CLOEXEC, F_SETFD}; let fd = unsafe { libc::mkstemp(name) }; diff --git a/src/fd_readable_set.rs b/src/fd_readable_set.rs index 4ef13c42c..0d2c4e7fe 100644 --- a/src/fd_readable_set.rs +++ b/src/fd_readable_set.rs @@ -42,14 +42,14 @@ pub fn poll_fd_readable(fd: i32) -> bool { /// This allows accumulating a set of fds and then seeing if they are readable. /// This only handles readability. /// Apple's `man poll`: "The poll() system call currently does not support devices." -#[cfg(target_os = "macos")] +#[cfg(apple)] pub struct FdReadableSet { // The underlying fdset and nfds value to pass to select(). fdset_: libc::fd_set, nfds_: c_int, } -#[cfg(target_os = "macos")] +#[cfg(apple)] impl FdReadableSet { /// Construct an empty set. pub fn new() -> FdReadableSet { @@ -124,12 +124,12 @@ pub fn poll_fd_readable(fd: RawFd) -> bool { } } -#[cfg(not(target_os = "macos"))] +#[cfg(not(apple))] pub struct FdReadableSet { pollfds_: Vec, } -#[cfg(not(target_os = "macos"))] +#[cfg(not(apple))] impl FdReadableSet { /// Construct an empty set. pub fn new() -> FdReadableSet { diff --git a/src/fds.rs b/src/fds.rs index fbc7507db..6a8934d43 100644 --- a/src/fds.rs +++ b/src/fds.rs @@ -263,7 +263,7 @@ mod o_search { /// On macOS we have O_SEARCH, which is defined as O_EXEC | O_DIRECTORY, /// where O_EXEC is 0x40000000. This is only on macOS 12.0+ or later; however /// prior macOS versions ignores O_EXEC so it is treated the same as O_RDONLY. - #[cfg(target_os = "macos")] + #[cfg(apple)] pub const BEST_O_SEARCH: OFlag = OFlag::from_bits_truncate(libc::O_DIRECTORY | 0x40000000); /// On FreeBSD, we have O_SEARCH = 0x00040000. @@ -277,10 +277,10 @@ mod o_search { /// Fall back to O_RDONLY. #[cfg(not(any( + apple, target_os = "linux", target_os = "android", target_os = "freebsd", - target_os = "macos" )))] pub const BEST_O_SEARCH: OFlag = OFlag::O_RDONLY; } diff --git a/src/fork_exec/postfork.rs b/src/fork_exec/postfork.rs index b2f267ce9..0bb9990f0 100644 --- a/src/fork_exec/postfork.rs +++ b/src/fork_exec/postfork.rs @@ -131,7 +131,7 @@ pub fn execute_setpgid(pid: Pid, pgroup: Pid, is_parent: bool) -> i32 { // 12.2) does not consider a child that has already forked, exec'd, and exited to "exist" // and returns ESRCH (process not found) instead of EACCES (child has called exec). // See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=251227 - #[cfg(any(bsd, target_os = "macos"))] + #[cfg(any(apple, bsd))] if err == libc::ESRCH && is_parent { // Handle this just like we would EACCES above, as we're virtually certain that // setpgid(2) was called against a process that was at least at one point in time a @@ -484,7 +484,7 @@ pub(crate) fn safe_report_exec_error( ); } - #[cfg(target_os = "macos")] + #[cfg(apple)] libc::EBADARCH => { FLOG_SAFE!( exec, diff --git a/src/signal.rs b/src/signal.rs index 79766c183..e0b4a5d20 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -401,10 +401,10 @@ macro_rules! signal_entry { signal_entry!(SIGSYS, "Bad system call"), signal_entry!(SIGIOT, "Abort (Alias for SIGABRT)"), - #[cfg(any(bsd, target_os = "macos"))] + #[cfg(any(apple, bsd))] signal_entry!(SIGEMT, "Unused signal"), - #[cfg(any(bsd, target_os = "macos"))] + #[cfg(any(apple, bsd))] signal_entry!(SIGINFO, "Information request"), #[cfg(target_os = "linux")] diff --git a/src/topic_monitor.rs b/src/topic_monitor.rs index 4698001f3..0c80c8115 100644 --- a/src/topic_monitor.rs +++ b/src/topic_monitor.rs @@ -263,7 +263,7 @@ pub fn die(&self, msg: &str) { // sem_destroy has been deprecated since macOS 10.10 but we only use it under Linux so silence the // warning. -#[cfg_attr(target_os = "macos", allow(deprecated))] +#[cfg_attr(apple, allow(deprecated))] impl Drop for BinarySemaphore { fn drop(&mut self) { if let Self::Semaphore(sem) = self { diff --git a/src/universal_notifier/mod.rs b/src/universal_notifier/mod.rs index 7fdccef06..858129d36 100644 --- a/src/universal_notifier/mod.rs +++ b/src/universal_notifier/mod.rs @@ -1,7 +1,7 @@ use once_cell::sync::OnceCell; use std::os::fd::RawFd; -#[cfg(target_os = "macos")] +#[cfg(apple)] mod notifyd; #[cfg(any(target_os = "android", target_os = "linux"))] @@ -53,7 +53,7 @@ fn notification_fd_became_readable(&self, _fd: RawFd) -> bool { /// Create a notifier. pub fn create_notifier() -> Box { - #[cfg(target_os = "macos")] + #[cfg(apple)] if let Some(notifier) = notifyd::NotifydNotifier::new() { return Box::new(notifier); }