-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.py
786 lines (628 loc) · 23.9 KB
/
configs.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
#
# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""APIs for build configurations."""
from pathlib import Path
from typing import Dict, List, Optional
import functools
import json
import hosts
import paths
import toolchains
import win_sdk
class Config:
"""Base configuration."""
name: str
target_os: hosts.Host
target_arch: hosts.Arch = hosts.Arch.X86_64
sysroot: Optional[Path] = None
"""Additional config data that a builder can specify."""
extra_config = None
@property
def llvm_triple(self) -> str:
raise NotImplementedError()
def get_c_compiler(self, toolchain: toolchains.Toolchain) -> Path:
"""Returns path to c compiler."""
return toolchain.cc
def get_cxx_compiler(self, toolchain: toolchains.Toolchain) -> Path:
"""Returns path to c++ compiler."""
return toolchain.cxx
def get_linker(self, toolchain: toolchains.Toolchain) -> Optional[Path]:
"""Returns the path to linker."""
return None
@property
def cflags(self) -> List[str]:
"""Returns a list of flags for c compiler."""
return []
@property
def cxxflags(self) -> List[str]:
"""Returns a list of flags used for cxx compiler."""
return self.cflags
@property
def ldflags(self) -> List[str]:
"""Returns a list of flags for static linker."""
return []
@property
def env(self) -> Dict[str, str]:
return {}
def __str__(self) -> str:
return self.target_os.name
@property
def output_suffix(self) -> str:
"""The suffix of output directory name."""
return f'-{self.target_os.value}'
@property
def cmake_defines(self) -> Dict[str, str]:
"""Additional defines for cmake."""
return dict()
class _BaseConfig(Config): # pylint: disable=abstract-method
"""Base configuration."""
use_lld: bool = True
target_os: hosts.Host
# Assume most configs are cross compiling
is_cross_compiling: bool = True
@property
def cflags(self) -> List[str]:
cflags: List[str] = [f'-ffile-prefix-map={paths.ANDROID_DIR}/=']
cflags.extend(f'-B{d}' for d in self.bin_dirs)
return cflags
@property
def ldflags(self) -> List[str]:
ldflags: List[str] = []
for lib_dir in self.lib_dirs:
ldflags.append(f'-B{lib_dir}')
ldflags.append(f'-L{lib_dir}')
if self.use_lld:
ldflags.append('-fuse-ld=lld')
return ldflags
@property
def bin_dirs(self) -> List[Path]:
"""Paths to binaries used in cflags."""
return []
@property
def lib_dirs(self) -> List[Path]:
"""Paths to libraries used in ldflags."""
return []
def get_linker(self, toolchain: toolchains.Toolchain) -> Optional[Path]:
if self.use_lld:
return toolchain.lld
return None
class BaremetalConfig(_BaseConfig):
"""Configuration for baremetal targets."""
target_os: hosts.Host = hosts.Host.Baremetal
@property
def cmake_defines(self) -> Dict[str, str]:
defines = super().cmake_defines
defines['COMPILER_RT_BAREMETAL_BUILD'] = 'ON'
return defines
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append(f'--target={self.llvm_triple}')
return cflags
@property
def output_suffix(self) -> str:
"""The suffix of output directory name."""
return f'-{self.target_arch.value}-baremetal'
class BaremetalAArch64Config(BaremetalConfig):
"""Configuration for baremetal targets."""
target_arch: hosts.Arch = hosts.Arch.AARCH64
@property
def llvm_triple(self) -> str:
return 'aarch64-elf'
class BaremetalArmMultilibConfig(BaremetalConfig):
"""Configuration for baremetal ARM multilib targets."""
target_arch: hosts.Arch = hosts.Arch.ARM
@property
def multilib_name(self) -> str:
"""The name of the multilib variant."""
raise NotImplementedError()
@property
def output_suffix(self) -> str:
"""The suffix of output directory name."""
return f'-{self.multilib_name}-baremetal'
class BaremetalArmv6MConfig(BaremetalArmMultilibConfig):
"""Configuration for baremetal Armv6-M target."""
@property
def llvm_triple(self) -> str:
return 'armv6m-none-eabi'
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append('-march=armv6-m')
cflags.append('-mfloat-abi=soft')
return cflags
@property
def multilib_name(self) -> str:
return 'armv6-m'
class BaremetalArmv8MBaseConfig(BaremetalArmMultilibConfig):
"""Configuration for baremetal Armv8-M baseline target."""
@property
def llvm_triple(self) -> str:
return 'armv8m.base-none-eabi'
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append('-march=armv8-m.base')
cflags.append('-mfloat-abi=soft')
return cflags
@property
def multilib_name(self) -> str:
return 'armv8-m.base'
class BaremetalArmv81MMainConfig(BaremetalArmMultilibConfig):
"""Configuration for baremetal Armv8.1-M mainline target."""
def __init__(self, fpu: hosts.Armv81MMainFpu):
self.fpu = fpu
@property
def llvm_triple(self) -> str:
if self.fpu == hosts.Armv81MMainFpu.NONE:
return 'armv8.1m.main-none-eabi'
else:
return 'armv8.1m.main-none-eabihf'
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append('-march=armv8.1-m.main')
cflags.append(f'-mfpu={self.fpu.llvm_fpu}')
cflags.append(f'-mfloat-abi={self.fpu.llvm_float_abi}')
return cflags
@property
def multilib_name(self) -> str:
return f'armv8.1-m.main+{self.fpu.value}'
class DarwinConfig(_BaseConfig):
"""Configuration for Darwin targets."""
target_os: hosts.Host = hosts.Host.Darwin
use_lld: bool = False
is_cross_compiling: bool = False
@property
def cflags(self) -> List[str]:
cflags = super().cflags
# Fails if an API used is newer than what specified in -mmacosx-version-min.
cflags.append('-Werror=unguarded-availability')
return cflags
@property
def llvm_triple(self) -> str:
# x86_64-apple-darwin is another choice
return 'arm64-apple-darwin'
class _GccConfig(_BaseConfig): # pylint: disable=abstract-method
"""Base config to use gcc libs."""
gcc_root: Path
gcc_triple: str
gcc_ver: str
def __init__(self, is_32_bit: bool = False):
self.is_32_bit = is_32_bit
@property
def bin_dirs(self) -> List[Path]:
return [self.gcc_root / self.gcc_triple / 'bin']
@property
def gcc_lib_dir(self) -> Path:
gcc_lib_dir = self.gcc_root / 'lib' / 'gcc' / self.gcc_triple / self.gcc_ver
if self.is_32_bit:
gcc_lib_dir = gcc_lib_dir / '32'
return gcc_lib_dir
@property
def gcc_builtin_dir(self)-> Path:
base = self.gcc_root / self.gcc_triple
if self.is_32_bit:
return base / 'lib32'
else:
return base / 'lib64'
@property
def lib_dirs(self) -> List[Path]:
return [self.gcc_lib_dir, self.gcc_builtin_dir]
class LinuxConfig(_GccConfig):
"""Configuration for Linux targets."""
target_os: hosts.Host = hosts.Host.Linux
sysroot: Optional[Path] = (paths.GCC_ROOT / 'host' / 'x86_64-linux-glibc2.17-4.8' / 'sysroot')
gcc_root: Path = (paths.GCC_ROOT / 'host' / 'x86_64-linux-glibc2.17-4.8')
gcc_triple: str = 'x86_64-linux'
gcc_ver: str = '4.8.3'
is_cross_compiling: bool = False
is_musl: bool = False
@property
def llvm_triple(self) -> str:
return 'i386-unknown-linux-gnu' if self.is_32_bit else 'x86_64-unknown-linux-gnu'
@property
def cflags(self) -> List[str]:
cflags = super().cflags
if self.is_32_bit and not self.is_musl:
# compiler-rt/lib/gwp_asan uses PRIu64 and similar format-specifier macros.
# Add __STDC_FORMAT_MACROS so their definition gets included from
# inttypes.h. This explicit flag is only needed here. 64-bit host runtimes
# are built in stage1/stage2 and get it from the LLVM CMake configuration.
# These are defined unconditionaly in bionic and newer glibc
# (https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1ef74943ce2f114c78b215af57c2ccc72ccdb0b7)
cflags.append('-D__STDC_FORMAT_MACROS')
cflags.append('-march=i686')
return cflags
@property
def ldflags(self) -> List[str]:
return super().ldflags + [
'-Wl,--hash-style=both',
]
class LinuxMuslConfig(LinuxConfig):
"""Config for Musl sysroot bootstrapping"""
target_os: hosts.Host = hosts.Host.Linux
target_arch: hosts.Arch
is_cross_compiling: bool
is_musl: bool = True
def __init__(self, arch: hosts.Arch = hosts.Arch.X86_64, is_cross_compiling: bool = True):
self.triple = arch.llvm_arch + '-unknown-linux-musl'
if arch is hosts.Arch.ARM:
self.triple += 'eabihf'
self.target_arch = arch
self.is_cross_compiling = is_cross_compiling
@property
def is_32_bit(self):
return self.target_arch in [hosts.Arch.ARM, hosts.Arch.I386]
@property
def llvm_triple(self) -> str:
return self.triple
@property
def cflags(self) -> List[str]:
cflags = super().cflags + [
f'--target={self.llvm_triple}',
'-D_LIBCPP_HAS_MUSL_LIBC',
'-D_LARGEFILE64_SOURCE=1',
# gcc does this automatically and glibc includes it in features.h
# Neither clang nor musl include it, so add it here. Otherwise
# libedit fails with error: wchar_t must store ISO 10646 characters
'-include stdc-predef.h',
]
if self.target_arch is hosts.Arch.ARM:
cflags.append('-march=armv7-a')
return cflags
@property
def cxxflags(self) -> List[str]:
cxxflags = super().cxxflags + [
# -stdlib=libc++ prevents the "Check for working CXX compiler"
# step from failing when it can't find libstdc++.
# -Wno-unused-command-line-argument is necessary for commands that
# use -Werror -nostdinc++.
'-stdlib=libc++',
'-Wno-unused-command-line-argument',
]
return cxxflags
@property
def ldflags(self) -> List[str]:
return super().ldflags + [
'-rtlib=compiler-rt',
'-Wl,-z,stack-size=2097152',
]
@property
def sysroot(self) -> Path:
return paths.BUILD_TOOLS_DIR / 'sysroots' / self.triple
@property
def output_suffix(self) -> str:
"""The suffix of output directory name."""
return f'-{self.llvm_triple}'
@property
def lib_dirs(self) -> List[Path]:
"""Override gcc libdirs."""
return []
@property
def bin_dirs(self) -> List[Path]:
"""Override gcc bindirs."""
return []
@property
def cmake_defines(self) -> Dict[str, str]:
defines = super().cmake_defines
defines['LIBCXX_USE_COMPILER_RT'] = 'TRUE'
defines['LIBCXXABI_USE_COMPILER_RT'] = 'TRUE'
defines['LIBUNWIND_USE_COMPILER_RT'] = 'TRUE'
# The musl sysroots contain empty libdl.a, libpthread.a and librt.a to
# satisfy the parts of the LLVM build that hardcode -lpthread, etc.,
# but that causes LLVM to mis-detect them as libpthread.so, etc.
# Hardcoded them as disabled to prevent references from .deplibs
# sections.
defines['LIBCXX_HAS_RT_LIB'] = 'FALSE'
defines['LIBCXX_HAS_PTHREAD_LIB'] = 'FALSE'
defines['LIBCXXABI_HAS_PTHREAD_LIB'] = 'FALSE'
defines['LIBUNWIND_HAS_DL_LIB'] = 'FALSE'
defines['LIBUNWIND_HAS_PTHREAD_LIB'] = 'FALSE'
defines['LLVM_DEFAULT_TARGET_TRIPLE'] = self.llvm_triple
return defines
class LinuxMuslHostConfig(LinuxMuslConfig):
"""Config for Musl as the host"""
def __init__(self, arch: hosts.Arch = hosts.Arch.X86_64):
super().__init__(arch=arch, is_cross_compiling=False)
@property
def env(self) -> Dict[str, str]:
env = super().env
env['LD_LIBRARY_PATH'] = str(self.sysroot / 'lib')
return env
# TODO: We should kill off 32-bit Windows support, but we still need it because
# we have a single 32-bit DLL for USB stuff for adb.exe/fastboot.exe.
class MinGWConfig(_GccConfig):
"""Configuration for MinGW targets."""
target_os: hosts.Host = hosts.Host.Windows
gcc_root: Path = (paths.GCC_ROOT / 'host' / 'x86_64-w64-mingw32-4.8')
gcc_triple: str = 'x86_64-w64-mingw32'
gcc_ver: str = '4.8.3'
@property
def target_arch(self) -> hosts.Arch:
return hosts.Arch.I386 if self.is_32_bit else hosts.Arch.X86_64
@property
def llvm_triple(self) -> str:
return 'i686-pc-windows-gnu' if self.is_32_bit else 'x86_64-pc-windows-gnu'
@property
def sysroot(self) -> Optional[Path]:
return paths.SYSROOTS / ('i686-w64-mingw32' if self.is_32_bit else 'x86_64-w64-mingw32')
@property
def output_suffix(self) -> str:
return '-windows32' if self.is_32_bit else '-windows'
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append(f'--target={self.llvm_triple}')
cflags.append('-D_LARGEFILE_SOURCE')
cflags.append('-D_FILE_OFFSET_BITS=64')
cflags.append('-D_WIN32_WINNT=0x0600')
cflags.append('-DWINVER=0x0600')
cflags.append('-D__MSVCRT_VERSION__=0x1400')
if self.target_arch == hosts.Arch.I386:
cflags.append('-fsjlj-exceptions')
return cflags
@property
def ldflags(self) -> List[str]:
ldflags = super().ldflags
if not self.is_32_bit:
ldflags.append('-Wl,--dynamicbase')
ldflags.append('-Wl,--nxcompat')
ldflags.append('-Wl,--high-entropy-va')
ldflags.append('-Wl,--Xlink=-Brepro')
return ldflags
@property
def lib_dirs(self) -> List[Path]:
# No need for explicit lib_dirs. We copy them into the sysroot.
return []
class MSVCConfig(Config):
"""Configuration for MSVC toolchain."""
target_os: hosts.Host = hosts.Host.Windows
# We still use lld but don't want -fuse-ld=lld in linker flags.
use_lld: bool = False
def get_c_compiler(self, toolchain: toolchains.Toolchain) -> Path:
return toolchain.cl
def get_cxx_compiler(self, toolchain: toolchains.Toolchain) -> Path:
return toolchain.cl
def get_linker(self, toolchain: toolchains.Toolchain) -> Optional[Path]:
return toolchain.lld_link
@functools.cached_property
def _read_env_setting(self) -> Dict[str, str]:
sdk_path = win_sdk.get_path()
assert sdk_path is not None
base_path = sdk_path / 'bin'
with (base_path / 'SetEnv.x64.json').open('r') as env_file:
env_setting = json.load(env_file)
return {key: ';'.join(str(base_path.joinpath(*v)) for v in value)
for key, value in env_setting['env'].items()}
@property
def llvm_triple(self) -> str:
return 'x86_64-pc-windows-msvc',
@property
def cflags(self) -> List[str]:
return super().cflags + [
'-w',
'-fuse-ld=lld',
'--target={self.llvm_triple}',
'-fms-compatibility-version=19.10',
'-D_HAS_EXCEPTIONS=1',
'-D_CRT_STDIO_ISO_WIDE_SPECIFIERS'
]
@property
def ldflags(self) -> List[str]:
return super().ldflags + [
'/MANIFEST:NO',
'/dynamicbase',
'/nxcompat',
'/highentropyva',
'/Brepro',
]
@property
def env(self) -> Dict[str, str]:
return self._read_env_setting
@property
def cmake_defines(self) -> Dict[str, str]:
defines = super().cmake_defines
defines['CMAKE_POLICY_DEFAULT_CMP0091'] = 'NEW'
defines['CMAKE_MSVC_RUNTIME_LIBRARY'] = 'MultiThreaded'
return defines
class AndroidConfig(_BaseConfig):
"""Config for Android targets."""
target_os: hosts.Host = hosts.Host.Android
target_arch: hosts.Arch
_toolchain_path: Optional[Path]
static: bool = False
platform: bool = False
suppress_libcxx_headers: bool = False
override_api_level: Optional[int] = None
@property
def base_llvm_triple(self) -> str:
"""Get base LLVM triple (without API level)."""
return f'{self.target_arch.llvm_arch}-linux-android'
@property
def llvm_triple(self) -> str:
"""Get LLVM triple (with API level)."""
return f'{self.base_llvm_triple}{self.api_level}'
@property
def ndk_arch(self) -> str:
"""Converts to ndk arch."""
return {
hosts.Arch.ARM: 'arm',
hosts.Arch.AARCH64: 'arm64',
hosts.Arch.I386: 'x86',
hosts.Arch.RISCV64: 'riscv64',
hosts.Arch.X86_64: 'x86_64',
}[self.target_arch]
@property
def ndk_sysroot_triple(self) -> str:
"""Triple used to identify NDK sysroot."""
if self.target_arch == hosts.Arch.ARM:
return 'arm-linux-androideabi'
return self.base_llvm_triple
@property
def sysroot(self) -> Path: # type: ignore
"""Returns sysroot path."""
platform_or_ndk = 'platform' if self.platform else 'ndk'
return paths.SYSROOTS / platform_or_ndk / self.ndk_arch
@property
def ldflags(self) -> List[str]:
ldflags = super().ldflags
ldflags.append('-rtlib=compiler-rt')
ldflags.append('-Wl,-z,defs')
ldflags.append('-Wl,--gc-sections')
ldflags.append('-Wl,--build-id=sha1')
ldflags.append('-pie')
if self.static:
ldflags.append('-static')
return ldflags
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append(f'--target={self.llvm_triple}')
if self._toolchain_path:
toolchain_bin = paths.GCC_ROOT / self._toolchain_path / 'bin'
cflags.append(f'-B{toolchain_bin}')
cflags.append('-ffunction-sections')
cflags.append('-fdata-sections')
return cflags
@property
def _libcxx_header_dirs(self) -> List[Path]:
# For the NDK, the sysroot has the C++ headers.
assert self.platform
if self.suppress_libcxx_headers:
return []
# <prebuilts>/include/c++/v1 includes the cxxabi headers
return [
paths.CLANG_PREBUILT_LIBCXX_HEADERS,
# The platform sysroot also has Bionic headers from an NDK release,
# but override them with the current headers.
paths.BIONIC_HEADERS,
paths.BIONIC_KERNEL_HEADERS,
]
@property
def cxxflags(self) -> List[str]:
cxxflags = super().cxxflags
if self.platform:
# For the NDK, the sysroot has the C++ headers, but for the
# platform, we need to add the headers manually.
cxxflags.append('-nostdinc++')
cxxflags.extend(f'-isystem {d}' for d in self._libcxx_header_dirs)
return cxxflags
@property
def api_level(self) -> int:
if self.override_api_level:
return self.override_api_level
if self.target_arch == hosts.Arch.RISCV64:
return 35
if self.static or self.platform:
# Set API level for platform to to 30 since these runtimes can be
# used for apexes targeting that API level.
return 30
return 21
def __str__(self) -> str:
return (f'{self.target_os.name}-{self.target_arch.name} ' +
f'(platform={self.platform} static={self.static} {self.extra_config})')
@property
def output_suffix(self) -> str:
suffix = f'-{self.target_arch.value}'
if not self.platform:
suffix += '-ndk-cxx'
return suffix
class AndroidARMConfig(AndroidConfig):
"""Configs for android arm targets."""
target_arch: hosts.Arch = hosts.Arch.ARM
_toolchain_path: Optional[Path] = Path('arm/arm-linux-androideabi-4.9/arm-linux-androideabi')
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append('-march=armv7-a')
return cflags
class AndroidAArch64Config(AndroidConfig):
"""Configs for android arm64 targets."""
target_arch: hosts.Arch = hosts.Arch.AARCH64
_toolchain_path: Optional[Path] = Path('aarch64/aarch64-linux-android-4.9/aarch64-linux-android')
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append('-mbranch-protection=standard')
return cflags
class AndroidRiscv64Config(AndroidConfig):
"""Configs for android riscv64 targets."""
target_arch: hosts.Arch = hosts.Arch.RISCV64
_toolchain_path: Optional[Path] = None
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append(f'-isystem {self.sysroot}/usr/include/{self.ndk_sysroot_triple}')
return cflags
class AndroidX64Config(AndroidConfig):
"""Configs for android x86_64 targets."""
target_arch: hosts.Arch = hosts.Arch.X86_64
_toolchain_path: Optional[Path] = Path('x86/x86_64-linux-android-4.9/x86_64-linux-android')
class AndroidI386Config(AndroidConfig):
"""Configs for android x86 targets."""
target_arch: hosts.Arch = hosts.Arch.I386
_toolchain_path: Optional[Path] = Path('x86/x86_64-linux-android-4.9/x86_64-linux-android')
@property
def cflags(self) -> List[str]:
cflags = super().cflags
cflags.append('-m32')
return cflags
def host_config(musl: bool=False) -> Config:
"""Returns the Config matching the current machine."""
return {
hosts.Host.Linux: LinuxMuslHostConfig if musl else LinuxConfig,
hosts.Host.Darwin: DarwinConfig,
hosts.Host.Windows: MinGWConfig
}[hosts.build_host()]()
def host_32bit_config(musl: bool=False) -> Config:
if hosts.build_host().is_darwin:
raise RuntimeError("host_32bit config only needed for Windows or Linux")
if musl:
return LinuxMuslHostConfig(hosts.Arch.I386)
if hosts.build_host().is_windows:
return MinGWConfig(is_32_bit=True)
else:
return LinuxConfig(is_32_bit=True)
def android_configs(platform: bool=True,
static: bool=False,
suppress_libcxx_headers: bool=False,
extra_config=None) -> List[Config]:
"""Returns a list of configs for android builds."""
configs = [
AndroidARMConfig(),
AndroidAArch64Config(),
AndroidI386Config(),
AndroidX64Config(),
AndroidRiscv64Config(),
]
for config in configs:
config.static = static
config.platform = platform
config.suppress_libcxx_headers = suppress_libcxx_headers
config.extra_config = extra_config
# List is not covariant. Explicit convert is required to make it List[Config].
return list(configs)
def android_ndk_tsan_configs() -> List[Config]:
"""Returns a list of configs for android builds."""
configs = [
AndroidAArch64Config(),
AndroidX64Config(),
]
for config in configs:
config.override_api_level = 24
# List is not covariant. Explicit convert is required to make it List[Config].
return list(configs)