Skip to content

Commit

Permalink
android: rust cargo build environment variables
Browse files Browse the repository at this point in the history
Adds rust cargo build environment variables to build.gradle

PR-URL: #10
Reviewed-By: Jaime Bernardo <jaime@janeasystems.com>
  • Loading branch information
stoically authored and jaimecbernardo committed Oct 30, 2019
1 parent cf4c909 commit b12b309
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -249,31 +249,36 @@ if ("1".equals(shouldRebuildNativeModules)) {
String temp_v8_arch;
String temp_suffix;
String temp_toolchain_name;
String cargo_build_target;
switch ( temp_arch )
{
case 'arm':
temp_dest_cpu = "${temp_arch}"
temp_v8_arch = "${temp_arch}"
temp_suffix = "${temp_arch}-linux-androideabi"
temp_toolchain_name = "${temp_suffix}"
cargo_build_target = 'arm-linux-androideabi'
break
case 'x86':
temp_dest_cpu = 'ia32'
temp_v8_arch = 'ia32'
temp_suffix = 'i686-linux-android'
temp_toolchain_name = "${temp_arch}"
cargo_build_target = temp_suffix
break
case 'x86_64':
temp_dest_cpu = 'x64'
temp_v8_arch = 'x64'
temp_suffix = "${temp_arch}-linux-android"
temp_toolchain_name = "${temp_arch}"
cargo_build_target = temp_suffix
break
case 'arm64':
temp_dest_cpu = "${temp_arch}"
temp_v8_arch = "${temp_arch}"
temp_suffix = 'aarch64-linux-android'
temp_toolchain_name = 'aarch64'
cargo_build_target = temp_suffix
break
default:
throw new GradleException("Unsupported architecture for nodejs-mobile native modules: ${temp_arch}")
Expand All @@ -287,6 +292,7 @@ if ("1".equals(shouldRebuildNativeModules)) {
String npm_toolchain_cc = "${standalone_toolchain}/bin/${temp_suffix}-clang"
String npm_toolchain_cxx = "${standalone_toolchain}/bin/${temp_suffix}-clang++"
String npm_toolchain_link = "${standalone_toolchain}/bin/${temp_suffix}-clang++"
String cargo_target_triple = cargo_build_target.toUpperCase().replaceAll('-', '_')

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

environment ('CARGO_BUILD_TARGET', "${cargo_build_target}")
environment ("CARGO_TARGET_${cargo_target_triple}_AR", "${npm_toolchain_ar}")
environment ("CARGO_TARGET_${cargo_target_triple}_LINKER", "${npm_toolchain_link}")

environment ('TOOLCHAIN',"${standalone_toolchain}")
environment ('AR',"${npm_toolchain_ar}")
environment ('CC',"${npm_toolchain_cc}")
Expand Down

0 comments on commit b12b309

Please sign in to comment.