This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid_toolchain_config.bzl
83 lines (76 loc) · 3.16 KB
/
android_toolchain_config.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
load(":unix_toolchain_config.bzl", "unix_cc_toolchain_config", "CLANG_OPTIONS")
WORKSPACE_NAME = "androidsdk_ndk-bundle"
ANDROID_COMPILE_OPTIONS = dict(CLANG_OPTIONS)
# Override groups of flags which differ for Android.
ANDROID_COMPILE_OPTIONS.update({
"compile_flags": CLANG_OPTIONS["compile_flags"] + [
"-funwind-tables",
"-fstack-protector-strong",
"-fpic",
],
"cxx_flags": [
"-stdlib=libc++",
],
})
_TOOL_PATHS = {
"ar": "{arch_base_dir}-ar",
"cpp": "{arch_base_dir}-cpp",
"gcc": "toolchains/llvm/prebuilt/linux-x86_64/bin/clang",
"gcov": "{arch_base_dir}-gcov",
"ld": "{arch_base_dir}-ld",
"nm": "/usr/bin/nm",
"objdump": "{arch_base_dir}-objdump",
"strip": "{arch_base_dir}-strip",
}
NDK_VERSION = "24"
ARCH_SPECIFIC_SETTINGS = {
"arm64": {
# <ndk root>/toolchains/llvm/prebuilt/linux-x86_64/bin/<target_system_name>-<tools...>
"target_system_name": "aarch64-linux-android",
# value of -target.
"target_flag": "aarch64-none-linux-android",
},
"armeabi": {
"target_system_name": "arm-linux-androideabi",
"target_flag": "armv7-none-linux-androideabi",
},
"x86_64": {
"target_system_name": "x86_64-linux-android",
"target_flag": "x86_64-none-linux-android",
},
}
def android_cc_toolchain_config(name, arch, ndk_version, extra_compile_flags = [], extra_dbg_compile_flags = [], extra_opt_compile_flags = [], extra_link_flags = [], **kwargs):
settings = ARCH_SPECIFIC_SETTINGS[arch]
target_flag = [
"-target",
settings["target_flag"] + ndk_version,
]
# All NDK toolchain binaries have the format <target_system_name>-<tool_name>. This variable
# contains the entire path up to and including the file name prefix, s.t. you just have to
# append `-<tool_name>`.
tool_base_path = "toolchains/llvm/prebuilt/linux-x86_64/bin/{target_system_name}".format(
target_system_name = settings["target_system_name"],
)
unix_cc_toolchain_config(
name = name,
abi_version = settings["target_system_name"],
compile_flags = ANDROID_COMPILE_OPTIONS["compile_flags"] +
target_flag +
extra_compile_flags,
cxx_flags = ANDROID_COMPILE_OPTIONS["cxx_flags"],
dbg_compile_flags = ANDROID_COMPILE_OPTIONS["dbg_compile_flags"] + extra_dbg_compile_flags,
include_directories = [], # Set "manually" with -isystem.
link_flags = ANDROID_COMPILE_OPTIONS["link_flags"] +
target_flag +
extra_link_flags,
opt_compile_flags = ANDROID_COMPILE_OPTIONS["opt_compile_flags"] + extra_opt_compile_flags,
opt_link_flags = ANDROID_COMPILE_OPTIONS["opt_link_flags"],
target_cpu = settings["target_system_name"],
target_system_name = settings["target_system_name"],
tool_paths = dict([(
k,
v.format(arch_base_dir = tool_base_path),
) for (k, v) in _TOOL_PATHS.items()]),
toolchain_identifier = settings["target_system_name"],
unfiltered_compile_flags = ANDROID_COMPILE_OPTIONS["unfiltered_compile_flags"],
)