From 38f082dff6a4d38cac1d3e5a5bdd6e649c5f9b35 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sun, 26 Feb 2023 04:43:05 +0800 Subject: [PATCH] Cross-compile for Linux ARM64 --- script/build.py | 16 ++++++++++++++-- script/common.py | 10 ++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/script/build.py b/script/build.py index 344945e..773a694 100755 --- a/script/build.py +++ b/script/build.py @@ -8,7 +8,7 @@ def main(): build_type = common.build_type() machine = common.machine() system = common.system() - ndk = common.ndk() + ndk = common.ndk() if build_type == 'Debug': args = ['is_debug=true'] @@ -52,8 +52,20 @@ def main(): # 'skia_enable_gpu=true', # 'skia_use_gl=true', 'extra_cflags_cc=["-frtti"]', - 'cxx="g++-9"', ] + + if (machine == 'arm64') and (machine != common.native_machine()): + args += [ + 'cc="aarch64-linux-gnu-gcc-9"', + 'cxx="aarch64-linux-gnu-g++-9"', + 'extra_cflags=["-I/usr/aarch64-linux-gnu/include"]' + ] + else: + args += [ + 'cc="gcc-9"', + 'cxx="g++-9"', + ] + elif 'windows' == system: args += [ 'skia_use_system_freetype2=false', diff --git a/script/common.py b/script/common.py index 6591e8d..4d2fad3 100644 --- a/script/common.py +++ b/script/common.py @@ -17,15 +17,18 @@ def system(): (args, _) = parser.parse_known_args() return args.system if args.system else {'Darwin': 'macos', 'Linux': 'linux', 'Windows': 'windows'}[platform.system()] +def native_machine(): + return {'AMD64': 'x64', 'x86_64': 'x64', 'arm64': 'arm64'}[platform.machine()] + def machine(): parser = create_parser() (args, _) = parser.parse_known_args() - return args.machine if args.machine else {'AMD64': 'x64', 'x86_64': 'x64', 'arm64': 'arm64', 'aarch64': 'arm64'}[platform.machine()] + return args.machine if args.machine else native_machine() def version(): parser = create_parser() args = parser.parse_args() - + if args.version: return args.version @@ -44,7 +47,7 @@ def classifier(): parser = create_parser() (args, _) = parser.parse_known_args() return '-' + args.classifier if args.classifier else '' - + def github_headers(): if os.environ.get('GITHUB_BASIC'): auth = 'Basic ' + base64.b64encode(os.environ.get('GITHUB_BASIC').encode('utf-8')).decode('utf-8') @@ -59,4 +62,3 @@ def ndk(): parser = create_parser() (args, _) = parser.parse_known_args() return args.ndk if args.ndk else '' -