From 2a5a5c3a42626c2542eb438829a011170836eb8a Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 2 Nov 2023 17:33:51 +0100 Subject: [PATCH] Correctly build ICU data when building for wasm. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we use `--disable-tools` (ie, when we are cross-compiling), ICU will build the data only if it detects we are cross-compiling. This make sens until we cross-compiling for wasm. Wasm output is a script file with the interpreter in the sdk we have installed. So ICU's configure can run the test binary and so doesn't detect we are cross-compiling. So we have to patch ICU Makefile to make it build the ICU data anyway. --- kiwixbuild/dependencies/base.py | 2 ++ kiwixbuild/dependencies/icu4c.py | 11 +++++++++++ kiwixbuild/utils.py | 3 +++ 3 files changed, 16 insertions(+) diff --git a/kiwixbuild/dependencies/base.py b/kiwixbuild/dependencies/base.py index c0d6e93..a9136ec 100644 --- a/kiwixbuild/dependencies/base.py +++ b/kiwixbuild/dependencies/base.py @@ -283,6 +283,8 @@ class Builder: if hasattr(self, '_pre_build_script'): self.command('pre_build_script', self._pre_build_script) self.command('configure', self._configure) + if hasattr(self, '_post_configure_script'): + self.command('post_configure_script', self._post_configure_script) self.command('compile', self._compile) if hasattr(self, '_test'): self.command('test', self._test) diff --git a/kiwixbuild/dependencies/icu4c.py b/kiwixbuild/dependencies/icu4c.py index b5a1e6d..dfeabcd 100644 --- a/kiwixbuild/dependencies/icu4c.py +++ b/kiwixbuild/dependencies/icu4c.py @@ -7,6 +7,7 @@ from .base import ( from kiwixbuild.utils import pj, SkipCommand, Remotefile, extract_archive from kiwixbuild._global import get_target_step, neutralEnv import os, shutil +import fileinput class Icu(Dependency): name = "icu4c" @@ -77,3 +78,13 @@ class Icu(Dependency): def set_env(self, env): env['ICU_DATA_FILTER_FILE'] = pj(os.path.dirname(os.path.realpath(__file__)), "icu4c_data_filter.json") + + def _post_configure_script(self, context): + if self.buildEnv.platformInfo.build != "wasm": + context.skip() + context.try_skip(self.build_path) + for line in fileinput.input(pj(self.build_path, 'Makefile'), inplace=True): + if line == "#DATASUBDIR = data\n": + print("DATASUBDIR = data") + else: + print(line, end="") diff --git a/kiwixbuild/utils.py b/kiwixbuild/utils.py index 0c5d4ec..c0c0b4a 100644 --- a/kiwixbuild/utils.py +++ b/kiwixbuild/utils.py @@ -189,6 +189,9 @@ class Context: self.autoskip_file = None self.no_skip = False + def skip(self, msg=""): + raise SkipCommand(msg) + def try_skip(self, path, extra_name=""): if self.no_skip: return