RustAudio / coreaudio-sys

Raw bindings to the OSX CoreAudio framework generated by bindgen (see coreaudio-rs for a more rust-esque wrapper).
MIT License
69 stars 38 forks source link

feat(apple): added visionOS support #102

Open eugenehp opened 5 months ago

eugenehp commented 5 months ago

Adds visionOS support

Similar issues with the CI:

Important note:

For rust target aarch64-apple-visionos it is important to use arm64-apple-xros target for clang. https://github.com/eugenehp/coreaudio-sys/blob/visionos/build.rs#L140-L141

eugenehp commented 5 months ago

Appreciate the feedback @simlay, I'll have coreaudio-rs and cpal PRs done once this PR is all sound and good. Committed few quick changes. Still working on the CI build pass for visionos.

While I have you, I'm thinking on rewriting example-ios, or rather written example-visionos and get rid of cargo-lipo. What would be preferred way to go about it?

eugenehp commented 5 months ago

In case you have a second: https://github.com/eugenehp/coreaudio-sys/actions/runs/9405587039/job/25907098630

--- stderr
  /Users/runner/work/coreaudio-sys/coreaudio-sys/coreaudio.h:4:10: fatal error: 'AudioUnit/AudioUnit.h' file not found
  thread 'main' panicked at build.rs:198:39:
  unable to generate bindings: ClangDiagnostic("/Users/runner/work/coreaudio-sys/coreaudio-sys/coreaudio.h:4:10: fatal error: 'AudioUnit/AudioUnit.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

and local one builds perfectly:

Screenshot 2024-06-06 at 2 18 06 PM
simlay commented 5 months ago

I'll have coreaudio-rs and cpal PRs done once this PR is all sound and good.

Use of the patch.crates-io feature can help with this. I've been using it to get my visionOS/tvOS/watchOS builds working

While I have you, I'm thinking on rewriting example-ios, or rather written example-visionos and get rid of cargo-lipo. What would be preferred way to go about it?

I actually don't know if that xcode example still works when ran. I know it's built in CI but audio examples are tough in CI.

Do you have a good technique for testing that your rust works in a visionOS simulator? For some stuff I use cargo-dinghy, https://github.com/sonos/dinghy/pull/223 adds support for the visionOS sim but I've not tried it with audio in the visionOS sim. The ios-example in coreaudio-rs looks to be a feedback example which means it'll need access to the microphone (needs a info.plist key that's cargo-dinghy doesn't add).

eugenehp commented 5 months ago

I'll have coreaudio-rs and cpal PRs done once this PR is all sound and good.

Use of the patch.crates-io feature can help with this. I've been using it to get my visionOS/tvOS/watchOS builds working

that's the plan. already submitted PRs on a bunch of other repos too. Spent some quality time with the Xcode runner too. 🤣

While I have you, I'm thinking on rewriting example-ios, or rather written example-visionos and get rid of cargo-lipo. What would be preferred way to go about it?

I actually don't know if that xcode example still works when ran. I know it's built in CI but audio examples are tough in CI.

Tested it on arm64-apple-darwin and arm64-apple-ios it works. But cargo-lipo is in the maintenance mode. And keeping universal libraries just for x86_64 is extra work, while most folks move away from it. Hence the idea to rewrite it for visionos and see how it goes.

Do you have a good technique for testing that your rust works in a visionOS simulator? For some stuff I use cargo-dinghy, sonos/dinghy#223 adds support for the visionOS sim but I've not tried it with audio in the visionOS sim. The ios-example in coreaudio-rs looks to be a feedback example which means it'll need access to the microphone (needs a info.plist key that's cargo-dinghy doesn't add).

I wish. It's Apple. Testing on simulator and real device. There was a hack to test some iOS features in native macOS mode in Xcode. But it doesn't fly with visionos.

simlay commented 5 months ago

I wish. It's Apple. Testing on simulator and real device. There was a hack to test some iOS features in native macOS mode in Xcode. But it doesn't fly with visionos.

Yeah... to do it on device with dinghy, you create an app with a specific name (Dinghy) and load it onto your phone once and then it does some hacky crap where it signs and loads it on.

xcrun devicectl is slowly getting things nicer but you still need to sign an app bundle. Various rust folks have looked into this like apple-codesign.

eugenehp commented 5 months ago

Yeah, it's imperfect. There was ios-deploy but it doesn't work well with visionos and doesn't let us debug it. We've been doing a lot of Tauri in production, and they build system cargo-mobile2 works for us.

https://github.com/tauri-apps/cargo-mobile2/pull/340

eugenehp commented 5 months ago

Okay, CI looks good. stable and nightly. Going to work on coreaudio-rs PR next. To make sure this one works. @simlay

simlay commented 5 months ago

@eugenehp I hope you're not offended by me authoring #103. There was a reddit thread today about someone not giving credit on PRs. I've since amended the commit in #103 and have you as a co-author as you went through rough parts on this PR. There were some refactors I felt were needed as iOS support was added 4 years ago.

eugenehp commented 5 months ago

@simlay I'd love to cherry pick this PR, but I don't think I have time to go and do proper testing for tvOS and watchOS together. Hence why the focus is on visionos for now. If you're okay to do this PR first, and then rollover with your refactored version (given you spend time testing tvOS and watchOS more), then this should be stable enough.

Also released couple helper libraries today, feel free to give your feedback on what could be improved: