Repository navigation
feat: spm support for audio worklets #1355
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // swift-tools-version: 6.0 | ||
| import Foundation | ||
| import PackageDescription | ||
|
|
||
| let packageDirectory = Context.packageDirectory | ||
|
|
||
| func readPackageVersion() -> String { | ||
| let url = URL(fileURLWithPath: packageDirectory).appendingPathComponent("package.json") | ||
| guard let data = try? Data(contentsOf: url), | ||
| let packageJSON = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any], | ||
| let version = packageJSON["version"] as? String | ||
| else { | ||
| fatalError("[RNAudioWorklets] Cannot read the version from \(url.path)") | ||
| } | ||
| return version | ||
| } | ||
|
|
||
| /// React Native autolinks every library as a sibling under | ||
| /// `<app>/ios/build/generated/autolinking/libs/<SwiftName>`, which is also where the `.package` | ||
| /// dependencies below point. react-native-audio-api's target exposes no headers (a module over | ||
| /// every engine header is not wanted), so its `<audioapi/...>` headers are reached by path, the | ||
| /// SwiftPM counterpart of the podspec's `Headers/Public/RNAudioAPI` search path. | ||
| let audioAPIHeadersPath = URL(fileURLWithPath: packageDirectory) | ||
| .deletingLastPathComponent() | ||
| .appendingPathComponent("ReactNativeAudioApi/common/cpp") | ||
| .path | ||
|
|
||
| let headerSearchPaths = ["common/cpp", "ios"] | ||
| let defines: [(name: String, value: String)] = [ | ||
| ("RCT_NEW_ARCH_ENABLED", "1"), | ||
| ("AUDIO_WORKLETS_VERSION", readPackageVersion()), | ||
| ] | ||
|
|
||
| // React Native's headers change class layouts on NDEBUG (without it `DebugStringConvertible` | ||
| // gains virtual methods) and the prebuilt React framework is built with NDEBUG in Release, so | ||
| // DEBUG/NDEBUG follow the configuration exactly, as in RNAudioAPI and React Native's own targets. | ||
| let cSettings: [CSetting] = | ||
| headerSearchPaths.map { .headerSearchPath($0) } + defines.map { .define($0.name, to: $0.value) } + [ | ||
| .define("DEBUG", to: "1", .when(configuration: .debug)), | ||
| .define("NDEBUG", .when(configuration: .release)), | ||
| .unsafeFlags(["-I", audioAPIHeadersPath]), | ||
| ] | ||
| let cxxSettings: [CXXSetting] = | ||
| headerSearchPaths.map { .headerSearchPath($0) } + defines.map { .define($0.name, to: $0.value) } + [ | ||
| .define("DEBUG", to: "1", .when(configuration: .debug)), | ||
| .define("NDEBUG", .when(configuration: .release)), | ||
| .unsafeFlags(["-I", audioAPIHeadersPath]), | ||
| ] | ||
|
|
||
| let reactHeaders: [Target.Dependency] = [ | ||
| .product(name: "ReactHeaders", package: "ReactNative"), | ||
| .product(name: "ReactNativeHeaders", package: "ReactNative"), | ||
| .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"), | ||
| .product(name: "ReactAppHeaders", package: "React-GeneratedCode"), | ||
| ] | ||
|
|
||
| // The package and product name is what React Native 0.87 derives from the npm name; 0.88 reads it | ||
| // from `swiftpmConfig.name` in package.json, which repeats it. | ||
| let package = Package( | ||
| name: "ReactNativeAudioWorklets", | ||
| platforms: [.iOS(.v15)], | ||
| products: [ | ||
| .library(name: "ReactNativeAudioWorklets", targets: ["RNAudioWorklets"]) | ||
| ], | ||
| dependencies: [ | ||
| .package(name: "ReactNative", path: "../../../../xcframeworks"), | ||
| .package(name: "React-GeneratedCode", path: "../../../ios"), | ||
| .package(name: "ReactNativeAudioApi", path: "../ReactNativeAudioApi"), | ||
| .package(name: "RNWorklets", path: "../RNWorklets"), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "RNAudioWorklets", | ||
| dependencies: reactHeaders + [ | ||
| .product(name: "ReactNativeAudioApi", package: "ReactNativeAudioApi"), | ||
| .product(name: "RNWorklets", package: "RNWorklets"), | ||
| ], | ||
| path: ".", | ||
| sources: ["common/cpp/audioworklets", "ios/audioworklets"], | ||
| publicHeadersPath: "ios/spm/include", | ||
| cSettings: cSettings, | ||
| cxxSettings: cxxSettings | ||
| ) | ||
| ], | ||
| cxxLanguageStandard: .cxx20 | ||
| ) |
2 changes: 2 additions & 0 deletions
2
packages/react-native-audio-worklets/ios/spm/include/.gitkeep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // The RNAudioWorklets SwiftPM target exposes no headers, but SwiftPM fails to resolve the package | ||
| // when a target's public headers directory is missing, so Package.swift points publicHeadersPath here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.