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
8 changes: 6 additions & 2 deletions apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNAudioAPI/audioapi (= 0.11.0)
- RNWorklets
- SocketRocket
- Yoga
- RNAudioAPI/audioapi (0.11.0):
Expand Down Expand Up @@ -2625,6 +2626,7 @@ PODS:
- ReactCommon/turbomodule/core
- RNAudioAPI/audioapi/audioapi_dsp (= 0.11.0)
- RNAudioAPI/audioapi/ios (= 0.11.0)
- RNWorklets
- SocketRocket
- Yoga
- RNAudioAPI/audioapi/audioapi_dsp (0.11.0):
Expand Down Expand Up @@ -2653,6 +2655,7 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNWorklets
- SocketRocket
- Yoga
- RNAudioAPI/audioapi/ios (0.11.0):
Expand Down Expand Up @@ -2681,6 +2684,7 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNWorklets
- SocketRocket
- Yoga
- RNGestureHandler (2.30.0):
Expand Down Expand Up @@ -3287,7 +3291,7 @@ SPEC CHECKSUMS:
FBLazyVector: 309703e71d3f2f1ed7dc7889d58309c9d77a95a4
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
hermes-engine: 42d6f09ee6ede2feb220e2fb772e8bebb42ca403
hermes-engine: f93b5009d8ccd9429fe2a772351980df8a22a413
RCT-Folly: 846fda9475e61ec7bcbf8a3fe81edfcaeb090669
RCTDeprecation: a41bbdd9af30bf2e5715796b313e44ec43eefff1
RCTRequired: 7be34aabb0b77c3cefe644528df0fa0afad4e4d0
Expand Down Expand Up @@ -3360,7 +3364,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 0eb286cc274abb059ee601b862ebddac2e681d01
ReactCodegen: b8e56b780fffe6edd6405be0af4a1e3049a937f7
ReactCommon: ac934cb340aee91282ecd6f273a26d24d4c55cae
RNAudioAPI: c7dc7b491a0e4b23535a55fd9b4a00d0f803f4bb
RNAudioAPI: aa794adb23edd2564e825dc6006e8504d20c3eb9
RNGestureHandler: cd4be101cfa17ea6bbd438710caa02e286a84381
RNReanimated: 132940c4c15ca2757f4f7d1fd7c9c3c01dbc4689
RNScreens: ffbb0296608eb3560de641a711bbdb663ed1f6b4
Expand Down
105 changes: 65 additions & 40 deletions packages/react-native-audio-api/RNAudioAPI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ require "json"
require_relative './scripts/rnaa_utils'

package_json = JSON.parse(File.read(File.join(__dir__, "package.json")))
$audio_api_config = find_audio_api_config()

$new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
$RN_AUDIO_API_FFMPEG_DISABLED = ENV['DISABLE_AUDIOAPI_FFMPEG'].nil? ? false : ENV['DISABLE_AUDIOAPI_FFMPEG'] == '1' # false by default

folly_flags = "-DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32"
fabric_flags = $new_arch_enabled ? '-DRCT_NEW_ARCH_ENABLED' : ''
version_flag = "-DAUDIOAPI_VERSION=#{package_json['version']}"
ios_min_version = '14.0'

worklets_enabled = $audio_api_config[:worklets_enabled]
worklets_preprocessor_flag = worklets_enabled ? '-DRN_AUDIO_API_ENABLE_WORKLETS=1' : ''

worklets_preprocessor_flag = check_if_worklets_enabled() ? '-DRN_AUDIO_API_ENABLE_WORKLETS=1' : ''
ffmpeg_flag = $RN_AUDIO_API_FFMPEG_DISABLED ? '-DRN_AUDIO_API_FFMPEG_DISABLED=1' : ''
skip_ffmpeg_argument = $RN_AUDIO_API_FFMPEG_DISABLED ? 'skipffmpeg' : ''

Expand All @@ -22,7 +25,7 @@ Pod::Spec.new do |s|
s.license = package_json["license"]
s.authors = package_json["author"]

s.platforms = { :ios => min_ios_version_supported }
s.platforms = { :ios => ios_min_version }
s.source = { :git => "https://github.com/software-mansion/react-native-audio-api.git", :tag => "#{s.version}" }

s.subspec "audioapi" do |ss|
Expand All @@ -45,9 +48,11 @@ Pod::Spec.new do |s|
end
end

s.ios.frameworks = 'CoreFoundation', 'CoreAudio', 'AudioToolbox', 'Accelerate', 'MediaPlayer', 'AVFoundation'
if worklets_enabled
s.dependency 'RNWorklets'
end

s.compiler_flags = "#{folly_flags}"
s.ios.frameworks = 'Accelerate', 'AVFoundation', 'MediaPlayer'

s.prepare_command = <<-CMD
chmod +x scripts/download-prebuilt-binaries.sh
Expand All @@ -67,41 +72,61 @@ Pod::Spec.new do |s|
'common/cpp/audioapi/external/ffmpeg_ios/libavutil.xcframework',
'common/cpp/audioapi/external/ffmpeg_ios/libswresample.xcframework'
]
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) HAVE_ACCELERATE=1',
"HEADER_SEARCH_PATHS" => %W[
$(PODS_TARGET_SRCROOT)/common/cpp
$(PODS_TARGET_SRCROOT)/ios
$(PODS_ROOT)/Headers/Public/RNWorklets
$(PODS_ROOT)/Headers/Private/React-Core
$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/include
$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/include/opus
$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/include/vorbis
].concat($RN_AUDIO_API_FFMPEG_DISABLED ? [] : ["$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/ffmpeg_include"]).join(" "),
'OTHER_CFLAGS' => "$(inherited) #{folly_flags} #{fabric_flags} #{version_flag} #{worklets_preprocessor_flag} #{ffmpeg_flag}",
'OTHER_CPLUSPLUSFLAGS' => "$(inherited) #{folly_flags} #{fabric_flags} #{version_flag} #{worklets_preprocessor_flag} #{ffmpeg_flag}",
}

s.user_target_xcconfig = {
'OTHER_LDFLAGS' => %W[
$(inherited)
-force_load #{lib_dir}/libopusfile.a
-force_load #{lib_dir}/libopus.a
-force_load #{lib_dir}/libogg.a
-force_load #{lib_dir}/libvorbis.a
-force_load #{lib_dir}/libvorbisenc.a
-force_load #{lib_dir}/libvorbisfile.a
-force_load #{lib_dir}/libssl.a
-force_load #{lib_dir}/libcrypto.a
].join(" "),
'HEADER_SEARCH_PATHS' => %W[
$(inherited)
$(PODS_ROOT)/Headers/Public/RNAudioAPI
$(PODS_TARGET_SRCROOT)/common/cpp
].join(' ')
}

s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"DEFINES_MODULE" => "YES",
"HEADER_SEARCH_PATHS" => [
'"$(PODS_TARGET_SRCROOT)/ReactCommon"',
'"$(PODS_TARGET_SRCROOT)"',
'"$(PODS_ROOT)/RCT-Folly"',
'"$(PODS_ROOT)/boost"',
'"$(PODS_ROOT)/boost-for-react-native"',
'"$(PODS_ROOT)/DoubleConversion"',
'"$(PODS_ROOT)/Headers/Private/React-Core"',
'"$(PODS_ROOT)/Headers/Private/Yoga"',
"\"$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/include\"",
"\"$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/include/opus\"",
"\"$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/include/vorbis\"",
]
.concat($RN_AUDIO_API_FFMPEG_DISABLED ? [] : ["\"$(PODS_TARGET_SRCROOT)/#{external_dir_relative}/ffmpeg_include\""])
.concat(worklets_enabled ? ['"$(PODS_ROOT)/Headers/Public/RNWorklets"'] : [])
.join(' '),
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) HAVE_ACCELERATE=1',
'OTHER_CFLAGS' => "$(inherited) #{fabric_flags} #{version_flag} #{worklets_preprocessor_flag} #{ffmpeg_flag}",
}

s.xcconfig = {
"HEADER_SEARCH_PATHS" => [
'"$(PODS_ROOT)/boost"',
'"$(PODS_ROOT)/boost-for-react-native"',
'"$(PODS_ROOT)/glog"',
'"$(PODS_ROOT)/RCT-Folly"',
'"$(PODS_ROOT)/Headers/Public/React-hermes"',
'"$(PODS_ROOT)/Headers/Public/hermes-engine"',
"\"$(PODS_ROOT)/#{$audio_api_config[:react_native_common_dir]}\"",
"\"$(PODS_ROOT)/#{$audio_api_config[:dynamic_frameworks_audio_api_dir]}/ios\"",
"\"$(PODS_ROOT)/#{$audio_api_config[:dynamic_frameworks_audio_api_dir]}/common/cpp\"",
]
.concat(worklets_enabled ? [
'"$(PODS_ROOT)/Headers/Public/RNWorklets"',
"\"$(PODS_ROOT)/#{$audio_api_config[:dynamic_frameworks_worklets_dir]}/apple\"",
"\"$(PODS_ROOT)/#{$audio_api_config[:dynamic_frameworks_worklets_dir]}/Common/cpp\""
] : [])
.join(' '),
'OTHER_LDFLAGS' => %W[
$(inherited)
-force_load #{lib_dir}/libopusfile.a
-force_load #{lib_dir}/libopus.a
-force_load #{lib_dir}/libogg.a
-force_load #{lib_dir}/libvorbis.a
-force_load #{lib_dir}/libvorbisenc.a
-force_load #{lib_dir}/libvorbisfile.a
-force_load #{lib_dir}/libssl.a
-force_load #{lib_dir}/libcrypto.a
].join(" "),
}
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
install_modules_dependencies(s)
Expand Down
50 changes: 50 additions & 0 deletions packages/react-native-audio-api/scripts/rnaa_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,53 @@ def check_if_worklets_enabled()
end
true
end

def try_to_parse_react_native_package_json(node_modules_dir)
react_native_package_json_path = File.join(node_modules_dir, 'react-native/package.json')
if !File.exist?(react_native_package_json_path)
return nil
end
return JSON.parse(File.read(react_native_package_json_path))
end

def find_audio_api_config()
result = {
:worklets_enabled => nil,
:react_native_common_dir => nil,
:dynamic_frameworks_audio_api_dir => nil,
:dynamic_frameworks_worklets_dir => nil
}

result[:worklets_enabled] = check_if_worklets_enabled()

react_native_node_modules_dir = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..')
react_native_json = try_to_parse_react_native_package_json(react_native_node_modules_dir)

if react_native_json == nil
# user configuration, just in case
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
react_native_json = try_to_parse_react_native_package_json(node_modules_dir)
end

if react_native_json == nil
raise '[AudioAPI] Unable to recognize your `react-native` version. Please set environmental variable with `react-native` location: `export REACT_NATIVE_NODE_MODULES_DIR="<path to react-native>" && pod install`.'
end

pods_root = Pod::Config.instance.project_pods_root
react_native_common_dir_absolute = File.join(react_native_node_modules_dir, 'react-native', 'ReactCommon')
react_native_common_dir_relative = Pathname.new(react_native_common_dir_absolute).relative_path_from(pods_root).to_s
result[:react_native_common_dir] = react_native_common_dir_relative

react_native_audio_api_dir_absolute = File.join(__dir__, '..')
react_native_audio_api_dir_relative = Pathname.new(react_native_audio_api_dir_absolute).relative_path_from(pods_root).to_s
result[:dynamic_frameworks_audio_api_dir] = react_native_audio_api_dir_relative

if result[:worklets_enabled] == true
react_native_worklets_node_modules_dir = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native-worklets/package.json')"`), '..')
react_native_worklets_dir_absolute = File.join(react_native_worklets_node_modules_dir, 'react-native-worklets')
react_native_worklets_dir_relative = Pathname.new(react_native_worklets_dir_absolute).relative_path_from(pods_root).to_s
result[:dynamic_frameworks_worklets_dir] = react_native_worklets_dir_relative
end

return result
end