Skip to content

Commit a5dc9d6

Browse files
committed
Partially add the CoreServices umbrella framework
CarbonCore is still left out, but that sub-framework is usually uninteresting these days anyhow. Fixes #590. Fixes #714.
1 parent 10dca41 commit a5dc9d6

File tree

24 files changed

+667
-65
lines changed

24 files changed

+667
-65
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/header-translator/configs/builtin.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,3 @@ fn.IOServiceAddMatchingNotification.skipped = true
2525
# `objc_method_family`
2626
# TODO: Move this
2727
class.ABNewPersonViewController.methods.newPersonViewDelegate.skipped = true
28-
29-
# Dependent on target endianness
30-
typedef.WideChar.skipped = true # union+typedef in CoreServices

crates/header-translator/src/config.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ impl Config {
111111
.filter(|(_, data)| !data.skipped)
112112
.map(|(name, data)| (&**name, data))
113113
}
114+
115+
pub fn module_configs<'l>(
116+
&'l self,
117+
location: &'l Location,
118+
) -> impl Iterator<Item = &'l ModuleConfig> + 'l {
119+
self.try_library(location.library_name())
120+
.map(|library| {
121+
let mut current = &library.module;
122+
location.modules().map_while(move |component| {
123+
if let Some(module_config) = current.get(component) {
124+
current = &module_config.module;
125+
Some(module_config)
126+
} else {
127+
None
128+
}
129+
})
130+
})
131+
.into_iter()
132+
.flatten()
133+
}
114134
}
115135

116136
fn get_version<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Option<Version>, D::Error> {
@@ -241,6 +261,18 @@ pub struct LibraryConfig {
241261
#[serde(rename = "typedef")]
242262
#[serde(default)]
243263
pub typedef_data: HashMap<String, TypedefData>,
264+
265+
#[serde(default)]
266+
pub module: HashMap<String, ModuleConfig>,
267+
}
268+
269+
#[derive(Deserialize, Debug, Default, Clone, PartialEq, Eq)]
270+
#[serde(deny_unknown_fields)]
271+
pub struct ModuleConfig {
272+
#[serde(default)]
273+
pub skipped: bool,
274+
#[serde(default)]
275+
pub module: HashMap<String, ModuleConfig>,
244276
}
245277

246278
impl LibraryConfig {

crates/header-translator/src/expr.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,24 @@ impl Expr {
179179
}
180180
(TokenKind::Punctuation, punct) => {
181181
match &*punct {
182-
// These have the same semantics in C and Rust
183-
"(" | ")" | "<<" | "-" | "+" | "|" | "&" | "^" => Token::Punctuation(punct),
182+
// These have the same semantics in C and Rust (bar overflow)
183+
"(" | ")" | "<<" | "-" | "+" | "|" | "&" | "^" | "*" => {
184+
Token::Punctuation(punct)
185+
}
184186
// Bitwise not
185187
"~" => Token::Punctuation("!".to_string()),
186188
// Binary/boolean not
187189
"!" => Token::Punctuation("!".to_string()),
188-
punct => panic!("unknown expr punctuation {punct}"),
190+
punct => {
191+
error!("unknown expr punctuation {punct}");
192+
Token::Punctuation(punct.to_string())
193+
}
189194
}
190195
}
191-
(kind, spelling) => panic!("unknown expr token {kind:?}/{spelling}"),
196+
(kind, spelling) => {
197+
error!("unknown expr token {kind:?}/{spelling}");
198+
Token::Literal(spelling.to_string())
199+
}
192200
});
193201
}
194202

crates/header-translator/src/id.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,48 @@ impl Location {
5656
fn new(module_path: impl Into<Box<str>>) -> Self {
5757
let module_path = module_path.into();
5858
let module_path = match &*module_path {
59-
// Normalize Objective-C (remove submodules)
59+
// Remove submodules for Objective-C.
6060
name if name.starts_with("ObjectiveC") => "ObjectiveC".into(),
6161

62+
// Remove "Darwin" prefix for Darwin.block and Darwin.os.
63+
"Darwin.block" => "block".into(),
64+
name if name.starts_with("Darwin.os") => name.strip_prefix("Darwin.").unwrap().into(),
65+
66+
// Move os_object to os
67+
"os_object" => "os.object".into(),
68+
69+
// Various macros
70+
name if name.starts_with("os_availability") => "__builtin__".into(),
71+
"DarwinFoundation.cdefs" => "__builtin__".into(),
72+
"Darwin.libkern.OSByteOrder" => "__builtin__".into(),
73+
"TargetConditionals" => "__builtin__".into(),
74+
"Darwin.AssertMacros" => "__builtin__".into(),
75+
"Darwin.ConditionalMacros" => "__builtin__".into(),
76+
"AvailabilityMacros" => "__builtin__".into(),
77+
name if name.starts_with("_assert") => "__builtin__".into(),
78+
6279
// These types are redefined in the framework crate itself.
6380
"Darwin.MacTypes" => "__builtin__".into(),
6481

82+
// We don't emit the `hfs`, so let's act as-if CoreServices is the
83+
// one that defines the types in there (such as HFSUniStr255).
84+
name if name.starts_with("Darwin.hfs") => "CoreServices.Files".into(),
85+
6586
// int8_t, int16_t etc., translated to i8, i16 etc.
66-
"_stdint" => "__builtin__".into(),
87+
"_Builtin_stdint" | "_stdint" => "__builtin__".into(),
88+
name if name.starts_with("_Builtin_stddef") => "__builtin__".into(),
6789
// Implementation of the above
6890
"DarwinFoundation.types.machine_types" => "__builtin__".into(),
6991
// UINT_MAX, FLT_MIN, DBL_MAX, etc.
7092
// Handled manually in `expr.rs`.
7193
"_Builtin_limits" => "__builtin__".into(),
94+
// C99 bool
95+
"_Builtin_stdbool" => "__builtin__".into(),
96+
// float_t and double_t
97+
"_math" => "__builtin__".into(),
7298

7399
// `core::ffi` types
74-
"_Builtin_stdarg.va_list" => {
100+
name if name.starts_with("_Builtin_stdarg") => {
75101
warn!("va_list is not yet supported");
76102
"__core__.ffi".into()
77103
}
@@ -83,11 +109,24 @@ impl Location {
83109

84110
// `libc`
85111
name if name.starts_with("sys_types") => "__libc__".into(),
112+
name if name.starts_with("Darwin.POSIX") => "__libc__".into(),
113+
name if name.starts_with("_signal") => "__libc__".into(),
86114
"DarwinFoundation.types.sys_types" => "__libc__".into(),
87115
"DarwinFoundation.qos" => "__libc__".into(),
88-
name if name.starts_with("Darwin.POSIX") => "__libc__".into(),
89116
"_stdio" => "__libc__".into(),
90117
"_time.timespec" => "__libc__".into(),
118+
"_fenv" => "__libc__".into(),
119+
"Darwin.sys.acl" => "__libc__".into(),
120+
"_ctype" => "__libc__".into(),
121+
"_errno" => "__libc__".into(),
122+
"_locale.locale" => "__libc__".into(),
123+
"_setjmp" => "__libc__".into(),
124+
"_stdlib" => "__libc__".into(),
125+
"_string" => "__libc__".into(),
126+
"_time" => "__libc__".into(),
127+
"ptrauth" => "__libc__".into(),
128+
"Darwin.uuid" => "__libc__".into(),
129+
"unistd" => "__libc__".into(),
91130

92131
// Will be moved to the `mach2` crate in `libc` v1.0
93132
name if name.starts_with("Darwin.Mach") => "__libc__".into(),

crates/header-translator/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ fn parse_translation_unit(
352352
EntityKind::InclusionDirective if preprocessing => {
353353
let file = entity.get_file().expect("inclusion directive has file");
354354
let location = Location::from_file(file);
355+
if context.module_configs(&location).any(|c| c.skipped) {
356+
return EntityVisitResult::Continue;
357+
}
355358
if location.library_name() == library.data.framework {
356359
library.add_module(location);
357360
}
@@ -380,6 +383,11 @@ fn parse_translation_unit(
380383
.expect("expanded location file");
381384
let location = Location::from_file(file);
382385

386+
// Don't try to parse if the entire module, or supermodule, is skipped.
387+
if context.module_configs(&location).any(|c| c.skipped) {
388+
return EntityVisitResult::Continue;
389+
}
390+
383391
let module = library.module_mut(location);
384392
for stmt in Stmt::parse(&entity, context) {
385393
module.add_stmt(stmt);

crates/header-translator/src/module.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl Module {
150150

151151
writeln!(f)?;
152152

153+
let module_names: Vec<_> = self.submodules.keys().map(|name| &**name).collect();
154+
153155
for (name, module) in &self.submodules {
154156
let location = emission_location.add_module(name);
155157
if !module.submodules.is_empty() {
@@ -164,11 +166,14 @@ impl Module {
164166

165167
for stmt in &module.stmts {
166168
if let Some(item) = stmt.provided_item() {
167-
let visibility = if item.name.starts_with("__") {
168-
// Item name may conflict with module name, don't
169-
// expose at all.
170-
continue;
171-
} else if item.name.starts_with('_') {
169+
let visibility = if item.name.starts_with('_') {
170+
if let Some(name) = item.name.strip_prefix("__") {
171+
if module_names.contains(&name) {
172+
// Item name conflicts with module name, don't
173+
// expose at all.
174+
continue;
175+
}
176+
}
172177
// Try to expose, but only to the rest of the crate.
173178
"pub(crate)"
174179
} else {
@@ -282,7 +287,11 @@ impl Module {
282287
continue;
283288
}
284289
error!("removing previous file {:?}", file.path());
285-
fs::remove_file(file.path())?;
290+
if file.path().is_dir() {
291+
fs::remove_dir_all(file.path())?;
292+
} else {
293+
fs::remove_file(file.path())?;
294+
}
286295
}
287296

288297
if emission_location.is_top_level() {

crates/header-translator/src/rust_type.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,13 @@ impl Ty {
839839
TypeKind::ULongLong => Self::Primitive(Primitive::ULongLong),
840840
TypeKind::Float => Self::Primitive(Primitive::Float),
841841
TypeKind::Double => Self::Primitive(Primitive::Double),
842+
TypeKind::LongDouble => {
843+
// https://github.com/rust-lang/rust/issues/116909
844+
error!("long double is not yet supported in Rust");
845+
Self::Pointee(PointeeTy::GenericParam {
846+
name: "UnknownLongDouble".to_string(),
847+
})
848+
}
842849
TypeKind::Record => {
843850
let declaration = ty.get_declaration().expect("record declaration");
844851
let mut id = ItemIdentifier::new_optional(&declaration, context);
@@ -854,7 +861,10 @@ impl Ty {
854861
let fields = if matches!(
855862
id.name.as_deref(),
856863
Some(
857-
"MIDISysexSendRequest"
864+
"QElem"
865+
| "TMTask"
866+
| "SleepQRec"
867+
| "MIDISysexSendRequest"
858868
| "MIDISysexSendRequestUMP"
859869
| "MIDIDriverInterface"
860870
| "cssm_list_element"
@@ -1270,6 +1280,10 @@ impl Ty {
12701280
"u_int32_t" => return Self::Primitive(Primitive::U32),
12711281
"u_int64_t" => return Self::Primitive(Primitive::U64),
12721282

1283+
// math.h
1284+
"float_t" => return Self::Primitive(Primitive::Float),
1285+
"double_t" => return Self::Primitive(Primitive::Double),
1286+
12731287
// Varargs, still unsupported by Rust.
12741288
"__builtin_va_list" => return Self::Primitive(Primitive::VaList),
12751289

@@ -1284,8 +1298,6 @@ impl Ty {
12841298
"SInt64" => return Self::Primitive(Primitive::I64),
12851299
"Float32" => return Self::Primitive(Primitive::F32),
12861300
"Float64" => return Self::Primitive(Primitive::F64),
1287-
"Float80" => panic!("can't handle 80 bit MacOS float"),
1288-
"Float96" => panic!("can't handle 96 bit 68881 float"),
12891301

12901302
simd if simd.starts_with("simd_")
12911303
| simd.starts_with("vector_")

crates/header-translator/src/unexposed_attr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ impl UnexposedAttr {
128128
| "__deprecated_msg"
129129
| "__IOS_AVAILABLE"
130130
| "__IOS_DEPRECATED"
131-
| "__OSX_AVAILABLE"
131+
| "__OS_AVAILABILITY_MSG"
132132
| "__OSX_AVAILABLE_BUT_DEPRECATED"
133133
| "__OSX_AVAILABLE_BUT_DEPRECATED_MSG"
134+
| "__OSX_AVAILABLE"
134135
| "__OSX_AVAILABLE_STARTING"
135136
| "__OSX_DEPRECATED"
136137
| "__SWIFT_UNAVAILABLE_MSG"
@@ -172,6 +173,7 @@ impl UnexposedAttr {
172173
| "CS_AVAILABLE_STARTING"
173174
| "CS_CLASS_AVAILABLE"
174175
| "CS_DEPRECATED"
176+
| "CS_SWIFT_UNAVAILABLE"
175177
| "CT_AVAILABLE"
176178
| "CT_DEPRECATED"
177179
| "CT_DEPRECATED_WITH_REPLACEMENT"
@@ -292,6 +294,8 @@ impl UnexposedAttr {
292294
| "GK_BASE_AVAILABILITY_2"
293295
| "GK_BASE_AVAILABILITY_3"
294296
| "INTERAPP_AUDIO_DEPRECATED"
297+
| "MD_AVAIL"
298+
| "MD_AVAIL_LEOPARD"
295299
| "MIDI_API_UNAVAILABLE_NON_MACOS"
296300
| "MIDI_AVAILABLE_UMP1_1"
297301
| "MIDICI1_0_AVAILABILITY"

crates/objc2/src/topics/about_generated/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
7575
- `CoreFoundation` / `objc2-core-foundation`.
7676
- `CoreMedia` / `objc2-core-media`.
7777
- `CoreMIDI` / `objc2-core-midi`.
78+
- `CoreServices` / `objc2-core-services`.
7879
- `CoreText` / `objc2-core-text`.
7980
- `CoreVideo` / `objc2-core-video`.
8081
- `DiskArbitration` / `objc2-disk-arbitration`.

crates/objc2/src/topics/about_generated/list_data.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
| `CoreMedia` | [![`objc2-core-media`](https://badgen.net/crates/v/objc2-core-media)](https://crates.io/crates/objc2-core-media) | [![docs.rs](https://docs.rs/objc2-core-media/badge.svg)](https://docs.rs/objc2-core-media/) |
4343
| `CoreMediaIO` | [![`objc2-core-media-io`](https://badgen.net/crates/v/objc2-core-media-io)](https://crates.io/crates/objc2-core-media-io) | [![docs.rs](https://docs.rs/objc2-core-media-io/badge.svg)](https://docs.rs/objc2-core-media-io/) |
4444
| `CoreMotion` | [![`objc2-core-motion`](https://badgen.net/crates/v/objc2-core-motion)](https://crates.io/crates/objc2-core-motion) | [![docs.rs](https://docs.rs/objc2-core-motion/badge.svg)](https://docs.rs/objc2-core-motion/) |
45+
| `CoreServices` | [![`objc2-core-services`](https://badgen.net/crates/v/objc2-core-services)](https://crates.io/crates/objc2-core-services) | [![docs.rs](https://docs.rs/objc2-core-services/badge.svg)](https://docs.rs/objc2-core-services/) |
4546
| `CoreSpotlight` | [![`objc2-core-spotlight`](https://badgen.net/crates/v/objc2-core-spotlight)](https://crates.io/crates/objc2-core-spotlight) | [![docs.rs](https://docs.rs/objc2-core-spotlight/badge.svg)](https://docs.rs/objc2-core-spotlight/) |
4647
| `CoreTelephony` | [![`objc2-core-telephony`](https://badgen.net/crates/v/objc2-core-telephony)](https://crates.io/crates/objc2-core-telephony) | [![docs.rs](https://docs.rs/objc2-core-telephony/badge.svg)](https://docs.rs/objc2-core-telephony/) |
4748
| `CoreText` | [![`objc2-core-text`](https://badgen.net/crates/v/objc2-core-text)](https://crates.io/crates/objc2-core-text) | [![docs.rs](https://docs.rs/objc2-core-text/badge.svg)](https://docs.rs/objc2-core-text/) |

crates/test-frameworks/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ test-frameworks = [
5454
"objc2-core-media",
5555
"objc2-core-media-io",
5656
"objc2-core-motion",
57+
"objc2-core-services",
5758
"objc2-core-spotlight",
5859
"objc2-core-telephony",
5960
"objc2-core-text",
@@ -200,7 +201,7 @@ objc2-external-accessory = ["dep:objc2-external-accessory"]
200201
objc2-file-provider = ["dep:objc2-file-provider", "objc2-file-provider?/objc2-uniform-type-identifiers"]
201202
objc2-file-provider-ui = ["dep:objc2-file-provider-ui"]
202203
objc2-finder-sync = ["dep:objc2-finder-sync"]
203-
objc2-foundation = ["dep:objc2-foundation"]
204+
objc2-foundation = ["dep:objc2-foundation", "objc2-foundation?/objc2-core-services"]
204205
objc2-game-controller = ["dep:objc2-game-controller"]
205206
objc2-game-kit = ["dep:objc2-game-kit"]
206207
objc2-health-kit = ["dep:objc2-health-kit", "objc2-health-kit?/objc2-uniform-type-identifiers"]
@@ -283,6 +284,7 @@ objc2-security-interface = ["dep:objc2-security-interface"]
283284
objc2-preference-panes = ["dep:objc2-preference-panes"]
284285
objc2-safari-services = ["dep:objc2-safari-services"]
285286
objc2-accessory-setup-kit = ["dep:objc2-accessory-setup-kit"]
287+
objc2-core-services = ["dep:objc2-core-services"]
286288

287289
[dependencies]
288290
block2 = { path = "../block2" }
@@ -305,6 +307,7 @@ objc2-core-location = { path = "../../framework-crates/objc2-core-location", opt
305307
objc2-core-midi = { path = "../../framework-crates/objc2-core-midi", optional = true }
306308
objc2-core-ml = { path = "../../framework-crates/objc2-core-ml", optional = true }
307309
objc2-core-media = { path = "../../framework-crates/objc2-core-media", optional = true }
310+
objc2-core-services = { path = "../../framework-crates/objc2-core-services", optional = true }
308311
objc2-core-text = { path = "../../framework-crates/objc2-core-text", optional = true }
309312
objc2-core-video = { path = "../../framework-crates/objc2-core-video", optional = true }
310313
objc2-data-detection = { path = "../../framework-crates/objc2-data-detection", optional = true }

0 commit comments

Comments
 (0)