From 71c52d9ee4c2282cc9876e2c763c7d70c358a06d Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 14 Apr 2017 14:04:37 +0200 Subject: [PATCH 1/4] Use the system declared in the cross-env in the cmake_cross_file template. Cmake use the 'Windows' name to detect we are building to Windows but meson use the lowered 'windows' string. So we need to lower the system declared in the cross-env when generating the meson cross_file. --- kiwix-build.py | 4 +++- templates/cmake_cross_file.txt | 4 ++-- templates/meson_cross_file.txt | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kiwix-build.py b/kiwix-build.py index d54923f..d8b594b 100755 --- a/kiwix-build.py +++ b/kiwix-build.py @@ -116,7 +116,8 @@ class TargetInfo: 'extra_libs': ['-lwinmm', '-lws2_32', '-lshlwapi', '-lrpcrt4', '-lmsvcr90'], 'extra_cflags': ['-DWIN32'], 'host_machine': { - 'system': 'windows', + 'system': 'Windows', + 'lsystem': 'windows', 'cpu_family': 'x86', 'cpu': 'i686', 'endian': 'little' @@ -148,6 +149,7 @@ class AndroidTargetInfo(TargetInfo): 'extra_cflags': [], 'host_machine': { 'system': 'Android', + 'lsystem': 'android', 'cpu_family': self.arch, 'cpu': self.cpu, 'endian': 'little' diff --git a/templates/cmake_cross_file.txt b/templates/cmake_cross_file.txt index 75a98a0..70184cf 100644 --- a/templates/cmake_cross_file.txt +++ b/templates/cmake_cross_file.txt @@ -1,5 +1,5 @@ -SET(CMAKE_SYSTEM_NAME Windows) -SET(CMAKE_SYSTEM_PROCESSOR x86) +SET(CMAKE_SYSTEM_NAME {host_machine[system]}) +SET(CMAKE_SYSTEM_PROCESSOR {host_machine[cpu_family]}) # specify the cross compiler SET(CMAKE_C_COMPILER "{toolchain.binaries[CC]}") diff --git a/templates/meson_cross_file.txt b/templates/meson_cross_file.txt index 9ea717f..dcc66ad 100644 --- a/templates/meson_cross_file.txt +++ b/templates/meson_cross_file.txt @@ -14,5 +14,5 @@ cpp_args = {extra_cflags!r} [host_machine] cpu_family = '{host_machine[cpu_family]}' cpu = '{host_machine[cpu]}' -system = '{host_machine[system]}' +system = '{host_machine[lsystem]}' endian = '{host_machine[endian]}' From 5957720a7d1554f0c5c84222b7a780877c231ef1 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 14 Apr 2017 14:31:50 +0200 Subject: [PATCH 2/4] Rename cross_env to cross_config. The dictionary is no more a environment. It is a full configuration dict. Rename it accordingly. --- kiwix-build.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kiwix-build.py b/kiwix-build.py index d8b594b..0ca5705 100755 --- a/kiwix-build.py +++ b/kiwix-build.py @@ -103,7 +103,7 @@ class TargetInfo: def __str__(self): return "{}_{}".format(self.build, 'static' if self.static else 'dyn') - def get_cross_env(self, host): + def get_cross_config(self, host): if self.build == 'native': return {} elif self.build == 'win32': @@ -143,7 +143,7 @@ class AndroidTargetInfo(TargetInfo): def __str__(self): return "android" - def get_cross_env(self, host): + def get_cross_config(self, host): return { 'extra_libs': [], 'extra_cflags': [], @@ -229,7 +229,7 @@ class BuildEnv: def setup_build(self, target_platform): self.platform_info = platform_info = self.target_platforms[target_platform] - self.cross_env = self.platform_info.get_cross_env(self.distname) + self.cross_config = self.platform_info.get_cross_config(self.distname) def setup_toolchains(self): toolchain_names = self.platform_info.toolchains @@ -250,7 +250,7 @@ class BuildEnv: template = f.read() content = template.format( toolchain=self.toolchains[0], - **self.cross_env + **self.cross_config ) with open(crossfile, 'w') as outfile: outfile.write(content) @@ -324,9 +324,9 @@ class BuildEnv: bin_dirs = [] if cross_compile_env: - for k, v in self.cross_env.get('env', {}).items(): + for k, v in self.cross_config.get('env', {}).items(): if k.startswith('_format_'): - v = v.format(**self.cross_env) + v = v.format(**self.cross_config) k = k[8:] env[k] = v for toolchain in self.toolchains: @@ -547,7 +547,7 @@ class mingw32_toolchain(Toolchain): @property def root_path(self): - return self.buildEnv.cross_env['root_path'] + return self.buildEnv.cross_config['root_path'] @property def binaries(self): @@ -574,7 +574,7 @@ class mingw32_toolchain(Toolchain): env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig') env['CFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS'] env['CXXFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS'] - env['LIBS'] = " ".join(self.buildEnv.cross_env['extra_libs']) + " " +env['LIBS'] + env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS'] class android_ndk(Toolchain): From 570170a92abf8cb7a7f0c53e249f0b1afca99f56 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 18 Apr 2017 11:46:58 +0200 Subject: [PATCH 3/4] Add armhf cross-compilation support. We directly use the cross-compilator provided by the raspberrypi project at https://github.com/raspberrypi/tools --- kiwix-build.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/kiwix-build.py b/kiwix-build.py index 0ca5705..36865b0 100755 --- a/kiwix-build.py +++ b/kiwix-build.py @@ -9,7 +9,7 @@ import platform from collections import OrderedDict from dependencies import Dependency -from dependency_utils import ReleaseDownload, Builder +from dependency_utils import ReleaseDownload, Builder, GitClone from utils import ( pj, remove_duplicates, @@ -60,6 +60,12 @@ PACKAGE_NAME_MAPPERS = { 'libmicrohttpd': None, # ['mingw32-libmicrohttpd-static'] packaging dependecy seems buggy, and some static lib are name libfoo.dll.a and # gcc cannot found them. }, + 'fedora_armhf_static': { + 'COMMON': ['cmake', 'automake', 'ccache'] + }, + 'fedora_armhf_dyn': { + 'COMMON': ['cmake', 'automake', 'ccache'] + }, 'fedora_android': { 'COMMON': ['gcc-c++', 'cmake', 'automake', 'ccache', 'java-1.8.0-openjdk-devel'] }, @@ -82,6 +88,12 @@ PACKAGE_NAME_MAPPERS = { 'debian_win32_static': { 'COMMON': ['g++-mingw-w64-i686', 'gcc-mingw-w64-i686', 'gcc-mingw-w64-base', 'mingw-w64-tools', 'cmake', 'ccache'] }, + 'debian_armhf_static': { + 'COMMON': ['cmake', 'automake', 'ccache'] + }, + 'debian_armhf_dyn': { + 'COMMON': ['cmake', 'automake', 'ccache'] + }, 'debian_android': { 'COMMON': ['automake', 'gcc', 'cmake', 'ccache', 'default-jdk'] }, @@ -121,9 +133,20 @@ class TargetInfo: 'cpu_family': 'x86', 'cpu': 'i686', 'endian': 'little' - } - } - + } + } + elif self.build == 'armhf': + return { + 'extra_libs': [], + 'extra_cflags': [], + 'host_machine': { + 'system': 'linux', + 'lsystem': 'linux', + 'cpu_family': 'arm', + 'cpu': 'armhf', + 'endian': 'little' + } + } class AndroidTargetInfo(TargetInfo): __arch_infos = { @@ -163,6 +186,8 @@ class BuildEnv: 'native_static': TargetInfo('native', True, []), 'win32_dyn': TargetInfo('win32', False, ['mingw32_toolchain']), 'win32_static': TargetInfo('win32', True, ['mingw32_toolchain']), + 'armhf_dyn': TargetInfo('armhf', False, ['armhf_toolchain']), + 'armhf_static': TargetInfo('armhf', True, ['armhf_toolchain']), 'android_arm': AndroidTargetInfo('arm'), 'android_arm64': AndroidTargetInfo('arm64'), 'android_mips': AndroidTargetInfo('mips'), @@ -264,6 +289,10 @@ class BuildEnv: self.cmake_crossfile = self._gen_crossfile('cmake_android_cross_file.txt') self.meson_crossfile = self._gen_crossfile('meson_cross_file.txt') + def setup_armhf(self): + self.cmake_crossfile = self._gen_crossfile('cmake_cross_file.txt') + self.meson_crossfile = self._gen_crossfile('meson_cross_file.txt') + def __getattr__(self, name): return getattr(self.options, name) @@ -752,6 +781,49 @@ class android_sdk(Toolchain): env['ANDROID_HOME'] = self.builder.install_path +class armhf_toolchain(Toolchain): + name = 'armhf' + arch_full = 'arm-linux-gnueabihf' + + class Source(GitClone): + git_remote = "https://github.com/raspberrypi/tools" + git_dir = "raspberrypi-tools" + + @property + def root_path(self): + return pj(self.source_path, 'arm-bcm2708', 'gcc-linaro-arm-linux-gnueabihf-raspbian-x64') + + @property + def binaries(self): + binaries = ((k,'{}-{}'.format(self.arch_full, v)) + for k, v in (('CC', 'gcc'), + ('CXX', 'g++'), + ('AR', 'ar'), + ('STRIP', 'strip'), + ('WINDRES', 'windres'), + ('RANLIB', 'ranlib'), + ('LD', 'ld')) + ) + return {k:pj(self.root_path, 'bin', v) + for k,v in binaries} + + @property + def configure_option(self): + return '--host={}'.format(self.arch_full) + + def get_bin_dir(self): + return [pj(self.root_path, 'bin')] + + def set_env(self, env): + env['CC'] = self.binaries['CC'] + env['CXX'] = self.binaries['CXX'] + + env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig') + env['CFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS'] + env['CXXFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS'] + env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS'] + + class Builder: def __init__(self, options): self.options = options From 07c3dbe8b950a7dfa52f17335bcf05aa6ae72bbc Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 18 Apr 2017 11:48:06 +0200 Subject: [PATCH 4/4] Compile and publish armhf architecture using travis CI. --- .travis.yml | 2 ++ travis/compile_all.sh | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index b72b72e..77eac45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,8 @@ env: - PLATFORM="native_static" - PLATFORM="win32_dyn" - PLATFORM="win32_static" + - PLATFORM="armhf_dyn" + - PLATFORM="armhf_static" - PLATFORM="android_arm" - PLATFORM="android_arm64" - PLATFORM="android_mips" diff --git a/travis/compile_all.sh b/travis/compile_all.sh index a7c5cc4..4f82e48 100755 --- a/travis/compile_all.sh +++ b/travis/compile_all.sh @@ -71,6 +71,14 @@ EOF tar -czf "${NIGHTLY_ARCHIVES_DIR}/$ARCHIVE_NAME" $FILES_LIST ) ;; + armhf_static) + ARCHIVE_NAME="kiwix-tools_armhf_$(date +%Y-%m-%d).tar.gz" + FILES_LIST="kiwix-install kiwix-manage kiwix-read kiwix-search kiwix-serve" + ( + cd ${BASE_DIR}/INSTALL/bin + tar -czf "${NIGHTLY_ARCHIVES_DIR}/$ARCHIVE_NAME" $FILES_LIST + ) + ;; android_*) APK_NAME="kiwix-${PLATFORM}" cp ${BASE_DIR}/kiwix-android/app/build/outputs/apk/app-kiwix-debug.apk ${NIGHTLY_ARCHIVES_DIR}/${APK_NAME}-debug.apk