@@ -14,6 +14,10 @@ import {
1414 isAppleTarget ,
1515} from "./targets.js" ;
1616
17+ const WEAK_NODE_API_PATH = new URL (
18+ import . meta. resolve ( "react-native-node-api-modules/weak-node-api" )
19+ ) . pathname ;
20+
1721const APPLE_XCFRAMEWORK_CHILDS_PER_TARGET : Record < AppleTargetName , string > = {
1822 "aarch64-apple-darwin" : "macos-arm64_x86_64" , // Universal
1923 "x86_64-apple-darwin" : "macos-arm64_x86_64" , // Universal
@@ -28,6 +32,13 @@ const APPLE_XCFRAMEWORK_CHILDS_PER_TARGET: Record<AppleTargetName, string> = {
2832 // "aarch64-apple-visionos-sim": "xros-arm64-simulator",
2933} ;
3034
35+ const ANDROID_ARCH_PR_TARGET : Record < AndroidTargetName , string > = {
36+ "aarch64-linux-android" : "arm64-v8a" ,
37+ "armv7-linux-androideabi" : "armeabi-v7a" ,
38+ "i686-linux-android" : "x86" ,
39+ "x86_64-linux-android" : "x86_64" ,
40+ } ;
41+
3142export function joinPathAndAssertExistence ( ...pathSegments : string [ ] ) {
3243 const joinedPath = path . join ( ...pathSegments ) ;
3344 assert ( fs . existsSync ( joinedPath ) , `Expected ${ joinedPath } to exist` ) ;
@@ -114,17 +125,23 @@ export function getTargetAndroidPlatform(target: AndroidTargetName) {
114125}
115126
116127export function getWeakNodeApiFrameworkPath ( target : AppleTargetName ) {
117- const weakNodeApiPath = new URL (
118- import . meta. resolve ( "react-native-node-api-modules/weak-node-api" )
119- ) . pathname ;
120- assert ( fs . existsSync ( weakNodeApiPath ) , "Expected weak-node-api to exist" ) ;
128+ assert ( fs . existsSync ( WEAK_NODE_API_PATH ) , "Expected weak-node-api to exist" ) ;
121129 return joinPathAndAssertExistence (
122- weakNodeApiPath ,
130+ WEAK_NODE_API_PATH ,
123131 "libweak-node-api.xcframework" ,
124132 APPLE_XCFRAMEWORK_CHILDS_PER_TARGET [ target ]
125133 ) ;
126134}
127135
136+ export function getWeakNodeApiAndroidLibraryPath ( target : AndroidTargetName ) {
137+ assert ( fs . existsSync ( WEAK_NODE_API_PATH ) , "Expected weak-node-api to exist" ) ;
138+ return joinPathAndAssertExistence (
139+ WEAK_NODE_API_PATH ,
140+ "libweak-node-api.android.node" ,
141+ ANDROID_ARCH_PR_TARGET [ target ]
142+ ) ;
143+ }
144+
128145export function getTargetEnvironmentVariables ( {
129146 target,
130147 ndkVersion,
@@ -149,8 +166,10 @@ export function getTargetEnvironmentVariables({
149166 const toolchainBinPath = getLLVMToolchainBinPath ( ndkPath ) ;
150167 const targetArch = getTargetAndroidArch ( target ) ;
151168 const targetPlatform = getTargetAndroidPlatform ( target ) ;
169+ const weakNodeApiPath = getWeakNodeApiAndroidLibraryPath ( target ) ;
152170
153171 return {
172+ RUSTFLAGS : `-L ${ weakNodeApiPath } -l weak-node-api` ,
154173 CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER : joinPathAndAssertExistence (
155174 toolchainBinPath ,
156175 `aarch64-linux-android${ androidApiLevel } -clang`
0 commit comments