Skip to content

Commit

Permalink
Add .xcode.env file with dynamic node binary path
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Jul 5, 2023
1 parent 73249ba commit bdd6ab1
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 14 deletions.
3 changes: 0 additions & 3 deletions ios-xcframework/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ fastlane/report.xml
# XCFramework build process intermediate and output artifacts
build

# This is generated by the `pod install` process.
# It is required by FBReactNativeSpec to compile in case `command -v node` does not give a result from within Xcode.
.xcode.env
# This file takes precedence over .xcode.env.
# Developers can use it to set a custom value without having to update .xcode.env after every `pod install`
.xcode.env.local
1 change: 1 addition & 0 deletions ios-xcframework/.xcode.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export NODE_BINARY=$(command -v node)
10 changes: 0 additions & 10 deletions ios-xcframework/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,4 @@ post_install do |installer|
configuration.build_settings.delete(IOS_VERSION_KEY) if pod_ios_deployment_target <= APP_IOS_DEPLOYMENT_TARGET
end
end

# This is to work around FBReactNativeSpec not finding Node.
#
# gutenberg-mobile/ios-xcframework/Pods/../../gutenberg/node_modules/react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh: line 35: .xcode.env: command not found
# [...]
# [Warning] You need to configure your node path in the environment. You can set it up quickly by running: echo 'export NODE_BINARY=' > .xcode.env in the ios folder. This is needed by React Native to work correctly. [...]
#
node_path = `command -v node`.strip
`echo 'export NODE_BINARY=#{node_path}' > .xcode.env`
puts "[Gutenberg] Generated .xcode.env file with NODE_BINARY=#{node_path}. You can override that value by creating a .xcode.env.local version."
end
2 changes: 1 addition & 1 deletion ios-xcframework/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,6 @@ SPEC CHECKSUMS:
WordPress-Aztec-iOS: 7d11d598f14c82c727c08b56bd35fbeb7dafb504
Yoga: f7decafdc5e8c125e6fa0da38a687e35238420fa

PODFILE CHECKSUM: a8dafa1cc910bd501726c27e1574de887526d588
PODFILE CHECKSUM: 5a5f2008f26d2a39dce2f914fe0da4d8ea348cba

COCOAPODS: 1.12.1

3 comments on commit bdd6ab1

@mokagio
Copy link
Contributor

@mokagio mokagio commented on bdd6ab1 Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... At the time, I was surprised by facing the need to generate the file at runtime by hardcoding the path to node rather than relying on command -v node to compute it.

I did that because, despited having the file like this, Xcode was failing to build for me. I added some logs in the script that RN calls to read that file and verified it was because the exported env var was empty.

On my machine, this still seems to be happening. Notice the lack of a version in the export NODE_BINARY= suggestion. Looking at the source for that message in React Native, it's clear that command -v node returns an empty value in my setup (despite, of course, working when run on the Terminal)

image

Thankfully, React Native's fallback logic to find the Node version worked this time around, and the build proceeded successfully. (There's a bit of red in the screenshot, but it's due to a different unrelated error that had to do with a dirty local cache)

@fluiddot
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, I haven't checked to build the XCFramework using Xcode, but I understand I might encounter a similar issue. So far, all the tests I made were in the terminal.

As mentioned here, we follow the same approach in the Gutenberg demo app, so I understand it should also work for this case. In the worst case, we could use the .xcode.env.local file to explicitly define the node path.

@mokagio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the worst case, we could use the .xcode.env.local file to explicitly define the node path.

Sounds good. Let's see if any problem reveals itself down the track

Please sign in to comment.