Add a support to compile libzim for wasm.

`icu4c_wasm.patch` is build by :
 - Copying config.sub from liblzma source as new version of config.sub there
   knows about wasm architecture.
 - Copying `mh-linux` on `mh-unknown` as specified in (origin) `mh-unknown`.
   This is because icu4c configure doesn't detect `emscripten` platform and
   "fallback" to `mh-unknown`.
This commit is contained in:
Matthieu Gautier 2022-11-02 16:05:54 +01:00
parent b8c120b179
commit 180fb249f6
10 changed files with 3396 additions and 7 deletions

View File

@ -280,6 +280,7 @@ def make_deps_archive(target=None, name=None, full=False):
if (base_dir / "meson_cross_file.txt").exists():
files_to_archive.append(base_dir / "meson_cross_file.txt")
files_to_archive += HOME.glob("BUILD_*/android-ndk*")
files_to_archive += HOME.glob("BUILD_*/emsdk*")
if (BASE_DIR / "meson_cross_file.txt").exists():
files_to_archive.append(BASE_DIR / "meson_cross_file.txt")

View File

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

View File

@ -340,7 +340,7 @@ class MakeBuilder(Builder):
@property
def make_install_target(self):
if self.buildEnv.platformInfo.build == 'iOS':
if self.buildEnv.platformInfo.build in ('iOS', "wasm"):
return 'install'
return 'install-strip'

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -9,5 +9,6 @@ from . import (
ios,
native,
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')