Skip to content

Commit 8d2cb35

Browse files
authored
android: use prebuilt toolchain for native modules
1 parent 2b57062 commit 8d2cb35

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

android/build.gradle

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -261,51 +261,59 @@ if ("1".equals(shouldRebuildNativeModules)) {
261261
String temp_cc_ver = '4.9';
262262
String temp_dest_cpu;
263263
String temp_v8_arch;
264-
String temp_suffix;
265-
String temp_toolchain_name;
264+
String temp_binutils_prefix;
265+
String temp_compiler_prefix;
266266
String cargo_build_target;
267267
switch ( temp_arch )
268268
{
269269
case 'arm':
270270
temp_dest_cpu = "${temp_arch}"
271271
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}"
274274
cargo_build_target = 'arm-linux-androideabi'
275275
break
276276
case 'x86':
277277
temp_dest_cpu = 'ia32'
278278
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"
282282
break
283283
case 'x86_64':
284284
temp_dest_cpu = 'x64'
285285
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"
289289
break
290290
case 'arm64':
291291
temp_dest_cpu = "${temp_arch}"
292292
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"
296296
break
297297
default:
298298
throw new GradleException("Unsupported architecture for nodejs-mobile native modules: ${temp_arch}")
299299
break
300300
}
301301

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+
302311
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++"
309317
String cargo_target_triple = cargo_build_target.toUpperCase().replaceAll('-', '_')
310318

311319
String npm_gyp_defines = "target_arch=${temp_arch}"
@@ -358,16 +366,8 @@ if ("1".equals(shouldRebuildNativeModules)) {
358366
}
359367
}
360368

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-
368369
task "BuildNpmModules${abi_name}" (type:Exec) {
369370
dependsOn "CopyNodeProjectAssets${abi_name}"
370-
dependsOn "MakeToolchain${abi_name}"
371371
description = "Building native modules for ${abi_name}."
372372
inputs.file "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/copy.timestamp"
373373
outputs.dir "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/nodejs-project/"
@@ -398,7 +398,7 @@ if ("1".equals(shouldRebuildNativeModules)) {
398398
environment ("CARGO_TARGET_${cargo_target_triple}_AR", "${npm_toolchain_ar}")
399399
environment ("CARGO_TARGET_${cargo_target_triple}_LINKER", "${npm_toolchain_link}")
400400

401-
environment ('TOOLCHAIN',"${standalone_toolchain}")
401+
environment ('TOOLCHAIN',"${toolchain_path}")
402402
environment ('AR',"${npm_toolchain_ar}")
403403
environment ('CC',"${npm_toolchain_cc}")
404404
environment ('CXX',"${npm_toolchain_cxx}")

0 commit comments

Comments
 (0)