Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new use_ios_framework for linking to SDL2.framework on iOS #1407

Merged
merged 2 commits into from
Jun 15, 2024

Conversation

nathanvoglsam
Copy link
Contributor

Currently the crate has a 'use_mac_framework' for linking to SDL2 using the .framework instead of linking directly to the static/dynamic libraries. This PR adds a new feature flag for doing the same, but for iOS.

AFAIK there are no official iOS builds for SDL2, but you can quite easily build your own SDL2.framework using the Xcode project. I'd like to be able to link iOS builds of my project using SDL2.framework but there's currently no way to either skip linking SDL2 inside the existing build script (and do it in my own build script) or to instruct the existing build script to link to a framework on iOS.

This PR remedies this by just making a duplicate of 'use_mac_framework' called 'use_ios_framework' which behaves much the same way, changing link type to 'framework' on iOS when the feature is enabled.

What do you think?

@Cobrand
Copy link
Member

Cobrand commented Jun 14, 2024

Looks good to me, have you tested it yourself to see that it worked on iOS?

@nathanvoglsam
Copy link
Contributor Author

nathanvoglsam commented Jun 14, 2024

I'm currently toying around with bring-up of my project on iOS. It does build but I'm still running through the steps of standing up an Xcode project to bundle the executable into an app.

Building my project with cargo build --target=aarch64-apple-ios --package aleph-test --bin aleph-test does work but I haven't gotten to the part where I can run it on a device yet.

@Cobrand
Copy link
Member

Cobrand commented Jun 14, 2024

Alright, please ring me up when you manage to make it work. We never know, there might be specific flags for framework that are needed in rust-sdl2, I'd prefer if we did that in one PR only.

@nathanvoglsam
Copy link
Contributor Author

Good news! It does work. Compiles, links and runs when testing on my iPad. There was one hiccup though. I had to add this println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/Frameworks") to my build.rs for the app executable to add the Frameworks directory to the rpath. Otherwise the linker couldn't find the SDL2.framework once bundled into the app.

Would have a nice photo or something of it running but MoltenVK is not being my friend. Log output would have to do:
Screenshot 2024-06-14 at 11 49 13 PM

@Cobrand
Copy link
Member

Cobrand commented Jun 14, 2024

Would you mind adding that part to the readme? I'm sure it will help some people.

@Cobrand
Copy link
Member

Cobrand commented Jun 14, 2024

And the changelog as well.

@nathanvoglsam
Copy link
Contributor Author

Just pushed an updated readme and changelog. Let me know if the changelog format is good.

@nathanvoglsam
Copy link
Contributor Author

And after a bit of poking at MoltenVK (the key was VK_EXT_metal_surface) it boots all the way to rendering 🎉
IMG_20240615_145300499

@Cobrand
Copy link
Member

Cobrand commented Jun 15, 2024

Nice job!

@Cobrand Cobrand merged commit 0b740d9 into Rust-SDL2:master Jun 15, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants