Skip to content

Commit 0b740d9

Browse files
authored
Merge pull request #1407 from nathanvoglsam/use_ios_framework
Add new use_ios_framework for linking to SDL2.framework on iOS
2 parents 380c6f1 + 2a9eb7d commit 0b740d9

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use-bindgen = ["sdl2-sys/use-bindgen"]
5353
use-pkgconfig = ["sdl2-sys/use-pkgconfig"]
5454
use-vcpkg = ["sdl2-sys/use-vcpkg"]
5555
use_mac_framework = ["sdl2-sys/use_mac_framework"]
56+
use_ios_framework = ["sdl2-sys/use_ios_framework"]
5657
bundled = ["sdl2-sys/bundled"]
5758
static-link = ["sdl2-sys/static-link"]
5859

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Rust-SDL2 uses the MIT license, but SDL2 itselfais in under the zlib license.
2525
* `use-pkgconfig` use pkg-config to detect where your library is located on your system. Mostly useful on unix systems for static linking.
2626
* `static-link` to link to SDL2 statically instead of dynamically.
2727
* `use_mac_framework` to use SDL2 from a Framework, on macOS only
28+
* `use_ios_framework` to use SDL2 from a Framework, on iOS only
2829
* `bundled`, which pulls the SDL repository and compiles it from source. More information below.
2930

3031
# Documentation
@@ -142,6 +143,18 @@ default = []
142143
use_sdl2_mac_framework = ["sdl2/use_mac_framework"]
143144
```
144145

146+
Similarly for iOS you can follow the same process using the `use_ios_framework` feature. However
147+
official builds of the iOS framework are not available so you must compile your own SDL2.framework.
148+
149+
Using the iOS framework also requires adding the 'Frameworks' directory to your rpath so that the
150+
dynamic linker can find SDL2.framework inside your app bundle. This is done by adding this to your
151+
`build.rs`:
152+
153+
```rust
154+
#[cfg(target_os="ios")]
155+
println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/Frameworks");
156+
```
157+
145158
#### Static linking on macOS using vcpkg
146159

147160
Instructions to generate a static binary on macOS and other operating systems using [vcpkg][vcpkg] are [here][cargo-vcpkg-usage].

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
In this file will be listed the changes, especially the breaking ones that one should be careful of
22
when upgrading from a version of rust-sdl2 to another.
33

4+
### Next
5+
6+
[PR #1407](https://github.com/Rust-SDL2/rust-sdl2/pull/1407) Add new use_ios_framework for linking to SDL2.framework on iOS
7+
48
### v0.37.0
59

610
[PR #1406](https://github.com/Rust-SDL2/rust-sdl2/pull/1406) Update bindings to SDL 2.0.26, add Event.is\_touch() for mouse events, upgrade wgpu to 0.20 in examples

sdl2-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use-vcpkg = ["vcpkg"]
5151
use-bindgen = ["bindgen"]
5252
static-link = []
5353
use_mac_framework = []
54+
use_ios_framework = []
5455
bundled = ["cmake"]
5556
mixer = []
5657
image = []

sdl2-sys/build.rs

+39-5
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ fn link_sdl2(target_os: &str) {
232232
// pkg-config automatically prints this output when probing,
233233
// however pkg_config isn't used with the feature "bundled"
234234
if cfg!(feature = "bundled") || cfg!(not(feature = "use-pkgconfig")) {
235-
if cfg!(feature = "use_mac_framework") && target_os == "darwin" {
235+
let use_mac_framework = cfg!(feature = "use_mac_framework") && target_os == "darwin";
236+
let use_ios_framework = cfg!(feature = "use_ios_framework") && target_os == "ios";
237+
if use_mac_framework || use_ios_framework {
236238
println!("cargo:rustc-flags=-l framework=SDL2");
237239
} else if target_os != "emscripten" {
238240
println!("cargo:rustc-flags=-l SDL2");
@@ -328,7 +330,15 @@ fn link_sdl2(target_os: &str) {
328330
} else if target_os.contains("windows") {
329331
println!("cargo:rustc-flags=-l SDL2_mixer");
330332
} else if target_os.contains("darwin") {
331-
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
333+
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
334+
if use_framework {
335+
println!("cargo:rustc-flags=-l framework=SDL2_mixer");
336+
} else {
337+
println!("cargo:rustc-flags=-l SDL2_mixer");
338+
}
339+
} else if target_os.contains("ios") {
340+
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
341+
if use_framework {
332342
println!("cargo:rustc-flags=-l framework=SDL2_mixer");
333343
} else {
334344
println!("cargo:rustc-flags=-l SDL2_mixer");
@@ -344,7 +354,15 @@ fn link_sdl2(target_os: &str) {
344354
} else if target_os.contains("windows") {
345355
println!("cargo:rustc-flags=-l SDL2_image");
346356
} else if target_os.contains("darwin") {
347-
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
357+
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
358+
if use_framework {
359+
println!("cargo:rustc-flags=-l framework=SDL2_image");
360+
} else {
361+
println!("cargo:rustc-flags=-l SDL2_image");
362+
}
363+
} else if target_os.contains("ios") {
364+
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
365+
if use_framework {
348366
println!("cargo:rustc-flags=-l framework=SDL2_image");
349367
} else {
350368
println!("cargo:rustc-flags=-l SDL2_image");
@@ -360,7 +378,15 @@ fn link_sdl2(target_os: &str) {
360378
} else if target_os.contains("windows") {
361379
println!("cargo:rustc-flags=-l SDL2_ttf");
362380
} else if target_os.contains("darwin") {
363-
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
381+
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
382+
if use_framework {
383+
println!("cargo:rustc-flags=-l framework=SDL2_ttf");
384+
} else {
385+
println!("cargo:rustc-flags=-l SDL2_ttf");
386+
}
387+
} else if target_os.contains("ios") {
388+
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
389+
if use_framework {
364390
println!("cargo:rustc-flags=-l framework=SDL2_ttf");
365391
} else {
366392
println!("cargo:rustc-flags=-l SDL2_ttf");
@@ -376,7 +402,15 @@ fn link_sdl2(target_os: &str) {
376402
} else if target_os.contains("windows") {
377403
println!("cargo:rustc-flags=-l SDL2_gfx");
378404
} else if target_os.contains("darwin") {
379-
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
405+
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
406+
if use_framework {
407+
println!("cargo:rustc-flags=-l framework=SDL2_gfx");
408+
} else {
409+
println!("cargo:rustc-flags=-l SDL2_gfx");
410+
}
411+
} else if target_os.contains("ios") {
412+
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
413+
if use_framework {
380414
println!("cargo:rustc-flags=-l framework=SDL2_gfx");
381415
} else {
382416
println!("cargo:rustc-flags=-l SDL2_gfx");

0 commit comments

Comments
 (0)