Skip to content

Commit 7681f6c

Browse files
committed
Automatically generate #[link(...)] definitions
1 parent e32b072 commit 7681f6c

File tree

57 files changed

+61
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+61
-163
lines changed

crates/header-translator/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub struct LibraryData {
6666
#[serde(default)]
6767
pub name: Option<String>,
6868
pub imports: Vec<String>,
69+
#[serde(rename = "gnustep-library")]
70+
#[serde(default)]
71+
pub gnustep_library: Option<String>,
6972
#[serde(rename = "extra-features")]
7073
#[serde(default)]
7174
pub extra_features: Vec<String>,

crates/header-translator/src/library.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ use std::fs;
44
use std::io;
55
use std::path::Path;
66

7+
use crate::config::LibraryData;
78
use crate::file::{File, FILE_PRELUDE};
89

910
#[derive(Debug, PartialEq, Default)]
1011
pub struct Library {
1112
pub files: BTreeMap<String, File>,
13+
link_name: String,
14+
gnustep_library: Option<String>,
1215
}
1316

1417
impl Library {
15-
pub fn new() -> Self {
18+
pub fn new(name: &str, data: &LibraryData) -> Self {
1619
Self {
1720
files: BTreeMap::new(),
21+
link_name: name.to_string(),
22+
gnustep_library: data.gnustep_library.clone(),
1823
}
1924
}
2025

@@ -47,6 +52,23 @@ impl fmt::Display for Library {
4752
writeln!(f, "#![allow(unused_imports)]")?;
4853
writeln!(f, "#![allow(deprecated)]")?;
4954

55+
// Link to the correct framework
56+
//
57+
// FIXME: We always do cfg_attr(feature = "apple", ...) to make compiling things for GNUStep easier.
58+
writeln!(
59+
f,
60+
"#[cfg_attr(feature = \"apple\", link(name = \"{}\", kind = \"framework\"))]",
61+
self.link_name
62+
)?;
63+
if let Some(gnustep_library) = &self.gnustep_library {
64+
writeln!(
65+
f,
66+
"#[cfg_attr(feature = \"gnustep-1-7\", link(name = \"{}\", kind = \"dylib\"))]",
67+
gnustep_library
68+
)?;
69+
}
70+
writeln!(f, "extern \"C\" {{}}")?;
71+
5072
for name in self.files.keys() {
5173
// NOTE: some SDK files have '+' in the file name
5274
let name = name.replace('+', "_");

crates/header-translator/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn parse_sdk(index: &Index<'_>, sdk: &SdkPath, llvm_target: &str, config: &Confi
197197
let tu = get_translation_unit(index, sdk, llvm_target);
198198

199199
let mut preprocessing = true;
200-
let mut result = Output::from_libraries(config.libraries.keys());
200+
let mut result = Output::from_libraries(&config.libraries);
201201

202202
let mut library_span = None;
203203
let mut library_span_name = String::new();

crates/header-translator/src/output.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::collections::{BTreeMap, BTreeSet};
1+
use std::collections::{BTreeMap, BTreeSet, HashMap};
22
use std::str::FromStr;
33

4-
use crate::config::Config;
4+
use crate::config::{Config, LibraryData};
55
use crate::library::Library;
66
use crate::stmt::Stmt;
77

@@ -11,10 +11,10 @@ pub struct Output {
1111
}
1212

1313
impl Output {
14-
pub fn from_libraries(libraries: impl IntoIterator<Item = impl Into<String>>) -> Self {
14+
pub fn from_libraries(libraries: &HashMap<String, LibraryData>) -> Self {
1515
let libraries = libraries
16-
.into_iter()
17-
.map(|name| (name.into(), Library::new()))
16+
.iter()
17+
.map(|(name, data)| (name.into(), Library::new(name, data)))
1818
.collect();
1919
Self { libraries }
2020
}
@@ -58,6 +58,7 @@ impl Output {
5858
]
5959
.into_iter()
6060
.collect();
61+
let mut gnustep_features: BTreeSet<String> = vec![].into_iter().collect();
6162

6263
for (mut library_name, library) in &config.libraries {
6364
if let Some(alias) = &library.name {
@@ -83,6 +84,10 @@ impl Output {
8384
macos_13_features.insert(format!("{library_name}_all"));
8485
}
8586
}
87+
88+
if library.gnustep_library.is_some() {
89+
gnustep_features.insert(format!("{library_name}_all"));
90+
}
8691
}
8792

8893
let _ = features.insert(
@@ -105,6 +110,10 @@ impl Output {
105110
"unstable-frameworks-macos-13".into(),
106111
macos_13_features.into_iter().collect(),
107112
);
113+
let _ = features.insert(
114+
"unstable-frameworks-gnustep".into(),
115+
gnustep_features.into_iter().collect(),
116+
);
108117

109118
for (library_name, library) in &self.libraries {
110119
let library_alias = config.get_library_alias(library_name.clone());

crates/header-translator/translation-config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tvos = "9.0"
2727

2828
[library.AppKit]
2929
imports = ["CoreData", "Foundation"]
30+
gnustep-library = "gnustep-gui"
3031
extra-features = [
3132
# Temporary, since some structs and statics use these
3233
"AppKit_NSApplication",
@@ -189,6 +190,7 @@ ios = "11.0"
189190

190191
[library.Foundation]
191192
imports = []
193+
gnustep-library = "gnustep-base"
192194
extra-features = [
193195
"objective-c",
194196
"block",

crates/icrate/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ unstable-example-metal = [
194194

195195
# Helps with CI
196196
unstable-frameworks-all = ["unstable-frameworks-ios", "unstable-frameworks-macos-13"]
197-
unstable-frameworks-gnustep = ["AppKit_all", "Foundation_all"]
198197
unstable-frameworks-gnustep-32bit = ["Foundation_all"]
199198
# TODO: Autogenerate this
200199
unstable-frameworks-ios = ["Foundation_all", "unstable-example-basic_usage", "unstable-example-speech_synthesis"]
@@ -5298,6 +5297,10 @@ WebKit_all = [
52985297
"WebKit_WebUndefined",
52995298
"WebKit_WebView",
53005299
]
5300+
unstable-frameworks-gnustep = [
5301+
"AppKit_all",
5302+
"Foundation_all",
5303+
]
53015304
unstable-frameworks-macos-10-13 = [
53025305
"CloudKit_all",
53035306
"Contacts_all",

crates/icrate/examples/metal.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,19 @@ declare_class!(
252252
msg_send_id![mtk_view, currentDrawable];
253253

254254
// prepare for drawing
255-
let Some(current_drawable) = current_drawable else { return; };
256-
let Some(command_buffer) = command_queue.commandBuffer() else { return; };
257-
let Some(pass_descriptor) = (unsafe { mtk_view.currentRenderPassDescriptor() }) else { return; };
258-
let Some(encoder) = command_buffer.renderCommandEncoderWithDescriptor(&pass_descriptor) else { return; };
255+
let Some(current_drawable) = current_drawable else {
256+
return;
257+
};
258+
let Some(command_buffer) = command_queue.commandBuffer() else {
259+
return;
260+
};
261+
let Some(pass_descriptor) = (unsafe { mtk_view.currentRenderPassDescriptor() }) else {
262+
return;
263+
};
264+
let Some(encoder) = command_buffer.renderCommandEncoderWithDescriptor(&pass_descriptor)
265+
else {
266+
return;
267+
};
259268

260269
// compute the scene properties
261270
let scene_properties_data = &SceneProperties {

crates/icrate/src/Accessibility/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22
mod generated;
33

44
pub use self::generated::*;
5-
6-
#[link(name = "Accessibility", kind = "framework")]
7-
extern "C" {}

crates/icrate/src/AdServices/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22
mod generated;
33

44
pub use self::generated::*;
5-
6-
#[link(name = "AdServices", kind = "framework")]
7-
extern "C" {}

crates/icrate/src/AdSupport/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22
mod generated;
33

44
pub use self::generated::*;
5-
6-
#[link(name = "AdSupport", kind = "framework")]
7-
extern "C" {}

0 commit comments

Comments
 (0)