Merge pull request #548 from kiwix/wasm

This commit is contained in:
Matthieu Gautier 2022-11-22 13:49:41 +01:00 committed by GitHub
commit 75ca8dcf2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 3476 additions and 45 deletions

View File

@ -6,9 +6,11 @@ from common import (
make_archive, make_archive,
create_desktop_image, create_desktop_image,
fix_macos_rpath, fix_macos_rpath,
upload_archive,
OS_NAME, OS_NAME,
PLATFORM_TARGET, PLATFORM_TARGET,
DESKTOP, DESKTOP,
DEV_BRANCH,
) )
if (PLATFORM_TARGET.startswith("android_") if (PLATFORM_TARGET.startswith("android_")
@ -32,14 +34,18 @@ elif PLATFORM_TARGET in ("win32_static", "armhf_static", "armhf_dyn", "i586_stat
TARGETS = ("kiwix-tools",) TARGETS = ("kiwix-tools",)
elif PLATFORM_TARGET == "flatpak": elif PLATFORM_TARGET == "flatpak":
TARGETS = ("kiwix-desktop",) TARGETS = ("kiwix-desktop",)
elif PLATFORM_TARGET == "wasm":
TARGETS = ("libzim", )
else: else:
TARGETS = ("libzim", "zim-tools", "libkiwix", "kiwix-tools") TARGETS = ("libzim", "zim-tools", "libkiwix", "kiwix-tools")
for target in TARGETS: for target in TARGETS:
run_kiwix_build(target, platform=PLATFORM_TARGET) run_kiwix_build(target, platform=PLATFORM_TARGET)
if target == "kiwix-desktop": if target == "kiwix-desktop":
create_desktop_image(make_release=False) archive = create_desktop_image(make_release=False)
else: else:
if PLATFORM_TARGET == "native_mixed" and OS_NAME == "osx": if PLATFORM_TARGET == "native_mixed" and OS_NAME == "osx":
fix_macos_rpath(target) fix_macos_rpath(target)
make_archive(target, make_release=False) archive = make_archive(target, make_release=False)
if archive:
upload_archive(archive, target, make_release=False, dev_branch=DEV_BRANCH)

View File

@ -38,6 +38,8 @@ elif PLATFORM_TARGET in ("win32_static", "armhf_static", "i586_static"):
TARGETS = ("kiwix-tools",) TARGETS = ("kiwix-tools",)
elif PLATFORM_TARGET == "flatpak": elif PLATFORM_TARGET == "flatpak":
TARGETS = ("kiwix-desktop",) TARGETS = ("kiwix-desktop",)
elif PLATFORM_TARGET == "wasm":
TARGETS = ("libzim", )
else: else:
TARGETS = ("libzim", "zim-tools", "libkiwix", "kiwix-tools") TARGETS = ("libzim", "zim-tools", "libkiwix", "kiwix-tools")

View File

@ -39,6 +39,11 @@ _ref = _environ.get("GITHUB_REF", "").split("/")[-1]
MAKE_RELEASE = re.fullmatch(r"r_[0-9]+", _ref) is not None MAKE_RELEASE = re.fullmatch(r"r_[0-9]+", _ref) is not None
MAKE_RELEASE = MAKE_RELEASE and (_environ.get('GITHUB_EVENT_NAME') != 'schedule') MAKE_RELEASE = MAKE_RELEASE and (_environ.get('GITHUB_EVENT_NAME') != 'schedule')
if not MAKE_RELEASE and _ref != "master":
DEV_BRANCH = _ref
else:
DEV_BRANCH = None
RELEASE_OS_NAME = "macos" if OS_NAME == "osx" else "linux" RELEASE_OS_NAME = "macos" if OS_NAME == "osx" else "linux"
PLATFORM_TO_RELEASE = { PLATFORM_TO_RELEASE = {
@ -51,13 +56,7 @@ PLATFORM_TO_RELEASE = {
"android_arm64": "android-arm64", "android_arm64": "android-arm64",
"android_x86": "android-x86", "android_x86": "android-x86",
"android_x86_64": "android-x86_64", "android_x86_64": "android-x86_64",
} "wasm": "wasm-emscripten",
LIB_PREFIX = {
"android_arm": "arm-linux-androideabi",
"android_arm64": "aarch64-linux-android",
"android_x86": "i686-linux-android",
"android_x86_64": "x86_64-linux-android",
} }
FLATPAK_HTTP_GIT_REMOTE = "https://github.com/flathub/org.kiwix.desktop.git" FLATPAK_HTTP_GIT_REMOTE = "https://github.com/flathub/org.kiwix.desktop.git"
@ -94,15 +93,12 @@ EXPORT_FILES = {
"libzim": ( "libzim": (
INSTALL_DIR, INSTALL_DIR,
( (
"lib/{libprefix}/libzim.so".format( "lib/*/libzim.a",
libprefix=LIB_PREFIX.get(PLATFORM_TARGET, "x86_64-linux-gnu"), "lib/*/libzim.so",
), "lib/*/libzim.so.{version}".format(
"lib/{libprefix}/libzim.so.{version}".format(
libprefix=LIB_PREFIX.get(PLATFORM_TARGET, "x86_64-linux-gnu"),
version=main_project_versions["libzim"] version=main_project_versions["libzim"]
), ),
"lib/{libprefix}/libzim.so.{version}".format( "lib/*/libzim.so.{version}".format(
libprefix=LIB_PREFIX.get(PLATFORM_TARGET, "x86_64-linux-gnu"),
version=main_project_versions["libzim"][0] version=main_project_versions["libzim"][0]
), ),
"lib/libzim.{}.dylib".format( "lib/libzim.{}.dylib".format(
@ -115,15 +111,11 @@ EXPORT_FILES = {
"libkiwix": ( "libkiwix": (
INSTALL_DIR, INSTALL_DIR,
( (
"lib/{libprefix}/libkiwix.so".format( "lib/*/libkiwix.so",
libprefix=LIB_PREFIX.get(PLATFORM_TARGET, "x86_64-linux-gnu"), "lib/*/libkiwix.so.{version}".format(
),
"lib/{libprefix}/libkiwix.so.{version}".format(
libprefix=LIB_PREFIX.get(PLATFORM_TARGET, "x86_64-linux-gnu"),
version=main_project_versions["libkiwix"] version=main_project_versions["libkiwix"]
), ),
"lib/{libprefix}/libkiwix.so.{version}".format( "lib/*/libkiwix.so.{version}".format(
libprefix=LIB_PREFIX.get(PLATFORM_TARGET, "x86_64-linux-gnu"),
version=main_project_versions["libkiwix"][0] version=main_project_versions["libkiwix"][0]
), ),
"include/kiwix/**/*.h" "include/kiwix/**/*.h"
@ -240,7 +232,7 @@ def upload(file_to_upload, host, dest_path):
subprocess.check_call(command) subprocess.check_call(command)
def upload_archive(archive, project, make_release): def upload_archive(archive, project, make_release, dev_branch=None):
if not archive.exists(): if not archive.exists():
print_message("No archive {} to upload!", archive) print_message("No archive {} to upload!", archive)
return return
@ -257,6 +249,9 @@ def upload_archive(archive, project, make_release):
else: else:
dest_path = dest_path + "nightly/" + DATE dest_path = dest_path + "nightly/" + DATE
if dev_branch:
dest_path = "/data/tmp/ci/" + dev_branch
else:
# Make the archive read only. This way, scp will preserve rights. # Make the archive read only. This way, scp will preserve rights.
# If somehow we try to upload twice the same archive, scp will fails. # If somehow we try to upload twice the same archive, scp will fails.
archive.chmod(0o444) archive.chmod(0o444)
@ -280,6 +275,7 @@ def make_deps_archive(target=None, name=None, full=False):
if (base_dir / "meson_cross_file.txt").exists(): if (base_dir / "meson_cross_file.txt").exists():
files_to_archive.append(base_dir / "meson_cross_file.txt") files_to_archive.append(base_dir / "meson_cross_file.txt")
files_to_archive += HOME.glob("BUILD_*/android-ndk*") files_to_archive += HOME.glob("BUILD_*/android-ndk*")
files_to_archive += HOME.glob("BUILD_*/emsdk*")
if (BASE_DIR / "meson_cross_file.txt").exists(): if (BASE_DIR / "meson_cross_file.txt").exists():
files_to_archive.append(BASE_DIR / "meson_cross_file.txt") files_to_archive.append(BASE_DIR / "meson_cross_file.txt")

View File

@ -14,6 +14,8 @@ from common import (
if PLATFORM_TARGET.startswith("android_") or PLATFORM_TARGET.startswith("iOS"): if PLATFORM_TARGET.startswith("android_") or PLATFORM_TARGET.startswith("iOS"):
TARGETS = ("libzim", "libkiwix") TARGETS = ("libzim", "libkiwix")
elif PLATFORM_TARGET == "wasm":
TARGETS = ("libzim", )
elif PLATFORM_TARGET.startswith("native_"): elif PLATFORM_TARGET.startswith("native_"):
if OS_NAME == "osx": if OS_NAME == "osx":
TARGETS = ("libzim", "zim-tools", "libkiwix") TARGETS = ("libzim", "zim-tools", "libkiwix")

View File

@ -38,6 +38,7 @@ jobs:
- native_dyn - native_dyn
- native_mixed - native_mixed
- native_desktop - native_desktop
- wasm
- armhf_static - armhf_static
- armhf_dyn - armhf_dyn
- i586_static - i586_static

View File

@ -148,3 +148,21 @@ class BuildEnv:
if cross_path: if cross_path:
env['PATH'] = ':'.join(self.platformInfo.get_bin_dir() + [env['PATH']]) env['PATH'] = ':'.join(self.platformInfo.get_bin_dir() + [env['PATH']])
return env return env
@property
def configure_wrapper(self):
wrapper = getattr(self.platformInfo, "configure_wrapper", "")
if wrapper:
return "{} ".format(wrapper)
else:
return ""
@property
def make_wrapper(self):
wrapper = getattr(self.platformInfo, "make_wrapper", "")
if wrapper:
return "{} ".format(wrapper)
else:
return ""

View File

@ -6,6 +6,7 @@ from . import (
aria2, aria2,
armhf, armhf,
docoptcpp, docoptcpp,
emsdk,
flatpak, flatpak,
gumbo, gumbo,
icu4c, icu4c,

View File

@ -12,6 +12,9 @@ class AllBaseDependencies(Dependency):
class Builder(NoopBuilder): class Builder(NoopBuilder):
@classmethod @classmethod
def get_dependencies(cls, platformInfo, allDeps): def get_dependencies(cls, platformInfo, allDeps):
if platformInfo.build == "wasm":
return ['zlib', 'lzma', 'zstd', 'icu4c', 'xapian-core']
base_deps = ['zlib', 'lzma', 'zstd', 'xapian-core', 'pugixml', 'libcurl', 'icu4c', 'mustache', 'libmicrohttpd', 'zim-testing-suite'] base_deps = ['zlib', 'lzma', 'zstd', 'xapian-core', 'pugixml', 'libcurl', 'icu4c', 'mustache', 'libmicrohttpd', 'zim-testing-suite']
# Add specific dependencies depending of the platform # Add specific dependencies depending of the platform
if platformInfo.build not in ('android', 'iOS'): if platformInfo.build not in ('android', 'iOS'):

View File

@ -70,8 +70,9 @@ class Source:
def _patch(self, context): def _patch(self, context):
context.try_skip(self.source_path) context.try_skip(self.source_path)
for p in self.patches: for p in self.patches:
with open(pj(SCRIPT_DIR, 'patches', p), 'r') as patch_input: patch_file_path = pj(SCRIPT_DIR, 'patches', p)
run_command("patch -p1", self.source_path, context, input=patch_input.read()) patch_command = "patch -p1 -i {patch}".format(patch=patch_file_path)
run_command(patch_command, self.source_path, context)
def command(self, name, function, *args): def command(self, name, function, *args):
print(" {} {} : ".format(name, self.name), end="", flush=True) print(" {} {} : ".format(name, self.name), end="", flush=True)
@ -339,7 +340,7 @@ class MakeBuilder(Builder):
@property @property
def make_install_target(self): def make_install_target(self):
if self.buildEnv.platformInfo.build == 'iOS': if self.buildEnv.platformInfo.build in ('iOS', "wasm"):
return 'install' return 'install'
return 'install-strip' return 'install-strip'
@ -368,8 +369,9 @@ class MakeBuilder(Builder):
def _configure(self, context): def _configure(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "{configure_script} {configure_option}" command = "{configure_wrapper}{configure_script} {configure_option}"
command = command.format( command = command.format(
configure_wrapper=self.buildEnv.configure_wrapper,
configure_script=pj(self.source_path, self.configure_script), configure_script=pj(self.source_path, self.configure_script),
configure_option=self.all_configure_option configure_option=self.all_configure_option
) )
@ -379,7 +381,8 @@ class MakeBuilder(Builder):
def _compile(self, context): def _compile(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make -j4 {make_target} {make_option}".format( command = "{make_wrapper}make -j4 {make_target} {make_option}".format(
make_wrapper=self.buildEnv.make_wrapper,
make_target=self.make_target, make_target=self.make_target,
make_option=self.make_option make_option=self.make_option
) )
@ -388,7 +391,8 @@ class MakeBuilder(Builder):
def _install(self, context): def _install(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make {make_install_target} {make_option}".format( command = "{make_wrapper}make {make_install_target} {make_option}".format(
make_wrapper=self.buildEnv.make_wrapper,
make_install_target=self.make_install_target, make_install_target=self.make_install_target,
make_option=self.make_option make_option=self.make_option
) )
@ -397,7 +401,9 @@ class MakeBuilder(Builder):
def _make_dist(self, context): def _make_dist(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make dist" command = "{make_wrapper}make dist".format(
make_wrapper=self.buildEnv.make_wrapper
)
env = self.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True) env = self.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
run_command(command, self.build_path, context, env=env) run_command(command, self.build_path, context, env=env)

View File

@ -0,0 +1,47 @@
import os
from .base import Dependency, ReleaseDownload, Builder
from kiwixbuild.utils import Remotefile, run_command, copy_tree
pj = os.path.join
class emsdk(Dependency):
dont_skip = True
neutral = False
name = 'emsdk'
class Source(ReleaseDownload):
archive = Remotefile('emsdk-3.1.24.tar.gz',
'1aa5365ccb2147701cc9d1e59a5a49577c1d6aea55da7c450df2d5ffa48b8a58',
'https://codeload.github.com/emscripten-core/emsdk/tar.gz/refs/tags/3.1.24')
@property
def source_dir(self):
return self.target.full_name()
class Builder(Builder):
@property
def install_path(self):
return self.build_path
def _copy_source(self, context):
context.try_skip(self.build_path)
copy_tree(self.source_path, self.build_path)
def _install(self, context):
context.try_skip(self.build_path)
command = "./emsdk install 3.1.24"
run_command(command, self.build_path, context)
def _activate(self, context):
context.try_skip(self.build_path)
command = "./emsdk activate 3.1.24"
run_command(command, self.build_path, context)
def build(self):
self.command('copy_source', self._copy_source)
self.command('install', self._install)
self.command('activate', self._activate)

View File

@ -18,7 +18,9 @@ class Icu(Dependency):
"icu4c_custom_data.patch", "icu4c_custom_data.patch",
"icu4c_noxlocale.patch", "icu4c_noxlocale.patch",
"icu4c_rpath.patch", "icu4c_rpath.patch",
"icu4c_build_config.patch"] "icu4c_build_config.patch",
"icu4c_wasm.patch"
]
class Builder(MakeBuilder): class Builder(MakeBuilder):
@ -42,6 +44,6 @@ class Icu(Dependency):
'native_static' if platformInfo.static else 'native_dyn') 'native_static' if platformInfo.static else 'native_dyn')
options += " --with-cross-build={} --disable-tools".format( options += " --with-cross-build={} --disable-tools".format(
icu_native_builder.build_path) icu_native_builder.build_path)
if platformInfo.build == 'android': if platformInfo.build in ('android', 'wasm'):
options += " --with-data-packaging=archive" options += " --with-data-packaging=archive"
return options return options

View File

@ -19,7 +19,7 @@ class Libzim(Dependency):
@classmethod @classmethod
def get_dependencies(cls, platformInfo, allDeps): def get_dependencies(cls, platformInfo, allDeps):
deps = ['lzma', 'zstd', 'xapian-core', 'icu4c'] deps = ['lzma', 'zstd', 'xapian-core', 'icu4c']
if platformInfo.build != 'flatpak': if platformInfo.name not in ('flatpak', 'wasm'):
deps.append('zim-testing-suite') deps.append('zim-testing-suite')
return deps return deps
@ -37,7 +37,9 @@ class Libzim(Dependency):
if platformInfo.name == "flatpak": if platformInfo.name == "flatpak":
config_options.append("--wrap-mode=nodownload") config_options.append("--wrap-mode=nodownload")
config_options.append("-Dtest_data_dir=none") config_options.append("-Dtest_data_dir=none")
else: if platformInfo.name == "wasm":
config_options.append("-Dexamples=false")
if platformInfo.name not in ("flatpak", "wasm"):
zim_testing_suite = get_target_step('zim-testing-suite', 'source') zim_testing_suite = get_target_step('zim-testing-suite', 'source')
config_options.append('-Dtest_data_dir={}'.format(zim_testing_suite.source_path)) config_options.append('-Dtest_data_dir={}'.format(zim_testing_suite.source_path))
return " ".join(config_options) return " ".join(config_options)

View File

@ -9,11 +9,20 @@ class lzma(Dependency):
name = 'lzma' name = 'lzma'
class Source(ReleaseDownload): class Source(ReleaseDownload):
archive = Remotefile('xz-5.2.4.tar.gz', archive = Remotefile('xz-5.2.6.tar.gz',
'b512f3b726d3b37b6dc4c8570e137b9311e7552e8ccbab4d39d47ce5f4177145' 'a2105abee17bcd2ebd15ced31b4f5eda6e17efd6b10f921a01cda4a44c91b3a0',
'https://altushost-swe.dl.sourceforge.net/project/lzmautils/xz-5.2.6.tar.gz'
) )
class Builder(MakeBuilder): class Builder(MakeBuilder):
@property @property
def configure_option(self): def configure_option(self):
return "--disable-xz --disable-xzdec" return ("--disable-xz "
"--disable-xzdec "
"--disable-lzmadec "
"--disable-lzmainfo "
"--disable-lzma-links "
"--disable-scripts "
"--disable-doc "
# "--disable-symbol-versions "
)

View File

@ -24,7 +24,7 @@ class Xapian(Dependency):
@classmethod @classmethod
def get_dependencies(cls, platformInfo, allDeps): def get_dependencies(cls, platformInfo, allDeps):
deps = ['zlib', 'lzma'] deps = ['zlib', 'lzma']
if (platformInfo.build == 'win32' if (platformInfo.build in ('win32', 'wasm')
or neutralEnv('distname') == 'Darwin'): or neutralEnv('distname') == 'Darwin'):
return deps return deps
return deps + ['uuid'] return deps + ['uuid']

File diff suppressed because it is too large Load Diff

View File

@ -9,5 +9,6 @@ from . import (
ios, ios,
native, native,
neutral, neutral,
win32 win32,
wasm
) )

View File

@ -0,0 +1,100 @@
from .base import PlatformInfo
from kiwixbuild.utils import pj
from kiwixbuild._global import get_target_step
class WasmPlatformInfo(PlatformInfo):
name = 'wasm'
static = True
build = 'wasm'
arch_full = 'wasm64-emscripten'
#arch_full = 'wasm64-linux'
toolchain_names = ['emsdk']
compatible_hosts = ['fedora', 'debian']
exe_wrapper_def = ""
def get_cross_config(self):
return {
'binaries': self.binaries,
'exe_wrapper_def': '',
'root_path': self.root_path,
'extra_libs': [],
'extra_cflags': [],
'host_machine': {
'system': 'emscripten',
'lsystem': 'emscripten',
'cpu_family': 'wasm64',
'cpu': 'wasm64',
'endian': 'little',
'abi': ''
}
}
@property
def wasm_sdk(self):
return get_target_step('emsdk', self.name)
@property
def install_path(self):
return self.wasm_sdk.install_path
@property
def root_path(self):
return self.install_path
@property
def binaries(self):
binaries = (('CC', 'emcc'),
('CXX', 'em++'),
('AR', 'emar'),
('STRIP', 'emstrip'),
('WINDRES', 'windres'),
('RANLIB', 'emranlib'),
('LD', 'wasm-ld'))
binaries = {k:pj(self.install_path, 'upstream', 'emscripten', v)
for k,v in binaries}
binaries['PKGCONFIG'] = 'pkg-config'
return binaries
@property
def configure_option(self):
#return ""
return '--host={}'.format(self.arch_full)
@property
def configure_wrapper(self):
return "emconfigure"
@property
def make_wrapper(self):
return "emmake"
def get_bin_dir(self):
return [pj(self.install_path, 'bin')]
def get_env(self):
env = super().get_env()
env['PATH'] = ':'.join([
env['PATH'],
self.install_path,
pj(self.install_path, 'upstream', 'emscripten'),
pj(self.install_path, 'node', '14.18.2_64bit', 'bin')
])
env['EMSDK'] = self.install_path
env['EMSDK_NODE'] = pj(self.install_path, 'node', '14.18.2_64bit', 'bin', 'node')
return env
def set_comp_flags(self, env):
super().set_comp_flags(env)
env['CFLAGS'] = " -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS']
env['CXXFLAGS'] = " -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS']
def set_compiler(self, env):
for k, v in self.binaries.items():
env[k] = v
def finalize_setup(self):
super().finalize_setup()
self.buildEnv.cmake_crossfile = self._gen_crossfile('cmake_cross_file.txt')
self.buildEnv.meson_crossfile = self._gen_crossfile('meson_cross_file.txt')

View File

@ -39,11 +39,11 @@ release_versions = {
# This is the "version" of the whole base_deps_versions dict. # This is the "version" of the whole base_deps_versions dict.
# Change this when you change base_deps_versions. # Change this when you change base_deps_versions.
base_deps_meta_version = '78' base_deps_meta_version = '79'
base_deps_versions = { base_deps_versions = {
'zlib' : '1.2.12', 'zlib' : '1.2.12',
'lzma' : '5.2.4', 'lzma' : '5.2.6',
'zstd' : '1.5.2', 'zstd' : '1.5.2',
'docoptcpp' : '0.6.2', 'docoptcpp' : '0.6.2',
'uuid' : '1.43.4', 'uuid' : '1.43.4',