From bd6bd033f1988eda44c720240afd018d3bca92a7 Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Wed, 7 Jun 2023 17:36:43 +0800 Subject: [PATCH 1/9] build gn and ninja in prebuild phase --- build/builder/common/env_checker.py | 2 + build/builder/common/prebuild.py | 57 +++++++++++++++++++++++++++++ build/configs/system_deps.toml | 1 - 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 build/builder/common/prebuild.py diff --git a/build/builder/common/env_checker.py b/build/builder/common/env_checker.py index bf29b16..e60023e 100755 --- a/build/builder/common/env_checker.py +++ b/build/builder/common/env_checker.py @@ -16,6 +16,7 @@ import toml from builder.common.logger import logger from builder.common.utils import exec_sys_command +from builder.common.prebuild import build_deps class Checker: """ @@ -80,6 +81,7 @@ class Checker: if missing_packages == []: return True elif install_missing_pkg: + build_deps(os.path.join(project_dir, "out", "prebuild")) return self._install_packages(missing_packages) else: logger.error('System package "{}" is not installed. Please install them by using `yum install` or `dnf install`'.format(', '.join(missing_packages))) diff --git a/build/builder/common/prebuild.py b/build/builder/common/prebuild.py new file mode 100755 index 0000000..a478d05 --- /dev/null +++ b/build/builder/common/prebuild.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# coding=utf-8 +import sys +import os +import shutil +import platform +from builder.common.utils import exec_sys_command +from builder.common.logger import logger +def get_machine_info(): + arch = platform.machine() + if arch == "x86_64": + arch = "x64" + os_name = platform.system().lower() + return arch,os_name + +def build_deps(output_dir): + arch, os_name = get_machine_info() + copy_path = "prebuilts/build-tools/" + os_name + "-" + arch + "/bin/" + + # build ninja + shutil.rmtree(output_dir) + ninja_dir = os.path.join(output_dir, "ninja-build") + os.makedirs(ninja_dir) + cmd = ['git', 'clone', 'https://gitee.com/src-openeuler/ninja-build.git', '-b', 'openEuler-22.03-LTS', ninja_dir] + is_success, _output = exec_sys_command(cmd) + if is_success: + cur_work_dir = os.getcwd() + exec_sys_command(['tar', 'xf', os.path.join(ninja_dir, 'ninja-1.10.2.tar.gz'), '-C', ninja_dir]) + os.chdir(os.path.join(ninja_dir, 'ninja-1.10.2')) + exec_sys_command(['python3', 'configure.py', '--bootstrap']) + if os.path.exists("ninja"): + exec_sys_command(['cp', 'ninja', os.path.join(output_dir, "../../", copy_path)]) + logger.info("build ninja success") + os.chdir(cur_work_dir) + + # build gn + gn_dir = os.path.join(output_dir, "gn-build") + os.makedirs(gn_dir) + cmd = ['git', 'clone', 'https://gitee.com/src-openeuler/gn.git', '-b', 'openEuler-22.03-LTS-SP1', gn_dir] + is_success, _output = exec_sys_command(cmd) + if is_success: + cur_work_dir = os.getcwd() + exec_sys_command(['tar', 'xf', os.path.join(gn_dir, 'gn-e1ac69b17da0c6d4f5e34e686690ff70c6a43e6f.tar.gz'), '-C', gn_dir]) + os.chdir(gn_dir) + #exec_sys_command(['patch', '-p1 Date: Wed, 7 Jun 2023 17:49:33 +0800 Subject: [PATCH 2/9] build.sh not find gn --- build/builder/common/env_checker.py | 1 + build/builder/common/prebuild.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build/builder/common/env_checker.py b/build/builder/common/env_checker.py index e60023e..d753b71 100755 --- a/build/builder/common/env_checker.py +++ b/build/builder/common/env_checker.py @@ -79,6 +79,7 @@ class Checker: missing_packages.append(pkg) if missing_packages == []: + build_deps(os.path.join(project_dir, "out", "prebuild")) return True elif install_missing_pkg: build_deps(os.path.join(project_dir, "out", "prebuild")) diff --git a/build/builder/common/prebuild.py b/build/builder/common/prebuild.py index a478d05..25287a0 100755 --- a/build/builder/common/prebuild.py +++ b/build/builder/common/prebuild.py @@ -16,6 +16,11 @@ def get_machine_info(): def build_deps(output_dir): arch, os_name = get_machine_info() copy_path = "prebuilts/build-tools/" + os_name + "-" + arch + "/bin/" + abs_copy_path = os.path.join(output_dir, "../../", copy_path) + ninja_path = os.path.join(abs_copy_path, "ninja") + gn_path = os.path.join(abs_copy_path, "gn") + if os.path.exists(ninja_path) and os.path.exists(gn_path): + return # build ninja shutil.rmtree(output_dir) @@ -29,7 +34,7 @@ def build_deps(output_dir): os.chdir(os.path.join(ninja_dir, 'ninja-1.10.2')) exec_sys_command(['python3', 'configure.py', '--bootstrap']) if os.path.exists("ninja"): - exec_sys_command(['cp', 'ninja', os.path.join(output_dir, "../../", copy_path)]) + exec_sys_command(['cp', 'ninja', abs_copy_path]) logger.info("build ninja success") os.chdir(cur_work_dir) @@ -49,7 +54,7 @@ def build_deps(output_dir): exec_sys_command([os.path.join(ninja_dir, "ninja-1.10.2", "ninja"), '-C', 'out']) os.chdir(os.path.join(gn_dir, "out")) if os.path.exists("gn"): - exec_sys_command(['cp', 'gn', os.path.join(output_dir, "../../", copy_path)]) + exec_sys_command(['cp', 'gn', abs_copy_path]) logger.info("build gn success") os.chdir(cur_work_dir) -- Gitee From 65d6cb1d8b0b75f73db1f7ad0416d3f551a6f971 Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Wed, 7 Jun 2023 20:26:07 +0800 Subject: [PATCH 3/9] fix rm out/prebuild error --- build/builder/common/prebuild.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build/builder/common/prebuild.py b/build/builder/common/prebuild.py index 25287a0..fcbd320 100755 --- a/build/builder/common/prebuild.py +++ b/build/builder/common/prebuild.py @@ -17,13 +17,14 @@ def build_deps(output_dir): arch, os_name = get_machine_info() copy_path = "prebuilts/build-tools/" + os_name + "-" + arch + "/bin/" abs_copy_path = os.path.join(output_dir, "../../", copy_path) - ninja_path = os.path.join(abs_copy_path, "ninja") - gn_path = os.path.join(abs_copy_path, "gn") + ninja_path = os.path.abspath(os.path.join(abs_copy_path, "ninja")) + gn_path = os.path.abspath(os.path.join(abs_copy_path, "gn")) if os.path.exists(ninja_path) and os.path.exists(gn_path): return # build ninja - shutil.rmtree(output_dir) + if os.path.exists(output_dir): + shutil.rmtree(output_dir) ninja_dir = os.path.join(output_dir, "ninja-build") os.makedirs(ninja_dir) cmd = ['git', 'clone', 'https://gitee.com/src-openeuler/ninja-build.git', '-b', 'openEuler-22.03-LTS', ninja_dir] -- Gitee From 621d3494b1c218151e6a57c202bf58da1b7175aa Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Thu, 8 Jun 2023 12:54:30 +0800 Subject: [PATCH 4/9] fix aarch64 build --- build/builder.py | 4 ++-- build/builder/commands/build.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build/builder.py b/build/builder.py index 9491f0e..a474f8c 100755 --- a/build/builder.py +++ b/build/builder.py @@ -59,8 +59,8 @@ class FtBuilder: build_parser = subparsers.add_parser('build', help='Build the project') build_parser.add_argument('-t', '--target-cpu', type=str, - choices=['x64', 'x86'], - default='x64', + choices=['auto', 'x64', 'x86', 'aarch64'], + default='auto', help='Specify the target CPU type.') build_parser.add_argument('-b', '--build-type', choices=['debug', 'release'], diff --git a/build/builder/commands/build.py b/build/builder/commands/build.py index 270695d..6f91b7f 100755 --- a/build/builder/commands/build.py +++ b/build/builder/commands/build.py @@ -17,6 +17,7 @@ import os from builder.common.logger import logger from builder.common.utils import exec_sys_command from builder.common.env_checker import checker +from builder.common.prebuild import get_machine_info class Builder: def __init__(self, args): @@ -24,7 +25,11 @@ class Builder: self.project_dir = args.project_dir self.build_output_dir = os.path.join(args.project_dir, "out", args.build_type.title(), args.target_cpu) - self._build_tools_dir = os.path.join(args.project_dir, "prebuilts", "build-tools", f"linux-{args.target_cpu}", "bin") + os_name = "linux" + arch = "x64" + if args.target_cpu == "auto": + arch, os_name = get_machine_info() + self._build_tools_dir = os.path.join(args.project_dir, "prebuilts", "build-tools", os_name+"-"+arch, "bin") self.gn_path = os.path.join(self._build_tools_dir, "gn") self.ninja_path = os.path.join(self._build_tools_dir, "ninja") -- Gitee From ded2ae970bb1926630db89cc8b874665f9b25c46 Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Thu, 8 Jun 2023 13:11:46 +0800 Subject: [PATCH 5/9] add tar deps --- build/configs/system_deps.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/build/configs/system_deps.toml b/build/configs/system_deps.toml index ee53ef9..224e18a 100755 --- a/build/configs/system_deps.toml +++ b/build/configs/system_deps.toml @@ -25,4 +25,5 @@ package_deps = [ "compiler-rt", "llvm-devel", "python3", + "tar", ] -- Gitee From e2d529979273ebc44da49f7c98907cfc87641798 Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Thu, 8 Jun 2023 13:15:13 +0800 Subject: [PATCH 6/9] fix install seq --- build/builder/common/env_checker.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/builder/common/env_checker.py b/build/builder/common/env_checker.py index d753b71..8ca0415 100755 --- a/build/builder/common/env_checker.py +++ b/build/builder/common/env_checker.py @@ -82,8 +82,10 @@ class Checker: build_deps(os.path.join(project_dir, "out", "prebuild")) return True elif install_missing_pkg: - build_deps(os.path.join(project_dir, "out", "prebuild")) - return self._install_packages(missing_packages) + ret = self._install_packages(missing_packages) + if ret: + build_deps(os.path.join(project_dir, "out", "prebuild")) + return ret else: logger.error('System package "{}" is not installed. Please install them by using `yum install` or `dnf install`'.format(', '.join(missing_packages))) return False -- Gitee From dae33b7bb6f1eb60075a1dc0bc1957215c7c68b1 Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Thu, 8 Jun 2023 14:27:14 +0800 Subject: [PATCH 7/9] fix aarch64 arch machine build error --- build/builder/common/prebuild.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/builder/common/prebuild.py b/build/builder/common/prebuild.py index fcbd320..3cf809a 100755 --- a/build/builder/common/prebuild.py +++ b/build/builder/common/prebuild.py @@ -35,7 +35,7 @@ def build_deps(output_dir): os.chdir(os.path.join(ninja_dir, 'ninja-1.10.2')) exec_sys_command(['python3', 'configure.py', '--bootstrap']) if os.path.exists("ninja"): - exec_sys_command(['cp', 'ninja', abs_copy_path]) + exec_sys_command(['cp', 'ninja', ninja_path]) logger.info("build ninja success") os.chdir(cur_work_dir) @@ -55,7 +55,7 @@ def build_deps(output_dir): exec_sys_command([os.path.join(ninja_dir, "ninja-1.10.2", "ninja"), '-C', 'out']) os.chdir(os.path.join(gn_dir, "out")) if os.path.exists("gn"): - exec_sys_command(['cp', 'gn', abs_copy_path]) + exec_sys_command(['cp', 'gn', gn_path]) logger.info("build gn success") os.chdir(cur_work_dir) -- Gitee From b64c5f12a78e170249f7e7e1d3e75287a0c8c0c2 Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Thu, 8 Jun 2023 14:40:56 +0800 Subject: [PATCH 8/9] fix aarch64 arch machine build error --- build/builder/common/prebuild.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/builder/common/prebuild.py b/build/builder/common/prebuild.py index 3cf809a..92db124 100755 --- a/build/builder/common/prebuild.py +++ b/build/builder/common/prebuild.py @@ -25,6 +25,8 @@ def build_deps(output_dir): # build ninja if os.path.exists(output_dir): shutil.rmtree(output_dir) + if not os.path.exists(abs_copy_path): + os.makedirs(abs_copy_path) ninja_dir = os.path.join(output_dir, "ninja-build") os.makedirs(ninja_dir) cmd = ['git', 'clone', 'https://gitee.com/src-openeuler/ninja-build.git', '-b', 'openEuler-22.03-LTS', ninja_dir] -- Gitee From e61d73105c6f25f9a51299de2cd108da214a3d46 Mon Sep 17 00:00:00 2001 From: ShaoboFeng Date: Thu, 8 Jun 2023 16:54:17 +0800 Subject: [PATCH 9/9] fix aarch64 arch machine build error --- .gitignore | 1 + build/builder/commands/build.py | 2 +- build/gn/toolchain/linux/BUILD.gn | 11 +++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ada3096..ea7c990 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/__pycache__ out +prebuilts/build-tools diff --git a/build/builder/commands/build.py b/build/builder/commands/build.py index 6f91b7f..6790715 100755 --- a/build/builder/commands/build.py +++ b/build/builder/commands/build.py @@ -24,11 +24,11 @@ class Builder: self.args = args self.project_dir = args.project_dir - self.build_output_dir = os.path.join(args.project_dir, "out", args.build_type.title(), args.target_cpu) os_name = "linux" arch = "x64" if args.target_cpu == "auto": arch, os_name = get_machine_info() + self.build_output_dir = os.path.join(args.project_dir, "out", args.build_type.title(), arch) self._build_tools_dir = os.path.join(args.project_dir, "prebuilts", "build-tools", os_name+"-"+arch, "bin") self.gn_path = os.path.join(self._build_tools_dir, "gn") self.ninja_path = os.path.join(self._build_tools_dir, "ninja") diff --git a/build/gn/toolchain/linux/BUILD.gn b/build/gn/toolchain/linux/BUILD.gn index 79eb8cc..154a223 100755 --- a/build/gn/toolchain/linux/BUILD.gn +++ b/build/gn/toolchain/linux/BUILD.gn @@ -16,10 +16,17 @@ import("//build/gn/toolchain/toolchain.gni") +clang_toolchain("clang_arm64") { + toolchain_args = { + current_cpu = "" + current_os = "" + } +} + clang_toolchain("clang_x64") { toolchain_args = { - current_cpu = "x64" - current_os = "linux" + current_cpu = "" + current_os = "" } if (use_musl) { -- Gitee