Skip to content

Commit

Permalink
Ensure codegen runs at Xcode buildtime (#30449)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #30449

Changelog:

Differential Revision: D25138896

fbshipit-source-id: be930cf9149803eac8b633b380f1ca7962049662
  • Loading branch information
hramos authored and facebook-github-bot committed Dec 1, 2020
1 parent ae6f4f3 commit bc0ce39
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 42 deletions.
17 changes: 16 additions & 1 deletion Libraries/FBReactNativeSpec/FBReactNativeSpec.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json")))
version = package['version']

source = { :git => 'https://github.com/facebook/react-native.git' }
codegenPathPrefix = File.join("..", "node_modules")
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
source[:commit] = `git rev-parse HEAD`.strip
codegenPathPrefix = "packages"
else
source[:tag] = "v#{version}"
end

reactNativePath = File.join(__dir__, "..", "..")
codegenScriptPath = File.join(reactNativePath, "scripts", "codegen-native-modules.rb")
codegenPath = File.join(reactNativePath, codegenPathPrefix, "react-native-codegen")
codegenCommand = "CODEGEN_PATH=#{codegenPath} ruby '#{codegenScriptPath}'"

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
folly_version = '2020.01.13.00'

Expand All @@ -29,7 +36,7 @@ Pod::Spec.new do |s|
s.platforms = { :ios => "10.0" }
s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness'
s.source = source
s.source_files = "**/*.{c,h,m,mm,cpp}"
s.source_files = "FBReactNativeSpec/FBReactNativeSpec.h", "FBReactNativeSpec/FBReactNativeSpec-generated.mm"
s.header_dir = "FBReactNativeSpec"

s.pod_target_xcconfig = {
Expand All @@ -44,4 +51,12 @@ Pod::Spec.new do |s|
s.dependency "React-Core", version
s.dependency "React-jsi", version
s.dependency "ReactCommon/turbomodule/core", version

s.prepare_command = codegenCommand
s.script_phase = {
:name => 'Generate Native Modules Code',
:output_files => ['FBReactNativeSpec/FBReactNativeSpec.h', 'FBReactNativeSpec/FBReactNativeSpec-generated.mm'],
:script => codegenCommand,
:execution_position => :before_compile
}
end
10 changes: 0 additions & 10 deletions packages/rn-tester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ def frameworks_pre_install(installer)
end
end

pre_install do |installer|
frameworks_pre_install(installer) if ENV['USE_FRAMEWORKS'] == '1'
if ENV['USE_CODEGEN'] != '0'
prefix_path = "../.."
codegen_path = "../../packages/react-native-codegen"
system("./#{codegen_path}/scripts/oss/build.sh") or raise "Could not build react-native-codegen package"
codegen_pre_install(installer, {path:prefix_path, codegen_path:codegen_path})
end
end

post_install do |installer|
flipper_post_install(installer)
end
18 changes: 9 additions & 9 deletions packages/rn-tester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ PODS:
- Flipper-Folly (~> 2.2)
- Flipper-RSocket (~> 1.1)
- Flipper-DoubleConversion (1.1.7)
- Flipper-Folly (2.2.0):
- Flipper-Folly (2.3.0):
- boost-for-react-native
- CocoaLibEvent (~> 1.0)
- Flipper-DoubleConversion
- Flipper-Glog
- OpenSSL-Universal (= 1.0.2.19)
- OpenSSL-Universal (= 1.0.2.20)
- Flipper-Glog (0.3.6)
- Flipper-PeerTalk (0.0.4)
- Flipper-RSocket (1.1.0):
Expand Down Expand Up @@ -58,9 +58,9 @@ PODS:
- FlipperKit/Core
- FlipperKit/FlipperKitNetworkPlugin
- glog (0.3.5)
- OpenSSL-Universal (1.0.2.19):
- OpenSSL-Universal/Static (= 1.0.2.19)
- OpenSSL-Universal/Static (1.0.2.19)
- OpenSSL-Universal (1.0.2.20):
- OpenSSL-Universal/Static (= 1.0.2.20)
- OpenSSL-Universal/Static (1.0.2.20)
- RCT-Folly (2020.01.13.00):
- boost-for-react-native
- DoubleConversion
Expand Down Expand Up @@ -490,16 +490,16 @@ SPEC CHECKSUMS:
CocoaLibEvent: 2fab71b8bd46dd33ddb959f7928ec5909f838e3f
DoubleConversion: cde416483dac037923206447da6e1454df403714
FBLazyVector: fe973c09b2299b5e8154186ecf1f6554b4f70987
FBReactNativeSpec: 20a9345af9157362b51ab0258d842cb7bb347d19
FBReactNativeSpec: 5abf6676352b0b7cffaeef981408e4802bda23a2
Flipper: be611d4b742d8c87fbae2ca5f44603a02539e365
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
Flipper-Folly: c12092ea368353b58e992843a990a3225d4533c3
Flipper-Folly: e4493b013c02d9347d5e0cb4d128680239f6c78a
Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7
FlipperKit: ab353d41aea8aae2ea6daaf813e67496642f3d7d
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355
OpenSSL-Universal: ff34003318d5e1163e9529b08470708e389ffcdd
RCT-Folly: b39288cedafe50da43317ec7d91bcc8cc0abbf33
RCTRequired: d3d4ce60e1e2282864d7560340690a3c8c646de1
RCTTypeSafety: 4da4f9f218727257c50fd3bf2683a06cdb4fede3
Expand Down Expand Up @@ -528,6 +528,6 @@ SPEC CHECKSUMS:
Yoga: 69ef0b2bba5387523f793957a9f80dbd61e89631
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: cd671238f92c51cd349a1c778fd089994174b101
PODFILE CHECKSUM: 3adfe268d800503789170d1862bde422ee204fe8

COCOAPODS: 1.10.0
34 changes: 34 additions & 0 deletions scripts/codegen-native-modules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/ruby
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

require 'tmpdir'

# Handle Core Modules
def codegen_core_modules(codegenPath)
reactNativePath = File.join(__dir__, "..")
srcsDir = File.join(reactNativePath, "Libraries")
libraryName = "FBReactNativeSpec"
outputDir = File.join(srcsDir, libraryName, libraryName)

codegen(codegenPath, srcsDir, libraryName, outputDir)
end

def codegen(codegenPath, srcsDir, libraryName, outputDir)
Dir.mktmpdir do |dir|
schemaFilePath = File.join(dir, "schema-#{libraryName}.json")
combineCliPath = File.join(codegenPath, "lib", "cli", "combine", "combine-js-to-schema-cli.js")
generateSpecsCliPath = File.join(__dir__, "generate-native-modules-specs-cli.js")
system("node #{combineCliPath} #{schemaFilePath} #{srcsDir}") or raise "Could not generate Native Module schema"
system("node #{generateSpecsCliPath} ios #{schemaFilePath} #{outputDir} #{libraryName}") or raise "Could not generate code for #{libraryName}"
end
end

def main()
codegenPath = ENV["CODEGEN_PATH"] ||= File.join(reactNativePath, "..", "react-native-codegen")
codegen_core_modules(codegenPath)
end

main()
18 changes: 0 additions & 18 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,3 @@ def flipper_post_install(installer)
end
end
end

# Pre Install processing for Native Modules
def codegen_pre_install(installer, options={})
# Path to React Native
prefix = options[:path] ||= "../node_modules/react-native"

# Path to react-native-codegen
codegen_path = options[:codegen_path] ||= "#{prefix}/../react-native-codegen"

# Handle Core Modules
Dir.mktmpdir do |dir|
native_module_spec_name = "FBReactNativeSpec"
schema_file = dir + "/schema-#{native_module_spec_name}.json"
srcs_dir = "#{prefix}/Libraries"
schema_generated = system("node #{codegen_path}/lib/cli/combine/combine-js-to-schema-cli.js #{schema_file} #{srcs_dir}") or raise "Could not generate Native Module schema"
specs_generated = system("node #{prefix}/scripts/generate-native-modules-specs-cli.js ios #{schema_file} #{srcs_dir}/#{native_module_spec_name}/#{native_module_spec_name}") or raise "Could not generate code for #{native_module_spec_name}"
end
end
4 changes: 0 additions & 4 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ target 'HelloWorld' do
# Pods for testing
end

pre_install do |installer|
codegen_pre_install(installer)
end

# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
Expand Down

0 comments on commit bc0ce39

Please sign in to comment.