-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[ios-prebuild] Implemented support for prebuilt in cocoapods #52109
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
269456c
[ios-prebuild] Implemented support for prebuilt in cocoapods
chrfalch 1e8c963
refactor: extract abort code to helper function
cipolleschi 0e91ead
refactor: simplify if check
cipolleschi 7b456c0
refactor: rename podspec_source_download_prebuild_release_tarball to …
cipolleschi 5adfe16
rename: release_tarball_url to stable
cipolleschi e0b0756
fix: handle XML requests properly
cipolleschi 93dc62a
fix: remove resolve_redirect as it is not used
cipolleschi 742c205
fix: remove resolve_redirect from rndependencies as it is not used
cipolleschi 284a20b
refactor: abort if use local rndeps when no file is present
cipolleschi ad732b8
fix: fix build from source
cipolleschi 08a6a1a
chore: add task to TODO
cipolleschi 0aa7989
fix: revert change to dSYM path
cipolleschi 6f1e48d
[ios][prebuild] fixed missing changes to ReactCodegen.podspec.template
chrfalch 3252173
[ios][prebuild] fixed header search paths in ReactCodegen template
chrfalch b7b0013
fix: support build rn core from source with prebuild rn dep
cipolleschi 27d152c
Update snapshot of ReactCodegen.podspec.template
cipolleschi c863979
fix: reset Podfile
cipolleschi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # | ||
| # This source code is licensed under the MIT license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| require "json" | ||
|
|
||
| begin | ||
| react_native_path = File.dirname(Pod::Executable.execute_command('node', ['-p', | ||
| 'require.resolve( | ||
| "react-native", | ||
| {paths: [process.argv[1]]}, | ||
| )', __dir__]).strip | ||
| ) | ||
| rescue => e | ||
| # Fallback to the parent directory if the above command fails (e.g when building locally in OOT Platform) | ||
| react_native_path = File.join(__dir__, "..", "..") | ||
| end | ||
|
|
||
| # package.json | ||
| package = JSON.parse(File.read(File.join(react_native_path, "package.json"))) | ||
| version = package['version'] | ||
|
|
||
| source = ReactNativeCoreUtils.resolve_podspec_source() | ||
|
|
||
| header_search_paths = [ | ||
| "${PODS_ROOT}/Headers/Private/React-Core-prebuilt", | ||
| "${PODS_ROOT}/Headers/Private/React-Core-prebuilt/RCTDeprecation", | ||
| "${PODS_ROOT}/Headers/Private/React-Core-prebuilt/ReactCommon/yoga", | ||
| "${PODS_ROOT}/Headers/Private/React-Core-prebuilt/ReactCommon", | ||
| "${PODS_ROOT}/Headers/Private/React-Core-prebuilt/Libraries/AppDelegate", | ||
| "${PODS_ROOT}/Headers/Private/React-Core-prebuilt/Libraries", | ||
|
|
||
| "$(REACT_NATIVE_PATH)/React/Base", | ||
| "$(REACT_NATIVE_PATH)/ReactCommon", | ||
| "$(REACT_NATIVE_PATH)/Libraries", | ||
| "$(REACT_NATIVE_PATH)/ReactApple", | ||
| "$(REACT_NATIVE_PATH)/ReactCxxPlatform", | ||
| "$(REACT_NATIVE_PATH)/ReactCommon/react/runtime/platform/ios", | ||
| "${REACT_NATIVE_PATH}/ReactCommon/jsi", | ||
| "$(REACT_NATIVE_PATH)/ReactCommon/jsiexecutor/", | ||
| "$(REACT_NATIVE_PATH)/ReactCommon/react/nativemodule/samples/platform/ios", | ||
| "$(REACT_NATIVE_PATH)/ReactCommon/react/nativemodule/samples", | ||
| ] | ||
|
|
||
| Pod::Spec.new do |spec| | ||
| spec.name = 'React-Core-prebuilt' | ||
| spec.version = version | ||
| spec.summary = "Prebuilt core of React Native." | ||
| spec.homepage = "https://reactnative.dev/" | ||
| spec.description = 'Prebuilt React Native Core libraries and headers' | ||
| spec.homepage = 'https://github.com/facebook/react-native' | ||
| spec.license = package['license'] | ||
| spec.authors = 'meta' | ||
| spec.platforms = min_supported_versions | ||
| spec.source = source | ||
|
|
||
| spec.vendored_frameworks = "React.xcframework" | ||
|
|
||
| spec.preserve_paths = '**/*.*' | ||
| spec.header_mappings_dir = 'React.xcframework/Headers' | ||
| spec.source_files = 'React.xcframework/Headers/**/*.{h,hpp}' | ||
|
|
||
| spec.module_name = 'React' | ||
| spec.module_map = 'React.xcframework/Modules/module.modulemap' | ||
| spec.public_header_files = 'React.xcframework/Headers/**/*.h' | ||
|
|
||
| # Setup the consuming project's search paths | ||
| spec.user_target_xcconfig = { | ||
| "HEADER_SEARCH_PATHS" => header_search_paths, | ||
| "SWIFT_INCLUDE_PATHS" => "${PODS_ROOT}/Headers/Private/React-Core-prebuilt", | ||
| 'DEFINES_MODULE' => 'YES', | ||
| 'CLANG_ENABLE_MODULES' => 'YES', | ||
| } | ||
|
|
||
| spec.pod_target_xcconfig = { | ||
| 'WARNING_CFLAGS' => '-Wno-comma -Wno-shorten-64-to-32', | ||
| "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), | ||
| 'DEFINES_MODULE' => 'YES', | ||
| 'CLANG_ENABLE_MODULES' => 'YES', | ||
| } | ||
|
|
||
| # We need to make sure that the React.xcframework is copied correctly - in the downloaded tarball | ||
| # the root directory is the framework, but when using it we need to have it in a subdirectory | ||
| # called React.xcframework, so we need to move the contents of the tarball into that directory. | ||
| # This is done in the prepare_command. | ||
| spec.prepare_command = <<~'CMD' | ||
| CURRENT_PATH=$(pwd) | ||
| XCFRAMEWORK_PATH="${CURRENT_PATH}/React.xcframework" | ||
| mkdir -p "${XCFRAMEWORK_PATH}" | ||
| find "$CURRENT_PATH" -mindepth 1 -maxdepth 1 ! -name "$(basename "$XCFRAMEWORK_PATH")" -exec mv {} "$XCFRAMEWORK_PATH" \; | ||
| CMD | ||
|
|
||
| # If we are passing a local tarball, we don't want to switch between Debug and Release | ||
| if !ENV["RCT_USE_LOCAL_RN_CORE"] | ||
| script_phase = { | ||
| :name => "[RNDeps] Replace React Native Core for the right configuration, if needed", | ||
| :execution_position => :before_compile, | ||
| :script => <<-EOS | ||
| . "$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh" | ||
|
|
||
| CONFIG="Release" | ||
| if echo $GCC_PREPROCESSOR_DEFINITIONS | grep -q "DEBUG=1"; then | ||
| CONFIG="Debug" | ||
| fi | ||
|
|
||
| # TODO: Add this for React Native Core as well | ||
| ##### "$NODE_BINARY" "$REACT_NATIVE_PATH/third-party-podspecs/replace_dependencies_version.js" -c "$CONFIG" -r "#{version}" -p "$PODS_ROOT" | ||
| EOS | ||
| } | ||
|
|
||
|
|
||
| # :always_out_of_date is only available in CocoaPods 1.13.0 and later | ||
| if Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.13.0') | ||
| # always run the script without warning | ||
| script_phase[:always_out_of_date] = "1" | ||
| end | ||
|
|
||
| spec.script_phase = script_phase | ||
| end | ||
|
|
||
| end | ||
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,219 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # | ||
| # This source code is licensed under the MIT license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| require "json" | ||
| require 'net/http' | ||
| require 'rexml/document' | ||
|
|
||
| require_relative './utils.rb' | ||
|
|
||
| ## - RCT_USE_PREBUILT_RNCORE: If set to 1, it will use the release tarball from Maven instead of building from source. | ||
| ## - RCT_USE_LOCAL_RNCORE: **TEST ONLY** If set, it will use a local tarball of RNCore if it exists. | ||
| ## - RCT_RNCORE_VERSION: **TEST ONLY** If set, it will override the version of RNCore to be used. | ||
|
|
||
| class ReactNativeCoreUtils | ||
| @@build_from_source = true | ||
| @@react_native_path = "" | ||
| @@react_native_version = "" | ||
| @@use_nightly = false | ||
|
|
||
| ## Sets up wether ReactNative Core should be built from source or not. | ||
| ## If RCT_USE_PREBUILT_RNCORE is set to 1 and the artifacts exists on Maven, it will | ||
| ## not build from source. Otherwise, it will build from source. | ||
| def self.setup_rncore(react_native_path, react_native_version) | ||
| # We don't want setup to be called multiple times, so we check if the variables are already set. | ||
| if @@react_native_version == "" | ||
| rncore_log("Setting up ReactNativeCore...") | ||
| @@react_native_path = react_native_path | ||
| @@react_native_version = ENV["RCT_RNCORE_VERSION"] == nil ? react_native_version : ENV["RCT_RNCORE_VERSION"] | ||
|
|
||
| if @@react_native_version.include? 'nightly' | ||
| @@use_nightly = true | ||
| if ENV["RCT_RNCORE_VERSION"] == "nightly" | ||
| @@react_native_version = ReactNativeDependenciesUtils.get_nightly_npm_version() | ||
| rncore_log("Using nightly version from npm: #{@@react_native_version}") | ||
| else | ||
| rncore_log("Using nightly build #{@@react_native_version}") | ||
| end | ||
| end | ||
|
|
||
| artifacts_exists = ENV["RCT_USE_PREBUILT_RNCORE"] == "1" && (@@use_nightly ? nightly_artifact_exists(@@react_native_version) : release_artifact_exists(@@react_native_version)) | ||
|
cipolleschi marked this conversation as resolved.
Outdated
|
||
| use_local_xcframework = ENV["RCT_USE_LOCAL_RNCORE"] && File.exist?(ENV["RCT_USE_LOCAL_RNCORE"]) | ||
|
|
||
| if ENV["RCT_USE_LOCAL_RNCORE"] | ||
| if !File.exist?(ENV["RCT_USE_LOCAL_RNCORE"]) | ||
| abort("RCT_USE_LOCAL_RNCORE is set to #{ENV["RCT_USE_LOCAL_RNCORE"]} but the file does not exist!") | ||
| end | ||
| end | ||
|
|
||
| @@build_from_source = !use_local_xcframework && !artifacts_exists | ||
|
|
||
| if @@build_from_source && ENV["RCT_USE_LOCAL_RNCORE"] && !use_local_xcframework | ||
| rncore_log("No local xcframework found, reverting to building from source.") | ||
| end | ||
| if @@build_from_source && ENV["RCT_USE_PREBUILT_RNCORE"] && !artifacts_exists | ||
| rncore_log("No prebuilt artifacts found, reverting to building from source.") | ||
| end | ||
| rncore_log("Building from source: #{@@build_from_source}") | ||
| rncore_log("Source: #{self.resolve_podspec_source()}") | ||
| end | ||
| end | ||
|
|
||
| def self.build_rncore_from_source() | ||
| return @@build_from_source | ||
| end | ||
|
|
||
| def self.resolve_podspec_source() | ||
| if ENV["RCT_USE_LOCAL_RNCORE"] | ||
| if !File.exist?(ENV["RCT_USE_LOCAL_RNCORE"]) | ||
| abort("RCT_USE_LOCAL_RNCORE is set to #{ENV["RCT_USE_LOCAL_RNCORE"]} but the file does not exist in the current directory (#{Dir.pwd}).") | ||
| end | ||
|
cipolleschi marked this conversation as resolved.
Outdated
|
||
| rncore_log("Using local xcframework at #{ENV["RCT_USE_LOCAL_RNCORE"]}") | ||
| return {:http => "file://#{ENV["RCT_USE_LOCAL_RNCORE"]}" } | ||
| end | ||
|
|
||
| if ENV["RCT_USE_PREBUILT_RNCORE"] && ENV["RCT_USE_PREBUILT_RNCORE"] == "1" | ||
|
cipolleschi marked this conversation as resolved.
Outdated
|
||
| if @@use_nightly | ||
| rncore_log("Using nightly tarball") | ||
| begin | ||
| return self.podspec_source_download_prebuilt_nightly_tarball(@@react_native_version) | ||
| rescue => e | ||
| rncore_log("Failed to download nightly tarball: #{e.message}", :error) | ||
| return | ||
| end | ||
| end | ||
|
|
||
| begin | ||
| return self.podspec_source_download_prebuild_release_tarball() | ||
| rescue => e | ||
| rncore_log("Failed to download release tarball: #{e.message}", :error) | ||
| return | ||
| end | ||
| end | ||
|
|
||
| end | ||
|
|
||
| def self.podspec_source_download_prebuild_release_tarball() | ||
| # Warn if @@react_native_path is not set | ||
| if @@react_native_path == "" | ||
| rncore_log("react_native_path is not set", :error) | ||
| return | ||
| end | ||
|
|
||
| # Warn if @@react_native_version is not set | ||
| if @@react_native_version == "" | ||
| rncore_log("react_native_version is not set", :error) | ||
| return | ||
| end | ||
|
|
||
| if @@build_from_source | ||
| return | ||
| end | ||
|
|
||
| url = release_tarball_url(@@react_native_version, :debug) | ||
|
cipolleschi marked this conversation as resolved.
Outdated
|
||
| rncore_log("Using tarball from URL: #{url}") | ||
| download_stable_rndeps(@@react_native_path, @@react_native_version, :debug) | ||
| download_stable_rndeps(@@react_native_path, @@react_native_version, :release) | ||
| return {:http => url} | ||
| end | ||
|
|
||
| def self.release_tarball_url(version, build_type) | ||
|
cipolleschi marked this conversation as resolved.
Outdated
|
||
| maven_repo_url = "https://repo1.maven.org/maven2" | ||
| group = "com/facebook/react" | ||
| # Sample url from Maven: | ||
| return "#{maven_repo_url}/#{group}/react-native-artifacts/#{version}/react-native-artifacts-#{version}-reactnative-core-debug.tar.gz-#{build_type.to_s}.tar.gz" | ||
| end | ||
|
|
||
| def self.nightly_tarball_url(version) | ||
| artefact_coordinate = "react-native-artifacts" | ||
| artefact_name = "reactnative-core-debug.tar.gz" | ||
| xml_url = "https://central.sonatype.com/repository/maven-snapshots/com/facebook/react/#{artefact_coordinate}/#{version}-SNAPSHOT/maven-metadata.xml" | ||
|
|
||
| xml = REXML::Document.new(Net::HTTP.get(URI(xml_url))) | ||
|
cipolleschi marked this conversation as resolved.
Outdated
|
||
| timestamp = xml.elements['metadata/versioning/snapshot/timestamp'].text | ||
| build_number = xml.elements['metadata/versioning/snapshot/buildNumber'].text | ||
| full_version = "#{version}-#{timestamp}-#{build_number}" | ||
|
|
||
| final_url = "https://central.sonatype.com/repository/maven-snapshots/com/facebook/react/#{artefact_coordinate}/#{version}-SNAPSHOT/#{artefact_coordinate}-#{full_version}-#{artefact_name}" | ||
| return final_url | ||
| end | ||
|
|
||
| def self.download_stable_rndeps(react_native_path, version, configuration) | ||
| tarball_url = release_tarball_url(version, configuration) | ||
| download_rndeps_tarball(react_native_path, tarball_url, version, configuration) | ||
| end | ||
|
|
||
| def self.podspec_source_download_prebuilt_nightly_tarball(version) | ||
| url = nightly_tarball_url(version) | ||
| rncore_log("Using nightly tarball from URL: #{url}") | ||
| return {:http => url} | ||
| end | ||
|
|
||
| def self.download_rndeps_tarball(react_native_path, tarball_url, version, configuration) | ||
| destination_path = configuration == nil ? | ||
| "#{artifacts_dir()}/reactnative-core-debug.tar.gz-#{version}.tar.gz" : | ||
| "#{artifacts_dir()}/reactnative-core-debug.tar.gz-#{version}-#{configuration}.tar.gz" | ||
|
|
||
| unless File.exist?(destination_path) | ||
| # Download to a temporary file first so we don't cache incomplete downloads. | ||
| tmp_file = "#{artifacts_dir()}/reactnative-core-debug.tar.gz.download" | ||
| `mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"` | ||
| end | ||
|
|
||
| return destination_path | ||
| end | ||
|
|
||
| def self.release_artifact_exists(version) | ||
| return artifact_exists(release_tarball_url(version, :debug)) | ||
| end | ||
|
|
||
| def self.nightly_artifact_exists(version) | ||
| return artifact_exists(nightly_tarball_url(version).gsub("\\", "")) | ||
| end | ||
|
|
||
| def self.artifacts_dir() | ||
| return File.join(Pod::Config.instance.project_pods_root, "ReactNativeCore-artifacts") | ||
| end | ||
|
|
||
| # This function checks that ReactNativeCore artifact exists on the maven repo | ||
| def self.artifact_exists(tarball_url) | ||
| # -L is used to follow redirects, useful for the nightlies | ||
| # I also needed to wrap the url in quotes to avoid escaping & and ?. | ||
| return (`curl -o /dev/null --silent -Iw '%{http_code}' -L "#{tarball_url}"` == "200") | ||
| end | ||
|
|
||
| def self.resolve_url_redirects(url) | ||
| return (`curl -Ls -o /dev/null -w %{url_effective} \"#{url}\"`) | ||
| end | ||
|
cipolleschi marked this conversation as resolved.
Outdated
|
||
|
|
||
| def self.rncore_log(message, level = :info) | ||
| if !Object.const_defined?("Pod::UI") | ||
| return | ||
| end | ||
| log_message = '[ReactNativeCore] ' + message | ||
| case level | ||
| when :info | ||
| Pod::UI.puts log_message.green | ||
| when :error | ||
| Pod::UI.puts log_message.red | ||
| else | ||
| Pod::UI.puts log_message.yellow | ||
| end | ||
| end | ||
|
|
||
| def self.get_nightly_npm_version() | ||
| uri = URI('https://registry.npmjs.org/react-native/nightly') | ||
| response = Net::HTTP.get_response(uri) | ||
|
|
||
| unless response.is_a?(Net::HTTPSuccess) | ||
| raise "Couldn't get an answer from NPM: #{response.code} #{response.message}" | ||
| end | ||
|
|
||
| json = JSON.parse(response.body) | ||
| latest_nightly = json['version'] | ||
| return latest_nightly | ||
| end | ||
|
|
||
| end | ||
Oops, something went wrong.
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.