Skip to content

Commit d0545fc

Browse files
authored
Add tvOS support with consolidated Apple examples (#146)
Add tvOS as a supported platform alongside iOS. Both platforms now share a single example in examples/apple/ with one Xcode project containing targets for both iOS and tvOS. Changes: - Add tvOS target support (aarch64-apple-tvos, aarch64-apple-tvos-sim) - Consolidate examples/ios and examples/tvos into examples/apple - Single Xcode project with iOS and tvOS targets sharing source files - Unified sine wave demo (440Hz) for both platforms - Platform-specific code via #[cfg(target_os)] in Rust and #if TARGET_OS_TV in Objective-C - SDK-conditional library search paths in Xcode project - Build script detects SDKROOT to build only relevant targets - Update CI workflow for both platforms tvOS is a Tier 3 target requiring nightly toolchain with -Zbuild-std.
1 parent 90d49fc commit d0545fc

25 files changed

Lines changed: 532 additions & 238 deletions

.github/workflows/coreaudio-rs.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,29 @@ jobs:
5858
with:
5959
toolchain: stable
6060
- name: Add iOS targets
61-
run: rustup target add aarch64-apple-ios x86_64-apple-ios
62-
- name: Install cargo lipo
63-
run: cargo install cargo-lipo
61+
run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim
6462
- name: Build iphonesimulator feedback example
65-
run: cd examples/ios && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=x86_64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator
63+
run: cd examples/apple && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator
64+
65+
tvos-build:
66+
runs-on: macOS-latest
67+
steps:
68+
- uses: actions/checkout@v6
69+
- uses: dtolnay/rust-toolchain@master
70+
with:
71+
toolchain: nightly
72+
components: rust-src
73+
- name: Build for tvOS simulator
74+
run: cd examples/apple && cargo +nightly build -Zbuild-std --target aarch64-apple-tvos-sim --release
75+
- name: Build for tvOS device
76+
run: cd examples/apple && cargo +nightly build -Zbuild-std --target aarch64-apple-tvos --release
77+
- uses: dtolnay/rust-toolchain@master
78+
with:
79+
toolchain: stable
80+
- name: Add iOS targets
81+
run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim
82+
- name: Build appletvsimulator example
83+
run: cd examples/apple && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-tvos-example -configuration Debug -derivedDataPath build -sdk appletvsimulator
6684

6785
# Build the docs with all features to make sure docs.rs will work.
6886
macos-docs:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ target/
33
.cargo/
44
.DS_Store
55
llvm/
6+
7+
# Xcode build artifacts
8+
examples/*/build/
9+
examples/*/Cargo.lock
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
2-
name = "coreaudio-ios-example"
2+
name = "coreaudio-apple-example"
33
version = "0.1.0"
44
authors = ["Michael Hills <mhills@gmail.com>"]
55
edition = "2018"
66

77
[lib]
8-
name = "coreaudio_ios_example"
8+
name = "coreaudio_apple_example"
99
crate-type = ["staticlib"]
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
//
22
// AppDelegate.m
3-
// coreaudio-ios-example
3+
// coreaudio-apple-example
44
//
55
// Created by Michael Hills on 2/10/20.
66
//
77

88
#import "AppDelegate.h"
9+
#if TARGET_OS_TV
10+
#import "ViewController.h"
11+
#endif
912
@import AVFoundation;
1013

11-
void rust_ios_main(void);
14+
void rust_apple_main(void);
1215

1316

1417
@interface AppDelegate ()
@@ -21,27 +24,40 @@ @implementation AppDelegate
2124

2225
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2326
// Override point for customization after application launch.
24-
27+
28+
#if TARGET_OS_TV
29+
// tvOS requires programmatic window creation (no storyboards)
30+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
31+
self.window.rootViewController = [[ViewController alloc] init];
32+
[self.window makeKeyAndVisible];
33+
#endif
34+
2535
NSError *error;
2636
BOOL success;
27-
37+
2838
// It is necessary to access the sharedInstance so that calls to AudioSessionGetProperty
2939
// will work.
3040
AVAudioSession *session = AVAudioSession.sharedInstance;
31-
// Setting up the category is not necessary, but generally advised.
41+
42+
#if TARGET_OS_TV
43+
// tvOS only supports Playback category (no microphone input, no DefaultToSpeaker)
44+
success = [session setCategory:AVAudioSessionCategoryPlayback error:&error];
45+
#else
46+
// iOS: Setting up the category is not necessary, but generally advised.
3247
// Since this demo records and plays, lets use AVAudioSessionCategoryPlayAndRecord.
3348
// Also default to speaker as defaulting to the phone earpiece would be unusual.
3449
success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
3550
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
3651
error:&error];
52+
#endif
3753

3854
if (success) {
39-
NSLog(@"Calling rust_ios_main()");
40-
rust_ios_main();
55+
NSLog(@"Calling rust_apple_main()");
56+
rust_apple_main();
4157
} else {
42-
NSLog(@"Failed to configure audio session category");
58+
NSLog(@"Failed to configure audio session category: %@", error);
4359
}
44-
60+
4561
return YES;
4662
}
4763

examples/ios/ios-src/Base.lproj/LaunchScreen.storyboard renamed to examples/apple/apple-src/Base.lproj/LaunchScreen.storyboard

File renamed without changes.
File renamed without changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
<key>UIApplicationSupportsIndirectInputEvents</key>
22+
<true/>
23+
</dict>
24+
</plist>

0 commit comments

Comments
 (0)