Skip to content
Open
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
21 changes: 17 additions & 4 deletions tools/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys

import common_compiler_flags
import my_spawn


def options(opts):
Expand Down Expand Up @@ -44,9 +43,6 @@ def generate(env):
print("Only arm64, x86_64, arm32, and x86_32 are supported on Android. Exiting.")
env.Exit(1)

if sys.platform == "win32" or sys.platform == "msys":
my_spawn.configure(env)

# Validate API level
if int(env["android_api_level"]) < 24:
print("WARNING: minimum supported Android target api is 24. Forcing target api 24.")
Expand Down Expand Up @@ -101,6 +97,17 @@ def generate(env):
},
}
arch_info = arch_info_table[env["arch"]]

if sys.platform == "win32" or sys.platform == "msys":
# Using short path which is guaranteed to have no whitespaces
import subprocess

def get_short_path(long_path):
cmd = f'cmd /c for %A in ("{long_path}") do @echo %~sA'
output = subprocess.check_output(cmd, shell=True)
return output.decode('utf-8').strip()

toolchain = get_short_path(toolchain)

# Setup tools
env["CC"] = toolchain + "/bin/clang"
Expand All @@ -112,6 +119,12 @@ def generate(env):
env["RANLIB"] = toolchain + "/bin/llvm-ranlib"
env["SHLIBSUFFIX"] = ".so"

if sys.platform == "win32" or sys.platform == "msys":
# Use TempFileMunge since some AR invocations are too long for cmd.exe.
# Use POSIX-style paths, required with TempFileMunge.
env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix")
env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}"

env.Append(
CCFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"], "-fPIC"]
)
Expand Down