| 17 | |
| 18 | |
| 19 | class Build: |
| 20 | # build env flags |
| 21 | BUILD_ENV = "Linux" |
| 22 | NINJA_BASE = "ninja" |
| 23 | NINJA_INSTALL_STR = "install/strip" |
| 24 | NINJA_VERBOSE = "" |
| 25 | # Android-termux will detect as Linux |
| 26 | SUPPORT_BUILD_ENV = ["Linux", "Windows", "Darwin"] |
| 27 | |
| 28 | # megcc runtime cross-build flags |
| 29 | CROSS_BUILD_TARGET_ARCH_LIST = [ |
| 30 | "x86_64", |
| 31 | "i386", |
| 32 | "aarch64", |
| 33 | "armv7-a", |
| 34 | "cortex-m", |
| 35 | "armv7-a-qemu", |
| 36 | "rv64gcv0p7", |
| 37 | "rv64norvv", |
| 38 | ] |
| 39 | # only config cross build target os, host build os, please check SUPPORT_BUILD_ENV |
| 40 | CROSS_BUILD_TARGET_OS_LIST = ["ANDROID", "LINUX", "IOS", "NOT_STANDARD_OS"] |
| 41 | CROSS_BUILD_TARGET_ARCH_OS_LIMIT = { |
| 42 | "ANDROID": ["x86_64", "i386", "aarch64", "armv7-a"], |
| 43 | # cross build for LINUX-arch, arch always not x86_64/i386 |
| 44 | "LINUX": ["aarch64", "armv7-a", "rv64gcv0p7", "rv64norvv"], |
| 45 | "IOS": ["aarch64", "armv7-a"], |
| 46 | "NOT_STANDARD_OS": CROSS_BUILD_TARGET_ARCH_LIST, |
| 47 | } |
| 48 | |
| 49 | def detect_build_env(self): |
| 50 | self.BUILD_ENV = platform.system() |
| 51 | assert (self.BUILD_ENV in self.SUPPORT_BUILD_ENV |
| 52 | ), "now only support build env at: {}".format( |
| 53 | self.SUPPORT_BUILD_ENV) |
| 54 | if self.BUILD_ENV == "Darwin": |
| 55 | READLINK = "greadlink" |
| 56 | elif self.BUILD_ENV == "Windows": |
| 57 | self.NINJA_BASE = "Ninja" |
| 58 | logging.debug("build runtime at host env: {}".format(self.BUILD_ENV)) |
| 59 | |
| 60 | def build(self): |
| 61 | self.detect_build_env() |
| 62 | parser = argparse.ArgumentParser( |
| 63 | formatter_class=argparse.RawTextHelpFormatter) |
| 64 | parser.add_argument( |
| 65 | "--cross_build", |
| 66 | action="store_true", |
| 67 | help= |
| 68 | "args for indicates cross build, when without this flags, means host build", |
| 69 | ) |
| 70 | parser.add_argument( |
| 71 | "--host_build_for_32bit", |
| 72 | action="store_true", |
| 73 | help="args for host build 32bit, only take effect for host build", |
| 74 | ) |
| 75 | parser.add_argument( |
| 76 | "--build_for_debug", |