Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions .github/workflows/coreaudio-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,29 @@ jobs:
with:
toolchain: stable
- name: Add iOS targets
run: rustup target add aarch64-apple-ios x86_64-apple-ios
- name: Install cargo lipo
run: cargo install cargo-lipo
run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim
- name: Build iphonesimulator feedback example
run: cd examples/ios && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=x86_64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator
run: cd examples/apple && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator

tvos-build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rust-src
- name: Build for tvOS simulator
run: cd examples/apple && cargo +nightly build -Zbuild-std --target aarch64-apple-tvos-sim --release
- name: Build for tvOS device
run: cd examples/apple && cargo +nightly build -Zbuild-std --target aarch64-apple-tvos --release
Comment on lines +73 to +76
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are duplicated in the buildscript that's called from the xcodebuild call. Granted, they do check different things. It's not a big deal.

- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Add iOS targets
run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim
- name: Build appletvsimulator example
run: cd examples/apple && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-tvos-example -configuration Debug -derivedDataPath build -sdk appletvsimulator

# Build the docs with all features to make sure docs.rs will work.
macos-docs:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ target/
.cargo/
.DS_Store
llvm/

# Xcode build artifacts
examples/*/build/
examples/*/Cargo.lock
4 changes: 2 additions & 2 deletions examples/ios/Cargo.toml → examples/apple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "coreaudio-ios-example"
name = "coreaudio-apple-example"
version = "0.1.0"
authors = ["Michael Hills <mhills@gmail.com>"]
edition = "2018"

[lib]
name = "coreaudio_ios_example"
name = "coreaudio_apple_example"
crate-type = ["staticlib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//
// AppDelegate.m
// coreaudio-ios-example
// coreaudio-apple-example
//
// Created by Michael Hills on 2/10/20.
//

#import "AppDelegate.h"
#if TARGET_OS_TV
#import "ViewController.h"
#endif
@import AVFoundation;

void rust_ios_main(void);
void rust_apple_main(void);


@interface AppDelegate ()
Expand All @@ -21,27 +24,40 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.


#if TARGET_OS_TV
// tvOS requires programmatic window creation (no storyboards)
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
#endif

NSError *error;
BOOL success;

// It is necessary to access the sharedInstance so that calls to AudioSessionGetProperty
// will work.
AVAudioSession *session = AVAudioSession.sharedInstance;
// Setting up the category is not necessary, but generally advised.

#if TARGET_OS_TV
// tvOS only supports Playback category (no microphone input, no DefaultToSpeaker)
success = [session setCategory:AVAudioSessionCategoryPlayback error:&error];
#else
// iOS: Setting up the category is not necessary, but generally advised.
// Since this demo records and plays, lets use AVAudioSessionCategoryPlayAndRecord.
// Also default to speaker as defaulting to the phone earpiece would be unusual.
success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
error:&error];
#endif

if (success) {
NSLog(@"Calling rust_ios_main()");
rust_ios_main();
NSLog(@"Calling rust_apple_main()");
rust_apple_main();
} else {
NSLog(@"Failed to configure audio session category");
NSLog(@"Failed to configure audio session category: %@", error);
}

return YES;
}

Expand Down
24 changes: 24 additions & 0 deletions examples/apple/apple-src/Info-tvOS.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
File renamed without changes.
30 changes: 30 additions & 0 deletions examples/apple/build_rust_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e

PATH=$PATH:$HOME/.cargo/bin

if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then
# Assume we're in Xcode, which means we're probably cross-compiling.
# In this case, we need to add an extra library search path for build scripts and proc-macros,
# which run on the host instead of the target.
# (macOS Big Sur does not have linkable libraries in /usr/lib/.)
export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}"
fi

# Detect which platform we're building for based on SDKROOT
# SDKROOT is set by Xcode and contains the SDK path (e.g., iphoneos, iphonesimulator, appletvos, appletvsimulator)
case "${SDKROOT:-}" in
*appletvos*|*appletvsimulator*)
# Build for tvOS (requires nightly toolchain and -Zbuild-std since tvOS is a Tier 3 target)
cargo +nightly build -Zbuild-std --target aarch64-apple-tvos-sim --release
cargo +nightly build -Zbuild-std --target aarch64-apple-tvos --release
;;
*)
# Default: Build for iOS (stable toolchain)
# Device (arm64)
cargo build --target aarch64-apple-ios --release
# Simulator (arm64)
cargo build --target aarch64-apple-ios-sim --release
;;
esac
Loading
Loading