Skip to content

Commit 80ae73b

Browse files
authored
Apple link without cocoapods (#351)
* Add dependencies and xcode helpers * Add command to patch xcode project * Copy and sign framework from xcode build phase * Remove incremental linking * Use bufferred output when converting plists to xml * Updated determineFrameworkSlice * Add changeset * Cleaning up * Fix lint issues * Fixing tests * Patch all application targets * Disregard CODE_SIGNING_REQUIRED when deciding to sign * Re-use existing build phase * Add check for "macos" when traversing FS for an xcode workspace * Use NODE_BINARY and read it off the environment * Use assignment instead of ||= operator now that it's gated by exit_hooks_installed
1 parent 81e91b9 commit 80ae73b

File tree

13 files changed

+565
-140
lines changed

13 files changed

+565
-140
lines changed

.changeset/social-peaches-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-node-api": minor
3+
---
4+
5+
Modify Xcode project to add a build phase to the main project app to link Node-API frameworks directly

package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/host/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"include",
3636
"babel-plugin.js",
3737
"scripts/patch-hermes.rb",
38+
"scripts/patch-xcode-project.rb",
3839
"weak-node-api/**",
3940
"!weak-node-api/build/",
4041
"*.js",
@@ -67,7 +68,9 @@
6768
],
6869
"license": "MIT",
6970
"dependencies": {
71+
"@bacons/xcode": "^1.0.0-alpha.29",
7072
"@expo/plist": "^0.4.7",
73+
"@xmldom/xmldom": "^0.8.11",
7174
"@react-native-node-api/cli-utils": "0.1.4",
7275
"pkg-dir": "^8.0.0",
7376
"read-pkg": "^9.0.1",

packages/host/react-native-node-api.podspec

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,7 @@ require "json"
33
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
44

55
require_relative "./scripts/patch-hermes"
6-
7-
NODE_PATH ||= `which node`.strip
8-
CLI_COMMAND ||= "'#{NODE_PATH}' '#{File.join(__dir__, "dist/node/cli/run.js")}'"
9-
COPY_FRAMEWORKS_COMMAND ||= "#{CLI_COMMAND} link --apple '#{Pod::Config.instance.installation_root}'"
10-
11-
# We need to run this now to ensure the xcframeworks are copied vendored_frameworks are considered
12-
XCFRAMEWORKS_DIR ||= File.join(__dir__, "xcframeworks")
13-
unless defined?(@xcframeworks_copied)
14-
puts "Executing #{COPY_FRAMEWORKS_COMMAND}"
15-
system(COPY_FRAMEWORKS_COMMAND) or raise "Failed to copy xcframeworks"
16-
# Setting a flag to avoid running this command on every require
17-
@xcframeworks_copied = true
18-
end
6+
require_relative "./scripts/patch-xcode-project"
197

208
if ENV['RCT_NEW_ARCH_ENABLED'] == '0'
219
Pod::UI.warn "React Native Node-API doesn't support the legacy architecture (but RCT_NEW_ARCH_ENABLED == '0')"
@@ -35,16 +23,6 @@ Pod::Spec.new do |s|
3523

3624
s.dependency "weak-node-api"
3725

38-
s.vendored_frameworks = "auto-linked/apple/*.xcframework"
39-
s.script_phase = {
40-
:name => 'Copy Node-API xcframeworks',
41-
:execution_position => :before_compile,
42-
:script => <<-CMD
43-
set -e
44-
#{COPY_FRAMEWORKS_COMMAND}
45-
CMD
46-
}
47-
4826
# Use install_modules_dependencies helper to install the dependencies (requires React Native version >=0.71.0).
4927
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
5028
if respond_to?(:install_modules_dependencies, true)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
unless defined?(@exit_hooks_installed)
2+
# Setting a flag to avoid running this command on every require
3+
@exit_hooks_installed = true
4+
5+
NODE_BINARY = ENV["NODE_BINARY"] || `command -v node`.strip
6+
CLI_COMMAND = "'#{NODE_BINARY}' '#{File.join(__dir__, "../dist/node/cli/run.js")}'"
7+
PATCH_XCODE_PROJECT_COMMAND = "#{CLI_COMMAND} patch-xcode-project '#{Pod::Config.instance.installation_root}'"
8+
9+
# Using an at_exit hook to ensure the command is executed after the pod install is complete
10+
at_exit do
11+
system(PATCH_XCODE_PROJECT_COMMAND) or raise "Failed to patch the Xcode project"
12+
end
13+
end

packages/host/src/node/cli/android.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
22
import fs from "node:fs";
33
import path from "node:path";
44

5-
import { getLatestMtime, getLibraryName, MAGIC_FILENAME } from "../path-utils";
5+
import { getLibraryName, MAGIC_FILENAME } from "../path-utils";
66
import {
77
getLinkedModuleOutputPath,
88
LinkModuleResult,
@@ -17,26 +17,11 @@ const ANDROID_ARCHITECTURES = [
1717
] as const;
1818

1919
export async function linkAndroidDir({
20-
incremental,
2120
modulePath,
2221
naming,
23-
platform,
2422
}: LinkModuleOptions): Promise<LinkModuleResult> {
2523
const libraryName = getLibraryName(modulePath, naming);
26-
const outputPath = getLinkedModuleOutputPath(platform, modulePath, naming);
27-
28-
if (incremental && fs.existsSync(outputPath)) {
29-
const moduleModified = getLatestMtime(modulePath);
30-
const outputModified = getLatestMtime(outputPath);
31-
if (moduleModified < outputModified) {
32-
return {
33-
originalPath: modulePath,
34-
libraryName,
35-
outputPath,
36-
skipped: true,
37-
};
38-
}
39-
}
24+
const outputPath = getLinkedModuleOutputPath("android", modulePath, naming);
4025

4126
await fs.promises.rm(outputPath, { recursive: true, force: true });
4227
await fs.promises.cp(modulePath, outputPath, { recursive: true });

0 commit comments

Comments
 (0)