diff --git a/.github/workflows/coreaudio-rs.yml b/.github/workflows/coreaudio-rs.yml index 15224a42e..766ca0521 100644 --- a/.github/workflows/coreaudio-rs.yml +++ b/.github/workflows/coreaudio-rs.yml @@ -50,37 +50,34 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} - ios-build: + xcode-builds: runs-on: macOS-latest steps: - uses: actions/checkout@v6 - 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 iphonesimulator feedback example - run: cd examples/apple && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator + toolchain: nightly + components: rust-src + targets: "aarch64-apple-ios,aarch64-apple-ios-sim" + - run: xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-tvos-example -configuration Debug -derivedDataPath build -sdk appletvsimulator + working-directory: examples/apple + - run: xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator + working-directory: examples/apple + - run: xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-visionos-example -configuration Debug -derivedDataPath build -sdk xrsimulator + working-directory: examples/apple - tvos-build: + check-examples: runs-on: macOS-latest + strategy: + matrix: + rust-target: [aarch64-apple-ios-sim, aarch64-apple-tvos-sim, aarch64-apple-visionos-sim] 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 - - 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 + - run: cargo +nightly build -Zbuild-std --all --target ${{ matrix.rust-target }} # Build the docs with all features to make sure docs.rs will work. macos-docs: diff --git a/Cargo.toml b/Cargo.toml index dbe20208d..0dc111f24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,10 +32,11 @@ audio_unit = ["audio_toolbox"] # Unsupported open_al = [] +[target.'cfg(target_os = "macos")'.dependencies] +libc = "0.2" [dependencies] bitflags = "2.10" -libc = "0.2" objc2-core-foundation = { version = "0.3", optional = true, default-features = false, features = [ "std", "CFString", @@ -67,6 +68,9 @@ objc2-core-audio-types = { version = "0.3", optional = true, default-features = "bitflags", "CoreAudioBaseTypes", ] } +[dev-dependencies] +[target.'cfg(any(target_os = "ios", target_os = "tvos", target_os = "visionos"))'.dev-dependencies] +objc2-avf-audio = "0.3.2" [package.metadata.docs.rs] all-features = true diff --git a/examples/apple/build_rust_deps.sh b/examples/apple/build_rust_deps.sh index 8114d3b88..30c6675aa 100755 --- a/examples/apple/build_rust_deps.sh +++ b/examples/apple/build_rust_deps.sh @@ -12,19 +12,11 @@ if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then 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 +cargo build -Zbuild-std \ + --target aarch64-apple-tvos-sim \ + --target aarch64-apple-tvos \ + --target aarch64-apple-visionos \ + --target aarch64-apple-visionos-sim \ + --release + +cargo build --target aarch64-apple-ios --target aarch64-apple-ios-sim --release diff --git a/examples/apple/coreaudio-ios-example.xcodeproj/project.pbxproj b/examples/apple/coreaudio-example.xcodeproj/project.pbxproj similarity index 71% rename from examples/apple/coreaudio-ios-example.xcodeproj/project.pbxproj rename to examples/apple/coreaudio-example.xcodeproj/project.pbxproj index 7b5bcaaff..3dd5032e8 100644 --- a/examples/apple/coreaudio-ios-example.xcodeproj/project.pbxproj +++ b/examples/apple/coreaudio-example.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -13,7 +13,12 @@ 57AB5B09252769700040DE8C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 57AB5B01252769700040DE8C /* Main.storyboard */; }; 57AB5B0A252769700040DE8C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5B03252769700040DE8C /* main.m */; }; 57AB5B0B252769700040DE8C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5B04252769700040DE8C /* AppDelegate.m */; }; - /* tvOS target build files */ + 968772A32EF5C86300CBB8F2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5B03252769700040DE8C /* main.m */; }; + 968772A42EF5C86300CBB8F2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5B04252769700040DE8C /* AppDelegate.m */; }; + 968772A52EF5C86300CBB8F2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5AFE252769700040DE8C /* ViewController.m */; }; + 968772A72EF5C86300CBB8F2 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57AB5AF2252767460040DE8C /* AVFoundation.framework */; }; + 968772A92EF5C86300CBB8F2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 57AB5B01252769700040DE8C /* Main.storyboard */; }; + 968772AA2EF5C86300CBB8F2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 57AB5AFF252769700040DE8C /* LaunchScreen.storyboard */; }; TVOS0001252767460040DE8C /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57AB5AF2252767460040DE8C /* AVFoundation.framework */; }; TVOS0002252769700040DE8C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5AFE252769700040DE8C /* ViewController.m */; }; TVOS0003252769700040DE8C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5B03252769700040DE8C /* main.m */; }; @@ -21,14 +26,21 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 57AB5AEE252766820040DE8C /* PBXContainerItemProxy */ = { + 968772B02EF5CD8600CBB8F2 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 57AB5AC2252762C00040DE8C /* Project object */; proxyType = 1; remoteGlobalIDString = 57AB5AE9252766240040DE8C; remoteInfo = cargo_apple; }; - TVOS0010252766820040DE8C /* PBXContainerItemProxy */ = { + 968772B32EF5CECD00CBB8F2 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 57AB5AC2252762C00040DE8C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 57AB5AE9252766240040DE8C; + remoteInfo = cargo_apple; + }; + 968772B62EF5D15600CBB8F2 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 57AB5AC2252762C00040DE8C /* Project object */; proxyType = 1; @@ -39,7 +51,6 @@ /* Begin PBXFileReference section */ 57AB5ACA252762C10040DE8C /* coreaudio-ios-example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "coreaudio-ios-example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; - TVOS0020252762C10040DE8C /* coreaudio-tvos-example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "coreaudio-tvos-example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 57AB5AF2252767460040DE8C /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 57AB5AFD252769700040DE8C /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 57AB5AFE252769700040DE8C /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; @@ -48,8 +59,11 @@ 57AB5B03252769700040DE8C /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 57AB5B04252769700040DE8C /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 57AB5B05252769700040DE8C /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; - TVOS0030252769700040DE8C /* Info-tvOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; 57AB5B06252769700040DE8C /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 968772AE2EF5C86300CBB8F2 /* coreaudio-visionos-example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "coreaudio-visionos-example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 968772AF2EF5C86300CBB8F2 /* coreaudio-ios-example copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "coreaudio-ios-example copy-Info.plist"; path = "/Users/simlay/projects/rust-audio/coreaudio-rs/examples/apple/coreaudio-ios-example copy-Info.plist"; sourceTree = ""; }; + TVOS0020252762C10040DE8C /* coreaudio-tvos-example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "coreaudio-tvos-example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + TVOS0030252769700040DE8C /* Info-tvOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -61,6 +75,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 968772A62EF5C86300CBB8F2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 968772A72EF5C86300CBB8F2 /* AVFoundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; TVOS0040252762C10040DE8C /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -78,6 +100,7 @@ 57AB5AFC252769700040DE8C /* apple-src */, 57AB5ACB252762C10040DE8C /* Products */, 57AB5AF1252767460040DE8C /* Frameworks */, + 968772AF2EF5C86300CBB8F2 /* coreaudio-ios-example copy-Info.plist */, ); sourceTree = ""; }; @@ -86,6 +109,7 @@ children = ( 57AB5ACA252762C10040DE8C /* coreaudio-ios-example.app */, TVOS0020252762C10040DE8C /* coreaudio-tvos-example.app */, + 968772AE2EF5C86300CBB8F2 /* coreaudio-visionos-example.app */, ); name = Products; sourceTree = ""; @@ -145,13 +169,31 @@ buildRules = ( ); dependencies = ( - 57AB5AEF252766820040DE8C /* PBXTargetDependency */, + 968772B72EF5D15600CBB8F2 /* PBXTargetDependency */, ); name = "coreaudio-ios-example"; productName = "coreaudio-ios-example"; productReference = 57AB5ACA252762C10040DE8C /* coreaudio-ios-example.app */; productType = "com.apple.product-type.application"; }; + 9687729F2EF5C86300CBB8F2 /* coreaudio-visionos-example */ = { + isa = PBXNativeTarget; + buildConfigurationList = 968772AB2EF5C86300CBB8F2 /* Build configuration list for PBXNativeTarget "coreaudio-visionos-example" */; + buildPhases = ( + 968772A22EF5C86300CBB8F2 /* Sources */, + 968772A62EF5C86300CBB8F2 /* Frameworks */, + 968772A82EF5C86300CBB8F2 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 968772B42EF5CECD00CBB8F2 /* PBXTargetDependency */, + ); + name = "coreaudio-visionos-example"; + productName = "coreaudio-ios-example"; + productReference = 968772AE2EF5C86300CBB8F2 /* coreaudio-visionos-example.app */; + productType = "com.apple.product-type.application"; + }; TVOS0050252762C10040DE8C /* coreaudio-tvos-example */ = { isa = PBXNativeTarget; buildConfigurationList = TVOS0060252762C30040DE8C /* Build configuration list for PBXNativeTarget "coreaudio-tvos-example" */; @@ -163,7 +205,7 @@ buildRules = ( ); dependencies = ( - TVOS0011252766820040DE8C /* PBXTargetDependency */, + 968772B12EF5CD8600CBB8F2 /* PBXTargetDependency */, ); name = "coreaudio-tvos-example"; productName = "coreaudio-tvos-example"; @@ -181,15 +223,15 @@ 57AB5AC9252762C10040DE8C = { CreatedOnToolsVersion = 12.0.1; }; - TVOS0050252762C10040DE8C = { + 57AB5AE9252766240040DE8C = { CreatedOnToolsVersion = 12.0.1; }; - 57AB5AE9252766240040DE8C = { + TVOS0050252762C10040DE8C = { CreatedOnToolsVersion = 12.0.1; }; }; }; - buildConfigurationList = 57AB5AC5252762C00040DE8C /* Build configuration list for PBXProject "coreaudio-ios-example" */; + buildConfigurationList = 57AB5AC5252762C00040DE8C /* Build configuration list for PBXProject "coreaudio-example" */; compatibilityVersion = "Xcode 9.3"; developmentRegion = en; hasScannedForEncodings = 0; @@ -205,6 +247,7 @@ 57AB5AC9252762C10040DE8C /* coreaudio-ios-example */, TVOS0050252762C10040DE8C /* coreaudio-tvos-example */, 57AB5AE9252766240040DE8C /* cargo_apple */, + 9687729F2EF5C86300CBB8F2 /* coreaudio-visionos-example */, ); }; /* End PBXProject section */ @@ -219,6 +262,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 968772A82EF5C86300CBB8F2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 968772A92EF5C86300CBB8F2 /* Main.storyboard in Resources */, + 968772AA2EF5C86300CBB8F2 /* LaunchScreen.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; TVOS0080252762C10040DE8C /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -239,6 +291,16 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 968772A22EF5C86300CBB8F2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 968772A32EF5C86300CBB8F2 /* main.m in Sources */, + 968772A42EF5C86300CBB8F2 /* AppDelegate.m in Sources */, + 968772A52EF5C86300CBB8F2 /* ViewController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; TVOS0070252762C10040DE8C /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -252,15 +314,21 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 57AB5AEF252766820040DE8C /* PBXTargetDependency */ = { + 968772B12EF5CD8600CBB8F2 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 57AB5AE9252766240040DE8C /* cargo_apple */; + targetProxy = 968772B02EF5CD8600CBB8F2 /* PBXContainerItemProxy */; + }; + 968772B42EF5CECD00CBB8F2 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 57AB5AE9252766240040DE8C /* cargo_apple */; - targetProxy = 57AB5AEE252766820040DE8C /* PBXContainerItemProxy */; + targetProxy = 968772B32EF5CECD00CBB8F2 /* PBXContainerItemProxy */; }; - TVOS0011252766820040DE8C /* PBXTargetDependency */ = { + 968772B72EF5D15600CBB8F2 /* PBXTargetDependency */ = { isa = PBXTargetDependency; + platformFilter = ios; target = 57AB5AE9252766240040DE8C /* cargo_apple */; - targetProxy = TVOS0010252766820040DE8C /* PBXContainerItemProxy */; + targetProxy = 968772B62EF5D15600CBB8F2 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -340,6 +408,8 @@ MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + TVOS_DEPLOYMENT_TARGET = 15.6; + XROS_DEPLOYMENT_TARGET = 1.3; }; name = Debug; }; @@ -392,7 +462,9 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; + TVOS_DEPLOYMENT_TARGET = 15.6; VALIDATE_PRODUCT = YES; + XROS_DEPLOYMENT_TARGET = 1.3; }; name = Release; }; @@ -409,10 +481,16 @@ ); "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = "$(SRCROOT)/target/aarch64-apple-ios/release"; "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(SRCROOT)/target/aarch64-apple-ios-sim/release"; + "LIBRARY_SEARCH_PATHS[sdk=xros*]" = "$(SRCROOT)/target/aarch64-apple-visionos/release"; + "LIBRARY_SEARCH_PATHS[sdk=xrsimulator*]" = "$(SRCROOT)/target/aarch64-apple-visionos-sim/release"; OTHER_LDFLAGS = "-lcoreaudio_apple_example"; OTHER_LIBTOOLFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "coreaudio-rs.coreaudio-ios-example"; PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -428,17 +506,115 @@ "$(inherited)", "@executable_path/Frameworks", ); + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = ( + "$(SRCROOT)/target/aarch64-apple-ios/release", + "$(SRCROOT)/target/aarch64-apple-visionos/release", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = ( + "$(SRCROOT)/target/aarch64-apple-ios-sim/release", + "$(SRCROOT)/target/aarch64-apple-visionos-sim/release", + ); + "LIBRARY_SEARCH_PATHS[sdk=xros*]" = "$(SRCROOT)/target/aarch64-apple-visionos/release"; + "LIBRARY_SEARCH_PATHS[sdk=xrsimulator*]" = "$(SRCROOT)/target/aarch64-apple-visionos-sim/release"; + OTHER_LDFLAGS = "-lcoreaudio_apple_example"; + OTHER_LIBTOOLFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = "coreaudio-rs.coreaudio-ios-example"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 57AB5AEB252766240040DE8C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEBUGGING_SYMBOLS = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 57AB5AEC252766240040DE8C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 968772AC2EF5C86300CBB8F2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "coreaudio-ios-example copy-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = "$(SRCROOT)/target/aarch64-apple-ios/release"; "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(SRCROOT)/target/aarch64-apple-ios-sim/release"; + "LIBRARY_SEARCH_PATHS[sdk=xros*]" = "$(SRCROOT)/target/aarch64-apple-visionos/release"; + "LIBRARY_SEARCH_PATHS[sdk=xrsimulator*]" = "$(SRCROOT)/target/aarch64-apple-visionos-sim/release"; OTHER_LDFLAGS = "-lcoreaudio_apple_example"; OTHER_LIBTOOLFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "coreaudio-rs.coreaudio-ios-example"; PRODUCT_NAME = "$(TARGET_NAME)"; - TARGETED_DEVICE_FAMILY = "1,2"; + SDKROOT = xros; + SUPPORTED_PLATFORMS = "xros xrsimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = 7; + }; + name = Debug; + }; + 968772AD2EF5C86300CBB8F2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "coreaudio-ios-example copy-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = ( + "$(SRCROOT)/target/aarch64-apple-ios/release", + "$(SRCROOT)/target/aarch64-apple-visionos/release", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = ( + "$(SRCROOT)/target/aarch64-apple-ios-sim/release", + "$(SRCROOT)/target/aarch64-apple-visionos-sim/release", + ); + "LIBRARY_SEARCH_PATHS[sdk=xros*]" = "$(SRCROOT)/target/aarch64-apple-visionos/release"; + "LIBRARY_SEARCH_PATHS[sdk=xrsimulator*]" = "$(SRCROOT)/target/aarch64-apple-visionos-sim/release"; + OTHER_LDFLAGS = "-lcoreaudio_apple_example"; + OTHER_LIBTOOLFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = "coreaudio-rs.coreaudio-ios-example"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = xros; + SUPPORTED_PLATFORMS = "xros xrsimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = 7; }; name = Release; }; - /* tvOS target configurations */ TVOS0090252762C30040DE8C /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -483,35 +659,10 @@ }; name = Release; }; - 57AB5AEB252766240040DE8C /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - DEBUGGING_SYMBOLS = YES; - DEBUG_INFORMATION_FORMAT = dwarf; - GCC_GENERATE_DEBUGGING_SYMBOLS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = ""; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 57AB5AEC252766240040DE8C /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = ""; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 57AB5AC5252762C00040DE8C /* Build configuration list for PBXProject "coreaudio-ios-example" */ = { + 57AB5AC5252762C00040DE8C /* Build configuration list for PBXProject "coreaudio-example" */ = { isa = XCConfigurationList; buildConfigurations = ( 57AB5AE1252762C30040DE8C /* Debug */, @@ -529,20 +680,29 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - TVOS0060252762C30040DE8C /* Build configuration list for PBXNativeTarget "coreaudio-tvos-example" */ = { + 57AB5AEA252766240040DE8C /* Build configuration list for PBXLegacyTarget "cargo_apple" */ = { isa = XCConfigurationList; buildConfigurations = ( - TVOS0090252762C30040DE8C /* Debug */, - TVOS0091252762C30040DE8C /* Release */, + 57AB5AEB252766240040DE8C /* Debug */, + 57AB5AEC252766240040DE8C /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 57AB5AEA252766240040DE8C /* Build configuration list for PBXLegacyTarget "cargo_apple" */ = { + 968772AB2EF5C86300CBB8F2 /* Build configuration list for PBXNativeTarget "coreaudio-visionos-example" */ = { isa = XCConfigurationList; buildConfigurations = ( - 57AB5AEB252766240040DE8C /* Debug */, - 57AB5AEC252766240040DE8C /* Release */, + 968772AC2EF5C86300CBB8F2 /* Debug */, + 968772AD2EF5C86300CBB8F2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + TVOS0060252762C30040DE8C /* Build configuration list for PBXNativeTarget "coreaudio-tvos-example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + TVOS0090252762C30040DE8C /* Debug */, + TVOS0091252762C30040DE8C /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/examples/apple/coreaudio-ios-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/examples/apple/coreaudio-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from examples/apple/coreaudio-ios-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to examples/apple/coreaudio-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/examples/apple/coreaudio-ios-example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/apple/coreaudio-example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from examples/apple/coreaudio-ios-example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to examples/apple/coreaudio-example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/examples/apple/coreaudio-example.xcodeproj/project.xcworkspace/xcuserdata/simlay.xcuserdatad/UserInterfaceState.xcuserstate b/examples/apple/coreaudio-example.xcodeproj/project.xcworkspace/xcuserdata/simlay.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..3a8c342f2 Binary files /dev/null and b/examples/apple/coreaudio-example.xcodeproj/project.xcworkspace/xcuserdata/simlay.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/examples/apple/coreaudio-ios-example.xcodeproj/xcshareddata/xcschemes/coreaudio-ios-example.xcscheme b/examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-ios-example.xcscheme similarity index 85% rename from examples/apple/coreaudio-ios-example.xcodeproj/xcshareddata/xcschemes/coreaudio-ios-example.xcscheme rename to examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-ios-example.xcscheme index 71bb8e421..663ce32c4 100644 --- a/examples/apple/coreaudio-ios-example.xcodeproj/xcshareddata/xcschemes/coreaudio-ios-example.xcscheme +++ b/examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-ios-example.xcscheme @@ -14,10 +14,10 @@ buildForAnalyzing = "YES"> + ReferencedContainer = "container:coreaudio-example.xcodeproj"> @@ -43,10 +43,10 @@ runnableDebuggingMode = "0"> + ReferencedContainer = "container:coreaudio-example.xcodeproj"> @@ -60,10 +60,10 @@ runnableDebuggingMode = "0"> + ReferencedContainer = "container:coreaudio-example.xcodeproj"> diff --git a/examples/apple/coreaudio-ios-example.xcodeproj/xcshareddata/xcschemes/coreaudio-tvos-example.xcscheme b/examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-tvos-example.xcscheme similarity index 85% rename from examples/apple/coreaudio-ios-example.xcodeproj/xcshareddata/xcschemes/coreaudio-tvos-example.xcscheme rename to examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-tvos-example.xcscheme index bd887e778..8fe3ccb96 100644 --- a/examples/apple/coreaudio-ios-example.xcodeproj/xcshareddata/xcschemes/coreaudio-tvos-example.xcscheme +++ b/examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-tvos-example.xcscheme @@ -14,10 +14,10 @@ buildForAnalyzing = "YES"> + ReferencedContainer = "container:coreaudio-example.xcodeproj"> @@ -43,10 +43,10 @@ runnableDebuggingMode = "0"> + ReferencedContainer = "container:coreaudio-example.xcodeproj"> @@ -60,10 +60,10 @@ runnableDebuggingMode = "0"> + ReferencedContainer = "container:coreaudio-example.xcodeproj"> diff --git a/examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-visionos-example.xcscheme b/examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-visionos-example.xcscheme new file mode 100644 index 000000000..4094458f4 --- /dev/null +++ b/examples/apple/coreaudio-example.xcodeproj/xcshareddata/xcschemes/coreaudio-visionos-example.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/apple/coreaudio-example.xcodeproj/xcuserdata/simlay.xcuserdatad/xcschemes/xcschememanagement.plist b/examples/apple/coreaudio-example.xcodeproj/xcuserdata/simlay.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 000000000..9f46ea030 --- /dev/null +++ b/examples/apple/coreaudio-example.xcodeproj/xcuserdata/simlay.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,29 @@ + + + + + SchemeUserState + + cargo_apple.xcscheme_^#shared#^_ + + orderHint + 3 + + coreaudio-ios-example.xcscheme_^#shared#^_ + + orderHint + 0 + + coreaudio-tvos-example.xcscheme_^#shared#^_ + + orderHint + 1 + + coreaudio-visionos-example.xcscheme_^#shared#^_ + + orderHint + 2 + + + + diff --git a/examples/apple/coreaudio-ios-example copy-Info.plist b/examples/apple/coreaudio-ios-example copy-Info.plist new file mode 100644 index 000000000..462567911 --- /dev/null +++ b/examples/apple/coreaudio-ios-example copy-Info.plist @@ -0,0 +1,49 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSupportsIndirectInputEvents + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + NSMicrophoneUsageDescription + coreaudio-rs feedback demo + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/examples/apple/rust-toolchain.toml b/examples/apple/rust-toolchain.toml new file mode 100644 index 000000000..c91614166 --- /dev/null +++ b/examples/apple/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly" +targets = ["aarch64-apple-ios-sim", "aarch64-apple-ios"] +components = ["rust-src"] diff --git a/examples/sine.rs b/examples/sine.rs index 2fb5a00e4..82b654197 100644 --- a/examples/sine.rs +++ b/examples/sine.rs @@ -34,13 +34,35 @@ impl Iterator for SineWaveGenerator { } fn main() -> Result<(), coreaudio::Error> { + #[cfg(any(target_os = "ios", target_os = "visionos", target_os = "tvos"))] + unsafe { + let session = objc2_avf_audio::AVAudioSession::sharedInstance(); + + #[cfg(target_os = "tvos")] + let _ = session.setCategory_error( + objc2_avf_audio::AVAudioSessionCategoryPlayback.expect("Failed to get option"), + ); + #[cfg(any(target_os = "ios", target_os = "tvos"))] + let _ = session.setCategory_withOptions_error( + objc2_avf_audio::AVAudioSessionCategoryPlayAndRecord.expect("Failed to get options"), + objc2_avf_audio::AVAudioSessionCategoryOptions::DefaultToSpeaker, + ); + } let frequency_hz = 440.; let volume = 0.15; let mut samples = SineWaveGenerator::new(frequency_hz, volume); // Construct an Output audio unit that delivers audio to the default output device. + #[cfg(target_os = "macos")] let mut audio_unit = AudioUnit::new(IOType::DefaultOutput)?; + #[cfg(any(target_os = "ios", target_os = "visionos", target_os = "tvos"))] + let mut audio_unit = AudioUnit::new(coreaudio::audio_unit::IOType::RemoteIO)?; + + // iOS/tvOS/visionOS don't let you reconfigure an "initialized" audio unit, so uninitialize it + #[cfg(any(target_os = "ios", target_os = "visionos", target_os = "tvos"))] + audio_unit.uninitialize()?; + // Read the input format. This is counterintuitive, but it's the format used when sending // audio data to the AudioUnit representing the output device. This is separate from the // format the AudioUnit later uses to send the data to the hardware device. @@ -65,9 +87,13 @@ fn main() -> Result<(), coreaudio::Error> { } Ok(()) })?; + #[cfg(any(target_os = "ios", target_os = "visionos", target_os = "tvos"))] + audio_unit.initialize()?; + audio_unit.start()?; + println!("Audio started - playing 440Hz sine wave"); - std::thread::sleep(std::time::Duration::from_millis(3000)); + std::thread::sleep(std::time::Duration::from_millis(10_000)); Ok(()) } diff --git a/src/audio_unit/mod.rs b/src/audio_unit/mod.rs index 6809d7c69..5f1c207d4 100644 --- a/src/audio_unit/mod.rs +++ b/src/audio_unit/mod.rs @@ -449,7 +449,7 @@ pub unsafe fn get_property( /// ---------- /// /// - **id**: The identifier of the property. -#[cfg(any(target_os = "ios", target_os = "tvos"))] +#[cfg(any(target_os = "ios", target_os = "tvos", target_os = "visionos"))] pub fn audio_session_get_property(id: u32) -> Result { let mut size = ::std::mem::size_of::() as u32; #[allow(deprecated)] diff --git a/src/audio_unit/render_callback.rs b/src/audio_unit/render_callback.rs index e6a767b21..07193bccd 100644 --- a/src/audio_unit/render_callback.rs +++ b/src/audio_unit/render_callback.rs @@ -571,7 +571,7 @@ impl AudioUnit { let buffer_frame_size: u32 = self.get_property(id, Scope::Global, Element::Output)?; buffer_frame_size }; - #[cfg(any(target_os = "ios", target_os = "tvos"))] + #[cfg(any(target_os = "ios", target_os = "tvos", target_os = "visionos"))] let mut buffer_frame_size: u32 = { let id = objc2_audio_toolbox::kAudioSessionProperty_CurrentHardwareIOBufferDuration; let seconds: f32 = super::audio_session_get_property(id)?; diff --git a/src/audio_unit/types.rs b/src/audio_unit/types.rs index 915f81da6..facbfda30 100644 --- a/src/audio_unit/types.rs +++ b/src/audio_unit/types.rs @@ -468,6 +468,6 @@ pub enum IOType { /// /// See /// **Available** in iOS 2.0 and later, and tvOS 9.0 and later. - #[cfg(any(target_os = "ios", target_os = "tvos"))] + #[cfg(any(target_os = "ios", target_os = "tvos", target_os = "visionos"))] RemoteIO = 1919512419, // kAudioUnitSubType_RemoteIO, only available in the iOS/tvOS SDK }