@@ -261,51 +261,59 @@ if ("1".equals(shouldRebuildNativeModules)) {
261
261
String temp_cc_ver = ' 4.9' ;
262
262
String temp_dest_cpu;
263
263
String temp_v8_arch;
264
- String temp_suffix ;
265
- String temp_toolchain_name ;
264
+ String temp_binutils_prefix ;
265
+ String temp_compiler_prefix ;
266
266
String cargo_build_target;
267
267
switch ( temp_arch )
268
268
{
269
269
case ' arm' :
270
270
temp_dest_cpu = " ${ temp_arch} "
271
271
temp_v8_arch = " ${ temp_arch} "
272
- temp_suffix = " ${ temp_arch } -linux-androideabi"
273
- temp_toolchain_name = " ${ temp_suffix } "
272
+ temp_binutils_prefix = " arm -linux-androideabi"
273
+ temp_compiler_prefix = " armv7a-linux-androideabi ${ _compileNativeModulesSdkVersion } "
274
274
cargo_build_target = ' arm-linux-androideabi'
275
275
break
276
276
case ' x86' :
277
277
temp_dest_cpu = ' ia32'
278
278
temp_v8_arch = ' ia32'
279
- temp_suffix = ' i686-linux-android'
280
- temp_toolchain_name = " ${ temp_arch } "
281
- cargo_build_target = temp_suffix
279
+ temp_binutils_prefix = " i686-linux-android"
280
+ temp_compiler_prefix = " i686-linux-android ${ _compileNativeModulesSdkVersion } "
281
+ cargo_build_target = " i686-linux-android "
282
282
break
283
283
case ' x86_64' :
284
284
temp_dest_cpu = ' x64'
285
285
temp_v8_arch = ' x64'
286
- temp_suffix = " ${ temp_arch } -linux-android"
287
- temp_toolchain_name = " ${ temp_arch } "
288
- cargo_build_target = temp_suffix
286
+ temp_binutils_prefix = " x86_64 -linux-android"
287
+ temp_compiler_prefix = " x86_64-linux-android ${ _compileNativeModulesSdkVersion } "
288
+ cargo_build_target = " x86_64-linux-android "
289
289
break
290
290
case ' arm64' :
291
291
temp_dest_cpu = " ${ temp_arch} "
292
292
temp_v8_arch = " ${ temp_arch} "
293
- temp_suffix = ' aarch64-linux-android'
294
- temp_toolchain_name = ' aarch64'
295
- cargo_build_target = temp_suffix
293
+ temp_binutils_prefix = " aarch64-linux-android"
294
+ temp_compiler_prefix = " aarch64-linux-android ${ _compileNativeModulesSdkVersion } "
295
+ cargo_build_target = " aarch64-linux-android "
296
296
break
297
297
default :
298
298
throw new GradleException (" Unsupported architecture for nodejs-mobile native modules: ${ temp_arch} " )
299
299
break
300
300
}
301
301
302
+ String temp_host_tag
303
+ if (OperatingSystem . current(). isMacOsX()) {
304
+ temp_host_tag = ' darwin-x86_64'
305
+ } else if (OperatingSystem . current(). isLinux()) {
306
+ temp_host_tag = ' linux-x86_64'
307
+ } else {
308
+ throw new GradleException (" Unsupported operating system for nodejs-mobile native builds: ${ OperatingSystem.current().getName()} " )
309
+ }
310
+
302
311
String ndk_bundle_path = android. ndkDirectory
303
- String standalone_toolchain = " ${ rootProject.buildDir} /standalone-toolchains/${ temp_toolchain_name} "
304
- String npm_toolchain_add_to_path = " ${ rootProject.buildDir} /bin"
305
- String npm_toolchain_ar = " ${ standalone_toolchain} /bin/${ temp_suffix} -ar"
306
- String npm_toolchain_cc = " ${ standalone_toolchain} /bin/${ temp_suffix} -clang"
307
- String npm_toolchain_cxx = " ${ standalone_toolchain} /bin/${ temp_suffix} -clang++"
308
- String npm_toolchain_link = " ${ standalone_toolchain} /bin/${ temp_suffix} -clang++"
312
+ String toolchain_path = " ${ ndk_bundle_path} /toolchains/llvm/prebuilt/${ temp_host_tag} "
313
+ String npm_toolchain_ar = " ${ toolchain_path} /bin/${ temp_binutils_prefix} -ar"
314
+ String npm_toolchain_cc = " ${ toolchain_path} /bin/${ temp_compiler_prefix} -clang"
315
+ String npm_toolchain_cxx = " ${ toolchain_path} /bin/${ temp_compiler_prefix} -clang++"
316
+ String npm_toolchain_link = " ${ toolchain_path} /bin/${ temp_compiler_prefix} -clang++"
309
317
String cargo_target_triple = cargo_build_target. toUpperCase(). replaceAll(' -' , ' _' )
310
318
311
319
String npm_gyp_defines = " target_arch=${ temp_arch} "
@@ -358,16 +366,8 @@ if ("1".equals(shouldRebuildNativeModules)) {
358
366
}
359
367
}
360
368
361
- task " MakeToolchain${ abi_name} " (type :Exec ) {
362
- description = " Building a native toolchain to compile nodejs-mobile native modules for ${ abi_name} ."
363
- executable = " ${ ndk_bundle_path} /build/tools/make-standalone-toolchain.sh"
364
- args " --toolchain=${ temp_toolchain_name} -${ temp_cc_ver} " , " --arch=${ temp_arch} " , " --install-dir=${ standalone_toolchain} " , " --stl=libc++" , " --force" , " --platform=android-${ _compileNativeModulesSdkVersion} "
365
- outputs. dir " ${ standalone_toolchain} "
366
- }
367
-
368
369
task " BuildNpmModules${ abi_name} " (type :Exec ) {
369
370
dependsOn " CopyNodeProjectAssets${ abi_name} "
370
- dependsOn " MakeToolchain${ abi_name} "
371
371
description = " Building native modules for ${ abi_name} ."
372
372
inputs. file " ${ rootProject.buildDir} /nodejs-native-assets-temp-build/nodejs-native-assets-${ abi_name} /copy.timestamp"
373
373
outputs. dir " ${ rootProject.buildDir} /nodejs-native-assets-temp-build/nodejs-native-assets-${ abi_name} /nodejs-project/"
@@ -398,7 +398,7 @@ if ("1".equals(shouldRebuildNativeModules)) {
398
398
environment (" CARGO_TARGET_${ cargo_target_triple} _AR" , " ${ npm_toolchain_ar} " )
399
399
environment (" CARGO_TARGET_${ cargo_target_triple} _LINKER" , " ${ npm_toolchain_link} " )
400
400
401
- environment (' TOOLCHAIN' ," ${ standalone_toolchain } " )
401
+ environment (' TOOLCHAIN' ," ${ toolchain_path } " )
402
402
environment (' AR' ," ${ npm_toolchain_ar} " )
403
403
environment (' CC' ," ${ npm_toolchain_cc} " )
404
404
environment (' CXX' ," ${ npm_toolchain_cxx} " )
0 commit comments