Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion priv/templates/mob.new/android/app/build.gradle.eex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (localPropsFile.exists()) localProps.load(localPropsFile.newDataInputStream()

def mobOtpRelease = localProps.getProperty('mob.otp_release', System.getenv('MOB_ANDROID_OTP_RELEASE') ?: '')
def mobOtpReleaseArm32 = localProps.getProperty('mob.otp_release_arm32', System.getenv('MOB_ANDROID_OTP_RELEASE_ARM32') ?: mobOtpRelease)
def mobOtpReleaseX86_64 = localProps.getProperty('mob.otp_release_x86_64', System.getenv('MOB_ANDROID_OTP_RELEASE_X86_64') ?: mobOtpRelease)
def mobDir = localProps.getProperty('mob.mob_dir', System.getenv('MOB_DIR') ?: '')

// Auto-detect ERTS version from the OTP release directory (arm64 is canonical).
Expand All @@ -36,13 +37,14 @@ android {
versionCode 1
versionName "1.0"

ndk { abiFilters 'arm64-v8a', 'armeabi-v7a' }
ndk { abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64' }

externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_static",
"-DOTP_RELEASE=${mobOtpRelease}",
"-DOTP_RELEASE_ARM32=${mobOtpReleaseArm32}",
"-DOTP_RELEASE_X86_64=${mobOtpReleaseX86_64}",
"-DERTS_VSN=${ertsVsn}",
"-DMOB_DIR=${mobDir}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ cmake_minimum_required(VERSION 3.22.1)
project(<%= app_name %>)

# Paths injected by build.gradle (read from android/local.properties or env vars).
# OTP_RELEASE (arm64), OTP_RELEASE_ARM32, ERTS_VSN, MOB_DIR are set via -D flags.
# OTP_RELEASE (arm64), OTP_RELEASE_ARM32, OTP_RELEASE_X86_64, ERTS_VSN, MOB_DIR are set via -D flags.

# Select OTP path based on target ABI.
if(ANDROID_ABI STREQUAL "armeabi-v7a")
set(OTP_DIR "${OTP_RELEASE_ARM32}")
elseif(ANDROID_ABI STREQUAL "x86_64")
set(OTP_DIR "${OTP_RELEASE_X86_64}")
else()
set(OTP_DIR "${OTP_RELEASE}")
endif()
Expand Down
13 changes: 11 additions & 2 deletions priv/templates/mob.new/android/app/src/main/jni/build.zig.eex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const abi = required(b, "abi", "Android ABI: arm64-v8a or armeabi-v7a");
const abi = required(b, "abi", "Android ABI: arm64-v8a, armeabi-v7a, or x86_64");
const otp_dir = required(b, "otp_dir", "Path to per-ABI Android OTP runtime");
const erts_vsn = required(b, "erts_vsn", "ERTS version dir name (e.g. erts-17.0)");
const mob_dir = required(b, "mob_dir", "Path to mob library");
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn build(b: *std.Build) void {

const target_query = abi_to_target(abi) orelse {
std.debug.print(
"ERROR: unsupported -Dabi={s} (expected arm64-v8a or armeabi-v7a)\n",
"ERROR: unsupported -Dabi={s} (expected arm64-v8a, armeabi-v7a, or x86_64)\n",
.{abi},
);
std.process.exit(1);
Expand Down Expand Up @@ -326,12 +326,21 @@ fn abi_to_target(abi: []const u8) ?std.Target.Query {
.abi = .androideabi,
};
}
if (std.mem.eql(u8, abi, "x86_64")) {
return .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.os_version_min = .{ .semver = ver },
.abi = .android,
};
}
return null;
}

fn ndk_arch_triple(abi: []const u8) []const u8 {
if (std.mem.eql(u8, abi, "arm64-v8a")) return "aarch64-linux-android";
if (std.mem.eql(u8, abi, "armeabi-v7a")) return "arm-linux-androideabi";
if (std.mem.eql(u8, abi, "x86_64")) return "x86_64-linux-android";
return "";
}

Expand Down
1 change: 1 addition & 0 deletions priv/templates/mob.new/android/local.properties.eex
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
# Mob build paths — configured by `mix mob.install`:
mob.otp_release=/path/to/otp
mob.otp_release_arm32=/path/to/otp-arm32
mob.otp_release_x86_64=/path/to/otp-x86_64
mob.mob_dir=/path/to/mob
3 changes: 3 additions & 0 deletions test/mob_new/project_generator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ defmodule MobNew.ProjectGeneratorTest do
{:ok, dir} = ProjectGenerator.generate("test_app", tmp)
content = File.read!(Path.join(dir, "android/app/src/main/jni/CMakeLists.txt"))
assert content =~ "${OTP_RELEASE}"
assert content =~ "${OTP_RELEASE_X86_64}"
assert content =~ "${MOB_DIR}"
refute content =~ "${OTP_BUILD}"
refute content =~ "/Users/"
Expand Down Expand Up @@ -550,6 +551,8 @@ defmodule MobNew.ProjectGeneratorTest do
content = File.read!(Path.join(dir, "android/app/build.gradle"))
assert content =~ "local.properties"
assert content =~ "mob.otp_release"
assert content =~ "mob.otp_release_x86_64"
assert content =~ "abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64'"
refute content =~ "mob.otp_build"
refute content =~ "MOB_OTP_SRC"
end
Expand Down
Loading