Skip to content

Commit b12b309

Browse files
stoicallyjaimecbernardo
authored andcommitted
android: rust cargo build environment variables
Adds rust cargo build environment variables to build.gradle PR-URL: JaneaSystems/nodejs-mobile-react-native#10 Reviewed-By: Jaime Bernardo <[email protected]>
1 parent cf4c909 commit b12b309

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

android/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,31 +249,36 @@ if ("1".equals(shouldRebuildNativeModules)) {
249249
String temp_v8_arch;
250250
String temp_suffix;
251251
String temp_toolchain_name;
252+
String cargo_build_target;
252253
switch ( temp_arch )
253254
{
254255
case 'arm':
255256
temp_dest_cpu = "${temp_arch}"
256257
temp_v8_arch = "${temp_arch}"
257258
temp_suffix = "${temp_arch}-linux-androideabi"
258259
temp_toolchain_name = "${temp_suffix}"
260+
cargo_build_target = 'arm-linux-androideabi'
259261
break
260262
case 'x86':
261263
temp_dest_cpu = 'ia32'
262264
temp_v8_arch = 'ia32'
263265
temp_suffix = 'i686-linux-android'
264266
temp_toolchain_name = "${temp_arch}"
267+
cargo_build_target = temp_suffix
265268
break
266269
case 'x86_64':
267270
temp_dest_cpu = 'x64'
268271
temp_v8_arch = 'x64'
269272
temp_suffix = "${temp_arch}-linux-android"
270273
temp_toolchain_name = "${temp_arch}"
274+
cargo_build_target = temp_suffix
271275
break
272276
case 'arm64':
273277
temp_dest_cpu = "${temp_arch}"
274278
temp_v8_arch = "${temp_arch}"
275279
temp_suffix = 'aarch64-linux-android'
276280
temp_toolchain_name = 'aarch64'
281+
cargo_build_target = temp_suffix
277282
break
278283
default:
279284
throw new GradleException("Unsupported architecture for nodejs-mobile native modules: ${temp_arch}")
@@ -287,6 +292,7 @@ if ("1".equals(shouldRebuildNativeModules)) {
287292
String npm_toolchain_cc = "${standalone_toolchain}/bin/${temp_suffix}-clang"
288293
String npm_toolchain_cxx = "${standalone_toolchain}/bin/${temp_suffix}-clang++"
289294
String npm_toolchain_link = "${standalone_toolchain}/bin/${temp_suffix}-clang++"
295+
String cargo_target_triple = cargo_build_target.toUpperCase().replaceAll('-', '_')
290296

291297
String npm_gyp_defines = "target_arch=${temp_arch}"
292298
npm_gyp_defines += " v8_target_arch=${temp_v8_arch}"
@@ -374,6 +380,10 @@ if ("1".equals(shouldRebuildNativeModules)) {
374380
environment ('PATH', "${original_project_bin}" + System.getProperty("path.separator") + "${System.env.PATH}")
375381
}
376382

383+
environment ('CARGO_BUILD_TARGET', "${cargo_build_target}")
384+
environment ("CARGO_TARGET_${cargo_target_triple}_AR", "${npm_toolchain_ar}")
385+
environment ("CARGO_TARGET_${cargo_target_triple}_LINKER", "${npm_toolchain_link}")
386+
377387
environment ('TOOLCHAIN',"${standalone_toolchain}")
378388
environment ('AR',"${npm_toolchain_ar}")
379389
environment ('CC',"${npm_toolchain_cc}")

0 commit comments

Comments
 (0)