require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) schema = JSON.parse(File.read(File.join(__dir__, 'schema.json'))) if ENV['ONE_PREBUILT_IOS'] == '0' prebuilt = { 'reason' => 'source build requested' } else # autolinking reads the podspec before use_react_native! initializes these. # use upstream's resolved mode, including an unavailable binary's source build. rn_manifest = Pod::Executable.execute_command('node', ['-p', 'require.resolve("react-native/package.json", {paths: [process.argv[1]]})', Pod::Config.instance.installation_root.to_s]).strip rn_package = JSON.parse(File.read(rn_manifest)) ENV['RCT_USE_PREBUILT_RNCORE'] = ENV['RCT_USE_PREBUILT_RNCORE'] == '0' ? '0' : '1' ENV['RCT_USE_RN_DEP'] = ENV['RCT_USE_RN_DEP'] == '0' ? '0' : '1' ReactNativeCoreUtils.setup_rncore(File.dirname(rn_manifest), rn_package['version']) ReactNativeDependenciesUtils.setup_react_native_dependencies(File.dirname(rn_manifest), rn_package['version']) rn_mode = !ReactNativeCoreUtils.build_rncore_from_source() && !ReactNativeDependenciesUtils.build_react_native_deps_from_source() ? 'prebuilt' : 'source' prebuilt = JSON.parse(Pod::Executable.execute_command('node', [File.join(__dir__, 'ios/prebuilt.mjs'), 'resolve', Pod::Config.instance.installation_root.to_s, rn_mode])) end Pod::Spec.new do |s| s.name = 'One' s.version = package['version'] s.summary = package['description'] s.description = package['description'] s.license = package['license'] s.author = 'one' s.homepage = 'https://github.com/onejs/one' s.platforms = { :ios => "#{schema['minimumVersion']}.0" } s.swift_version = '5.9' s.source = { git: 'https://github.com/onejs/one.git' } s.static_framework = true sdk_version = Gem::Version.new(`xcrun --sdk iphoneos --show-sdk-version`.strip) swift_flags = '$(inherited) -Xcc -Wno-non-modular-include-in-framework-module' # one flag per SDK that declares newer api: generated swift guards that api with it, so # an older Xcode still compiles. codegen/sdkGuard.ts lists the same versions. { '27' => 'ONE_IOS_27_SDK', '27.1' => 'ONE_IOS_27_1_SDK' }.each do |version, flag| swift_flags += " -D #{flag}" if sdk_version >= Gem::Version.new(version) end # feature groups link only the apple frameworks they need (ios-link-set.json). debug # builds every group. other configurations build the groups the app's production # bundle uses, which `one prebuild` writes to ios/one-link-set.json; an app without # that file builds every group. catalog = JSON.parse(File.read(File.join(__dir__, 'ios-link-set.json')))['groups'].keys link_set_file = File.join(Pod::Config.instance.installation_root, 'one-link-set.json') release_groups = File.exist?(link_set_file) ? JSON.parse(File.read(link_set_file))['groups'] : catalog unknown = release_groups - catalog raise "#{link_set_file} names unknown groups: #{unknown.join(', ')}" unless unknown.empty? group_flags = ->(groups) { groups.map { |group| "ONE_GROUP_#{group.upcase}" } } s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => (['$(inherited)'] + group_flags.(release_groups)).join(' '), 'SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug]' => (['$(inherited)'] + group_flags.(catalog)).join(' '), 'GCC_PREPROCESSOR_DEFINITIONS' => (['$(inherited)'] + group_flags.(release_groups).map { |flag| "#{flag}=1" }).join(' '), 'GCC_PREPROCESSOR_DEFINITIONS[config=Debug]' => (['$(inherited)'] + group_flags.(catalog).map { |flag| "#{flag}=1" }).join(' '), 'SWIFT_COMPILATION_MODE' => 'incremental', 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES', 'OTHER_SWIFT_FLAGS' => swift_flags, 'HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)/cpp" "$(OBJECT_FILE_DIR_normal)/$(CURRENT_ARCH)"', } # required-reason api declarations (user defaults, boot time, file # timestamps, disk space); xcode aggregates these into the app manifest. s.resource_bundles = { 'One' => ['ios/PrivacyInfo.xcprivacy'] } # c entries the app's bridging header imports without importing the one module. # nitrogen appends its own public headers after these. # nitro hybrid objects: nitrogen generates the specs and bridges from # src/specs/*.nitro.ts into nitrogen/generated (see README). # declared for both paths: the app's bridging header imports these C # entries without importing the One module, and the sources are present # in the pod either way. s.public_header_files = 'ios/SDK/OneSDKBridge.h', 'ios/Nitro/OneUpdatesLauncherBridge.h', 'ios/Nitro/OneLaunchScreen.h', 'ios/Nitro/OneViewCulling.h', 'ios/Nitro/OneBackgroundTasksBridge.h', 'ios/Nitro/OneAppIntentsBridge.h', 'ios/OneNativeSourceEventsBridge.h', 'ios/Keyboard/objc/TextInput+OneKCDelegateManager.h', 'ios/Keyboard/objc/NSObject+OneKCSafeKVC.h' if prebuilt['path'] Pod::UI.puts "[One] Using precompiled iOS libraries (#{File.basename(prebuilt['path'])[0, 12]})" s.vendored_frameworks = "#{prebuilt['path']}/Debug/One.xcframework" s.preserve_paths = ['ios/prebuilt.mjs', "#{prebuilt['path']}/**/*"] s.module_map = false s.dependency 'NitroModules' s.script_phase = { :name => '[One] Select precompiled iOS configuration', :execution_position => :before_compile, :always_out_of_date => '1', :script => <<~SCRIPT set -e . "$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh" "$NODE_BINARY" "$PODS_TARGET_SRCROOT/ios/prebuilt.mjs" select "$PODS_TARGET_SRCROOT/#{prebuilt['path']}" "$PODS_XCFRAMEWORKS_BUILD_DIR/One" SCRIPT } else Pod::UI.puts "[One] Compiling native sources: #{prebuilt['reason']}" shadow_members = Dir[File.join(__dir__, 'cpp/OneNativeShadowNodeBatch*.cpp')].flat_map do |file| File.read(file).scan(/#include "([^"]+\.cpp)"/).flatten.map { |name| "cpp/#{name}" } end s.exclude_files = ['ios/Tests/**/*', 'ios/Generated/*ComponentView.mm', 'ios/Prebuilt/**/*'] + shadow_members s.source_files = 'ios/**/*.{h,m,swift,mm,cpp}', 'cpp/**/*.{h,cpp}' load 'nitrogen/generated/ios/One+autolinking.rb' add_nitrogen_files(s) end op_manifest = IO.popen(['node', '--print', "require.resolve('@op-engineering/op-sqlite/package.json', {paths: [process.argv[1]]})", Pod::Config.instance.installation_root.to_s], &:read).strip raise 'One requires the installed @op-engineering/op-sqlite package' if op_manifest.empty? app_directory = File.dirname(File.dirname(op_manifest)) loop do break if File.file?(File.join(app_directory, 'package.json')) parent = File.dirname(app_directory) raise 'op-sqlite application package.json not found' if parent == app_directory app_directory = parent end op_config = JSON.parse(File.read(File.join(app_directory, 'package.json')))['op-sqlite'] || {} if op_config['libsql'] == true || op_config['turso'] == true s.exclude_files = Array(s.attributes_hash['exclude_files']) + ['cpp/zero/**/*'] zero_config = s.attributes_hash['pod_target_xcconfig'].dup ['GCC_PREPROCESSOR_DEFINITIONS', 'GCC_PREPROCESSOR_DEFINITIONS[config=Debug]'].each do |key| zero_config[key] += ' ONE_ZERO_SQLITE=0' end s.pod_target_xcconfig = zero_config end # objc++ units build without clang modules, so One-Swift.h skips its # own @import lines (React, UserNotifications, Social) and never sees the # nitro bridge types its c++ section names; every unit gets them first. s.prefix_header_contents = "#ifdef __OBJC__\n#import \n#import \n#import \n#endif\n#ifdef __cplusplus\n#include \"OneSDKBridge.h\"\n#include \"One-Swift-Cxx-Bridge.hpp\"\n#endif" s.dependency 'op-sqlite' s.dependency 'RNWorklets' # webp encoding has no system encoder on ios; expo-image-manipulator uses the same coder. s.dependency 'SDWebImageWebPCoder', '>= 0.14.6', '< 0.16' install_modules_dependencies(s) end