diff --git a/llvm-build/MakeLiblzma b/llvm-build/MakeLiblzma index 681fa4e1304f3fd528d85639633c7e5fa1e2f5b4..5a98a98e4f1f2a0c1ca710a28529338cb5032930 100644 --- a/llvm-build/MakeLiblzma +++ b/llvm-build/MakeLiblzma @@ -13,54 +13,93 @@ SYSROOT := INSTALL_DIR := +BUILD_DIR := TARGET_TRIPLE := CC := -SRCS := 7zAlloc.c 7zArcIn.c 7zBuf2.c 7zBuf.c 7zCrc.c 7zCrcOpt.c 7zDec.c 7zFile.c 7zStream.c Aes.c AesOpt.c Alloc.c Bcj2.c Bra86.c Bra.c BraIA64.c CpuArch.c Delta.c LzFind.c Lzma2Dec.c Lzma2Enc.c Lzma86Dec.c Lzma86Enc.c LzmaDec.c LzmaEnc.c LzmaLib.c Ppmd7.c Ppmd7Dec.c Ppmd7Enc.c Sha256.c Sha256Opt.c Sort.c Xz.c XzCrc64.c XzCrc64Opt.c XzDec.c XzEnc.c XzIn.c MtDec.c MtCoder.c LzFindMt.c LzFindOpt.c Threads.c +AR := +SRCS := 7zAlloc.c 7zArcIn.c 7zBuf2.c 7zBuf.c 7zCrc.c 7zCrcOpt.c 7zDec.c 7zFile.c 7zStream.c Alloc.c Bcj2.c Bra86.c Bra.c BraIA64.c CpuArch.c Delta.c LzFind.c Lzma2Dec.c Lzma2Enc.c Lzma86Dec.c Lzma86Enc.c LzmaDec.c LzmaEnc.c LzmaLib.c Ppmd7.c Ppmd7Dec.c Ppmd7Enc.c Sha256.c Sha256Opt.c Sort.c Xz.c XzCrc64.c XzCrc64Opt.c XzDec.c XzEnc.c XzIn.c MtDec.c MtCoder.c LzFindMt.c LzFindOpt.c Threads.c + SRC_PREFIX := LIB_VERSION := +C_CFLAGS_COMMON := -D_7ZIP_ST -Wall -Werror -Wno-empty-body -Wno-enum-conversion -Wno-logical-op-parentheses -Wno-self-assign -fPIC -fstack-protector-strong +C_CFLAGS_OHOS := -D_IS_TRY_USE_HW_SHA=0 -DZ7_AFFINITY_DISABLE -Wno-implicit-function-declaration +IS_STATIC := +ifeq ($(IS_STATIC), True) + LDFLAGS_IS_STATIC := -static + TARGET_NAME := liblzma.a +else + LDFLAGS_IS_STATIC := -shared + TARGET_NAME := liblzma.so +endif + +$(info TARGET TRIPLE:$(TARGET_TRIPLE)) ifeq ($(TARGET_TRIPLE),linux-x86_64) -CFLAGS := --target=x86_64-unknown-linux-gnu -D_7ZIP_ST -Wall -Werror -Wno-empty-body -Wno-enum-conversion -Wno-logical-op-parentheses -Wno-self-assign -fPIC -fstack-protector-strong +CFLAGS := --target=x86_64-unknown-linux-gnu $(C_CFLAGS_COMMON) LDFLAGS := -shared -fuse-ld=lld -Wl,-z,relro,-z,now -Wl,-z,noexecstack TARGET := liblzma.so else ifeq ($(TARGET_TRIPLE),windows-x86_64) -CFLAGS := --target=x86_64-pc-windows-gnu --sysroot=$(SYSROOT) -D_7ZIP_ST -Wall -Werror -Wno-empty-body -Wno-enum-conversion -Wno-logical-op-parentheses -Wno-self-assign -fPIC -fstack-protector-strong +CFLAGS := --target=x86_64-pc-windows-gnu --sysroot=$(SYSROOT) $(C_CFLAGS_COMMON) LDFLAGS := -shared -fuse-ld=lld --rtlib=compiler-rt -Wl,--out-implib=liblzma.dll.a TARGET := liblzma.dll TARGET_A := liblzma.dll.a else ifeq ($(findstring darwin,$(TARGET_TRIPLE)),darwin) SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path) -CFLAGS := -D_7ZIP_ST -Wall -Werror -Wno-empty-body -Wno-enum-conversion -Wno-logical-op-parentheses -Wno-self-assign -fPIC -current_version $(LIB_VERSION) -compatibility_version $(LIB_VERSION) -fstack-protector-strong +CFLAGS := $(C_CFLAGS_COMMON) -current_version $(LIB_VERSION) -compatibility_version $(LIB_VERSION) LDFLAGS := -dynamiclib -fuse-ld=lld -Wl,-syslibroot,$(SDKROOT) -install_name @rpath/liblzma.$(LIB_VERSION).dylib TARGET := liblzma.$(LIB_VERSION).dylib else +ifeq ($(TARGET_TRIPLE),arm-linux-ohos) +CFLAGS := --target=arm-linux-ohos -march=armv7-a -mfloat-abi=softfp --sysroot=$(SYSROOT) $(C_CFLAGS_COMMON) $(C_CFLAGS_OHOS) -I$(SYSROOT)/$(TARGET_TRIPLE)/usr/include +LDFLAGS := $(LDFLAGS_IS_STATIC) -fuse-ld=lld -Wl,-z,relro,-z,now -Wl,-z,noexecstack --sysroot=$(SYSROOT) -L$(SYSROOT)/$(TARGET_TRIPLE)/usr/lib -lc --rtlib=compiler-rt -lpthread -lunwind +TARGET := $(TARGET_NAME) +else +ifeq ($(TARGET_TRIPLE),aarch64-linux-ohos) +CFLAGS := --target=aarch64-linux-ohos --sysroot=$(SYSROOT) $(C_CFLAGS_COMMON) $(C_CFLAGS_OHOS) -I$(SYSROOT)/$(TARGET_TRIPLE)/usr/include +LDFLAGS := $(LDFLAGS_IS_STATIC) -fuse-ld=lld -Wl,-z,relro,-z,now -Wl,-z,noexecstack --sysroot=$(SYSROOT) -L$(SYSROOT)/$(TARGET_TRIPLE)/usr/lib -lc --rtlib=compiler-rt -lpthread -lunwind +TARGET := $(TARGET_NAME) +else $(warning *** warning: TARGET_TRIPLE $(TARGET_TRIPLE) has not been set in rights) endif endif endif +endif +endif lzma_header_install: @echo "begin header install" mkdir -p $(INSTALL_DIR)/include cp -rf $(SRC_PREFIX)* $(INSTALL_DIR)/include +ifeq ($(IS_STATIC), True) +# Compile the source file as .o +OBJECTS := $(addprefix $(BUILD_DIR)/, $(SRCS:.c=.o)) +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) +$(BUILD_DIR)/%.o: $(SRC_PREFIX)/%.c | $(BUILD_DIR) + $(CC) $(CFLAGS) -c $< -o $@ +# Link. o as a static library +$(TARGET): $(OBJECTS) lzma_header_install + $(AR) rc $(TARGET) $(OBJECTS) +else $(TARGET): lzma_header_install $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(addprefix $(SRC_PREFIX), $(SRCS)) +endif .PHONY: clean clean: - rm -f $(TARGET) $(SRC_PREFIX)*.o + rm -f $(TARGET) $(SRC_PREFIX)*.o $(BUILD_DIR)/*.o .PHONY:install install: $(TARGET) @echo "begin install" - mkdir -p $(INSTALL_DIR)/lib/$(TARGET_TRIPLE) - mv $(TARGET) $(INSTALL_DIR)/lib/$(TARGET_TRIPLE) + mkdir -p $(INSTALL_DIR)/lib + mv $(TARGET) $(INSTALL_DIR)/lib ifeq ($(TARGET_TRIPLE),windows-x86_64) - mv $(TARGET_A) $(INSTALL_DIR)/lib/$(TARGET_TRIPLE) + mv $(TARGET_A) $(INSTALL_DIR)/lib endif @echo "install success!" diff --git a/llvm-build/build.py b/llvm-build/build.py index 4459e122e246513bee70cb7f934ae74843ba1700..399ab6111ad801b005ef44b67b60c56e1e562fa6 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -686,6 +686,12 @@ class BuildUtils(object): prog = re.compile(r'#define MY_VERSION_NUMBERS "(.*?)"') return self.get_version(lzma_version_file, prog) + def merge_install_dir(self, name, platform_triple, *args): + return self.merge_out_path('third_party', name, 'install', platform_triple, *args) + + def merge_build_dir(self, name, platform_triple, *args): + return self.merge_out_path('third_party', name, 'build', platform_triple, *args) + def merge_ncurses_install_dir(self, platform_triple, *args): return self.merge_out_path('third_party', 'ncurses', 'install', platform_triple, *args) @@ -898,7 +904,7 @@ class LlvmCore(BuildUtils): llvm_defines['PANEL_LIBRARIES'] = ncurses_libs if self.build_config.enable_lzma_7zip: - llvm_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', self.use_platform(), 'liblzma.so') + llvm_defines['LIBLZMA_LIBRARIES'] = self.merge_install_dir('lzma', self.use_platform(), 'lib', 'liblzma.so') if self.build_config.build_libedit: llvm_defines['LibEdit_LIBRARIES'] = \ @@ -955,7 +961,7 @@ class LlvmCore(BuildUtils): if self.build_config.enable_lzma_7zip: llvm_defines['LLDB_ENABLE_LZMA'] = 'ON' llvm_defines['LLDB_ENABLE_LZMA_7ZIP'] = 'ON' - llvm_defines['LIBLZMA_INCLUDE_DIRS'] = self.merge_out_path('lzma', 'include') + llvm_defines['LIBLZMA_INCLUDE_DIRS'] = self.merge_install_dir('lzma', self.use_platform(), 'include') if self.build_config.build_libedit: llvm_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' @@ -1152,8 +1158,8 @@ class LlvmCore(BuildUtils): if self.build_config.enable_lzma_7zip: windows_defines['LLDB_ENABLE_LZMA'] = 'ON' windows_defines['LLDB_ENABLE_LZMA_7ZIP'] = 'ON' - windows_defines['LIBLZMA_INCLUDE_DIRS'] = self.merge_out_path('lzma', 'include') - windows_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', 'windows-x86_64', 'liblzma.dll.a') + windows_defines['LIBLZMA_INCLUDE_DIRS'] = self.merge_install_dir('lzma', 'windows-x86_64', 'include') + windows_defines['LIBLZMA_LIBRARIES'] = self.merge_install_dir('lzma', 'windows-x86_64', 'lib', 'liblzma.dll.a') def llvm_compile_windows_flags(self, windows_defines, @@ -1973,6 +1979,13 @@ class LlvmLibs(BuildUtils): lldb_defines['LIBXML2_INCLUDE_DIR'] = self.merge_libxml2_install_dir(llvm_triple, 'include', 'libxml2') lldb_defines['LIBXML2_LIBRARY'] = self.merge_libxml2_install_dir(llvm_triple, 'lib', 'libxml2.a') + if self.build_config.enable_lzma_7zip: + self.build_lzma(None, llvm_install, llvm_triple, True) + lldb_defines['LLDB_ENABLE_LZMA'] = 'ON' + lldb_defines['LLDB_ENABLE_LZMA_7ZIP'] = 'ON' + lldb_defines['LIBLZMA_INCLUDE_DIRS'] = self.merge_install_dir('lzma', llvm_triple, 'include') + lldb_defines['LIBLZMA_LIBRARIES'] = self.merge_install_dir('lzma', llvm_triple, 'lib', 'liblzma.a') + if self.build_config.lldb_timeout: lldb_defines['LLDB_ENABLE_TIMEOUT'] = 'True' @@ -2068,40 +2081,54 @@ class LlvmLibs(BuildUtils): self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_make) self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_install) - def build_lzma(self, llvm_make, llvm_install): + def build_lzma(self, llvm_make, llvm_install, platform_triple, static = False): self.logger().info('Building lzma') target_triple = self.use_platform() - liblzma_build_path = self.merge_out_path('lzma') - llvm_clang_prebuilts = os.path.abspath(os.path.join(self.buildtools_path, 'clang', 'ohos', self.use_platform(), + liblzma_install_path = self.merge_install_dir('lzma', platform_triple) + liblzma_build_path = self.merge_build_dir('lzma', platform_triple) + asm_source_dir = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'lzma', 'Asm') + sysroot = "" + asm_arc_dir = "" + ar = "" + if not platform_triple.endswith("ohos"): + if platform_triple.startswith("windows"): + llvm_clang_prebuilts = self.merge_out_path('llvm-install', 'bin', 'clang') + sysroot = self.merge_out_path('mingw', self.build_config.MINGW_TRIPLE) + target_triple = platform_triple + else: + llvm_clang_prebuilts = os.path.abspath(os.path.join(self.buildtools_path, 'clang', 'ohos', self.use_platform(), 'clang-%s' % self.build_config.CLANG_VERSION, 'bin', 'clang')) + else: + llvm_clang_prebuilts = self.merge_out_path('llvm-install', 'bin', 'clang') + sysroot = self.merge_out_path("sysroot") + ar = self.merge_out_path('llvm-install', 'bin', 'llvm-ar') + target_triple = platform_triple + if platform_triple.startswith("aarch64"): + asm_arc_dir = os.path.abspath(os.path.join(asm_source_dir, 'arm64')) + if platform_triple.startswith("arm"): + asm_arc_dir = os.path.abspath(os.path.join(asm_source_dir, 'arm')) + src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'lzma', 'C')) cmd = [ 'make', 'install', 'CC=%s' % llvm_clang_prebuilts, 'SRC_PREFIX=%s/' % src_dir, + 'ASM_PREFIX=%s/' % asm_arc_dir, + 'SYSROOT=%s' % sysroot, + 'AR=%s' % ar, 'TARGET_TRIPLE=%s' % target_triple, - 'INSTALL_DIR=%s' % liblzma_build_path, + 'INSTALL_DIR=%s' % liblzma_install_path, + 'BUILD_DIR=%s' % liblzma_build_path, 'LIB_VERSION=%s' % self.build_config.LZMA_VERSION, + 'IS_STATIC=%s' % static, '-f', 'MakeLiblzma'] os.chdir(self.build_config.LLVM_BUILD_DIR) self.check_call(cmd) - if self.host_is_darwin(): - shlib_ext = f'.{self.build_config.LZMA_VERSION}.dylib' - if self.host_is_linux(): - shlib_ext = '.so' - lzma_file = os.path.join(liblzma_build_path, 'lib', target_triple, 'liblzma' + shlib_ext) - - self.logger().info('Copy lzma to llvm make dir is %s', llvm_make) - lib_make_path = os.path.join(llvm_make, 'lib') - self.check_create_dir(lib_make_path) - self.check_copy_file(lzma_file, lib_make_path + '/liblzma' + shlib_ext) - - self.logger().info('Copy lzma to llvm install dir is %s', llvm_install) - lib_dst_path = os.path.join(llvm_install, 'lib') - self.check_create_dir(lib_dst_path) - self.check_copy_file(lzma_file, lib_dst_path + '/liblzma' + shlib_ext) + if not static: + self.llvm_package.copy_lzma_to_llvm(platform_triple, llvm_make) + self.llvm_package.copy_lzma_to_llvm(platform_triple, llvm_install) def build_libedit(self, llvm_make, llvm_install, platform_triple, static = False): self.logger().info('Building libedit') @@ -2663,7 +2690,7 @@ class LlvmPackage(BuildUtils): if self.build_config.enable_lzma_7zip: windows_additional_bin_files += ['liblzma%s' % shlib_ext] bin_root = os.path.join(install_dir, 'bin') - prebuild_dir = self.merge_out_path('lzma', 'lib', 'windows-x86_64', 'liblzma.dll') + prebuild_dir = self.merge_install_dir('lzma', 'windows-x86_64', 'lib', 'liblzma.dll') shutil.copyfile(prebuild_dir, os.path.join(bin_root, 'liblzma.dll')) new_necessary_bin_files = list(set(necessary_bin_files) - set(windows_forbidden_list_bin_files)) @@ -2834,6 +2861,25 @@ class LlvmPackage(BuildUtils): self.check_copy_file(libxml2_src, lib_dst_path) + def copy_lzma_to_llvm(self, platform_triple, install_dir): + self.logger().info('copy_lzma_to_llvm install_dir is %s', install_dir) + + if self.host_is_darwin(): + shlib_ext = [f'.{self.build_config.LZMA_VERSION}.dylib'] + if self.host_is_linux(): + shlib_ext = ['.so'] + if platform_triple.startswith("windows"): + shlib_ext = ['.dll'] + lzma_file = [self.merge_install_dir('lzma', platform_triple, 'lib', + f'liblzma{ext}') for ext in shlib_ext] + + lib_dst_path = os.path.join(install_dir, 'lib') + if not os.path.exists(lib_dst_path): + os.makedirs(lib_dst_path) + + for file in lzma_file: + self.check_copy_file(file, lib_dst_path) + # Packing Operation. def package_operation(self, build_dir, host): @@ -2986,7 +3032,7 @@ def main(): if build_config.LZMA_VERSION is None: raise Exception('Lzma version information not found, please check if the 7zVersion.h file exists') if build_config.enable_lzma_7zip: - llvm_libs.build_lzma(llvm_make, llvm_install) + llvm_libs.build_lzma(llvm_make, llvm_install, build_utils.use_platform()) build_config.LIBEDIT_VERSION = build_utils.get_libedit_version() if build_config.LIBEDIT_VERSION is None: @@ -3106,22 +3152,7 @@ def main(): if build_config.enable_lzma_7zip: build_utils.logger().info('build windows lzma') target_triple = 'windows-x86_64' - build_dir = build_utils.merge_out_path('lzma') - build_utils.check_create_dir(build_dir) - clang_path = build_utils.merge_out_path('llvm-install', 'bin', 'clang') - src_dir = os.path.abspath(os.path.join(build_config.REPOROOT_DIR, 'third_party', 'lzma', 'C')) - windows_sysroot = build_utils.merge_out_path('mingw', build_config.MINGW_TRIPLE) - cmd = [ 'make', - 'install', - 'CC=%s' % clang_path, - 'SRC_PREFIX=%s/' % src_dir, - 'SYSROOT=%s' % windows_sysroot, - 'TARGET_TRIPLE=%s' % target_triple, - 'INSTALL_DIR=%s' % build_dir, - '-f', - 'MakeLiblzma'] - os.chdir(build_config.LLVM_BUILD_DIR) - build_utils.check_call(cmd) + llvm_libs.build_lzma(build_utils.merge_out_path(target_triple), windows64_install, target_triple) llvm_core.llvm_compile_for_windows(build_config.TARGETS, build_config.enable_assertions, diff --git a/llvm-build/cross_toolchain_builder.py b/llvm-build/cross_toolchain_builder.py index 81f167f617eb295f51e24658d0e9c42adefa3691..7f2bb792fa7815e9bd22292ceb7e7e22f9719adc 100644 --- a/llvm-build/cross_toolchain_builder.py +++ b/llvm-build/cross_toolchain_builder.py @@ -177,6 +177,16 @@ class CrossToolchainBuilder: ) ) + if self._build_config.enable_lzma_7zip: + lldb_defines['LLDB_ENABLE_LZMA'] = 'ON' + lldb_defines['LLDB_ENABLE_LZMA_7ZIP'] = 'ON' + lldb_defines['LIBLZMA_INCLUDE_DIRS'] = ( + self._build_utils.merge_install_dir('lzma', self._llvm_triple, 'include') + ) + lldb_defines['LIBLZMA_LIBRARIES'] = ( + self._build_utils.merge_install_dir('lzma', self._llvm_triple, 'lib', 'liblzma.so') + ) + if self._build_config.build_python or self._install_python_from_prebuilts: lldb_defines["LLDB_ENABLE_PYTHON"] = "ON" lldb_defines["LLDB_EMBED_PYTHON_HOME"] = "ON" @@ -199,7 +209,6 @@ class CrossToolchainBuilder: ) lldb_defines['Python3_RPATH'] = os.path.join('$ORIGIN', '..', 'python3', 'lib') - lldb_defines["LLDB_ENABLE_LZMA"] = "OFF" # Debug & Tuning if self._build_config.enable_monitoring: lldb_defines["LLDB_ENABLE_PERFORMANCE"] = "ON" @@ -216,6 +225,8 @@ class CrossToolchainBuilder: if self._build_config.build_python: self._python_builder.build() self._python_builder.prepare_for_package() + if self._build_config.enable_lzma_7zip: + self._llvm_libs.build_lzma(self._llvm_path, self._llvm_install, self._llvm_triple) self._build_utils.invoke_cmake( self._llvm_project_path,