Skip to content

Commit

Permalink
Add new use_ios_framework for linking to SDL2.framework on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanvoglsam committed Jun 14, 2024
1 parent 4d5a1d9 commit d5d9ea1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use-bindgen = ["sdl2-sys/use-bindgen"]
use-pkgconfig = ["sdl2-sys/use-pkgconfig"]
use-vcpkg = ["sdl2-sys/use-vcpkg"]
use_mac_framework = ["sdl2-sys/use_mac_framework"]
use_ios_framework = ["sdl2-sys/use_ios_framework"]
bundled = ["sdl2-sys/bundled"]
static-link = ["sdl2-sys/static-link"]

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Rust-SDL2 uses the MIT license, but SDL2 itselfais in under the zlib license.
* `use-pkgconfig` use pkg-config to detect where your library is located on your system. Mostly useful on unix systems for static linking.
* `static-link` to link to SDL2 statically instead of dynamically.
* `use_mac_framework` to use SDL2 from a Framework, on macOS only
* `use_ios_framework` to use SDL2 from a Framework, on iOS only
* `bundled`, which pulls the SDL repository and compiles it from source. More information below.

# Documentation
Expand Down Expand Up @@ -141,6 +142,9 @@ default = []
use_sdl2_mac_framework = ["sdl2/use_mac_framework"]
```

Similarly for iOS you can follow the same process using the `use_ios_framework` feature. However
official builds of the iOS framework are not available so you must compile your own SDL2.framework.

#### Static linking on macOS using vcpkg

Instructions to generate a static binary on macOS and other operating systems using [vcpkg][vcpkg] are [here][cargo-vcpkg-usage].
Expand Down
1 change: 1 addition & 0 deletions sdl2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use-vcpkg = ["vcpkg"]
use-bindgen = ["bindgen"]
static-link = []
use_mac_framework = []
use_ios_framework = []
bundled = ["cmake"]
mixer = []
image = []
Expand Down
44 changes: 39 additions & 5 deletions sdl2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ fn link_sdl2(target_os: &str) {
// pkg-config automatically prints this output when probing,
// however pkg_config isn't used with the feature "bundled"
if cfg!(feature = "bundled") || cfg!(not(feature = "use-pkgconfig")) {
if cfg!(feature = "use_mac_framework") && target_os == "darwin" {
let use_mac_framework = cfg!(feature = "use_mac_framework") && target_os == "darwin";
let use_ios_framework = cfg!(feature = "use_ios_framework") && target_os == "ios";
if use_mac_framework || use_ios_framework {
println!("cargo:rustc-flags=-l framework=SDL2");
} else if target_os != "emscripten" {
println!("cargo:rustc-flags=-l SDL2");
Expand Down Expand Up @@ -328,7 +330,15 @@ fn link_sdl2(target_os: &str) {
} else if target_os.contains("windows") {
println!("cargo:rustc-flags=-l SDL2_mixer");
} else if target_os.contains("darwin") {
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_mixer");
} else {
println!("cargo:rustc-flags=-l SDL2_mixer");
}
} else if target_os.contains("ios") {
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_mixer");
} else {
println!("cargo:rustc-flags=-l SDL2_mixer");
Expand All @@ -344,7 +354,15 @@ fn link_sdl2(target_os: &str) {
} else if target_os.contains("windows") {
println!("cargo:rustc-flags=-l SDL2_image");
} else if target_os.contains("darwin") {
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_image");
} else {
println!("cargo:rustc-flags=-l SDL2_image");
}
} else if target_os.contains("ios") {
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_image");
} else {
println!("cargo:rustc-flags=-l SDL2_image");
Expand All @@ -360,7 +378,15 @@ fn link_sdl2(target_os: &str) {
} else if target_os.contains("windows") {
println!("cargo:rustc-flags=-l SDL2_ttf");
} else if target_os.contains("darwin") {
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_ttf");
} else {
println!("cargo:rustc-flags=-l SDL2_ttf");
}
} else if target_os.contains("ios") {
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_ttf");
} else {
println!("cargo:rustc-flags=-l SDL2_ttf");
Expand All @@ -376,7 +402,15 @@ fn link_sdl2(target_os: &str) {
} else if target_os.contains("windows") {
println!("cargo:rustc-flags=-l SDL2_gfx");
} else if target_os.contains("darwin") {
if cfg!(any(mac_framework, feature = "use_mac_framework")) {
let use_framework = cfg!(any(mac_framework, feature = "use_mac_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_gfx");
} else {
println!("cargo:rustc-flags=-l SDL2_gfx");
}
} else if target_os.contains("ios") {
let use_framework = cfg!(any(ios_framework, feature = "use_ios_framework"));
if use_framework {
println!("cargo:rustc-flags=-l framework=SDL2_gfx");
} else {
println!("cargo:rustc-flags=-l SDL2_gfx");
Expand Down

0 comments on commit d5d9ea1

Please sign in to comment.