From bad884a7c7f08560855d084c1b33997254ec115f Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Sun, 19 Mar 2023 00:08:48 +0800 Subject: [PATCH] Issue #2165 - Build ICU as a shared library if we're building Spidermonkey shared. It seems that if we're going to enable JS_SHARED_LIBRARY, we need ICU to be a shared library too in order to prevent code duplication in mozjs.dll bloating it to a whopping 21 MB. This unfortunately means we have to fold icudata back to icu itself. But since icudata is still separated from libxul (which is what really matters for #1451), I think this is a fair compromise. Building ICU as shared is offered as an option via --enable-shared-icu. But technically you really need --enable-shared-icu if you're going to use --enable-shared-js. Unfortunately I can't make configure exit with an error if MOZ_SHARED_ICU is not defined when JS_SHARED_LIBRARY is enabled, because options are controlled by different configure scripts (icu is based on bash, while js is based on python), and I have no idea how to pass MOZ_SHARED_ICU to js's moz.configure. Tag #62 --- build/autoconf/icu.m4 | 15 ++++++++------- build/moz.configure/old.configure | 1 + config/external/icu/moz.build | 5 +++-- intl/unicharutil/util/moz.build | 5 ++++- js/src/moz.build | 26 ++++++++++---------------- old-configure.in | 9 +++++---- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/build/autoconf/icu.m4 b/build/autoconf/icu.m4 index 090d6c0a2d..2530f6a69c 100644 --- a/build/autoconf/icu.m4 +++ b/build/autoconf/icu.m4 @@ -34,11 +34,10 @@ if test -n "$USE_ICU"; then ICU_DATA_FILE="icudt${version}l.dat" dnl We won't build ICU data as a separate file when building - dnl JS standalone so that embedders don't have to deal with it. - dnl We also don't do it on Windows because sometimes the file goes - dnl missing -- possibly due to overzealous antivirus software? -- - dnl which prevents the browser from starting up :( - if test -z "$JS_STANDALONE"; then + dnl ICU as a shared library, as we need to fold the data into + dnl the shared library in order for consumers like Spidermonkey + dnl to use it without code duplication. + if test -z "$MOZ_SHARED_ICU"; then MOZ_ICU_DATA_ARCHIVE=1 else MOZ_ICU_DATA_ARCHIVE= @@ -50,13 +49,15 @@ AC_SUBST(ENABLE_INTL_API) AC_SUBST(USE_ICU) AC_SUBST(ICU_DATA_FILE) AC_SUBST(MOZ_ICU_DATA_ARCHIVE) +AC_SUBST(MOZ_SHARED_ICU) if test -n "$USE_ICU"; then if test -z "$YASM" -a -z "$GNU_AS" -a "$COMPILE_ENVIRONMENT"; then AC_MSG_ERROR([Building ICU requires either yasm or a GNU assembler. If you do not have either of those available for this platform you must use --without-intl-api]) fi - dnl We build ICU as a static library. - AC_DEFINE(U_STATIC_IMPLEMENTATION) + if test -z "$MOZ_SHARED_ICU"; then + AC_DEFINE(U_STATIC_IMPLEMENTATION) + fi dnl Source files that use ICU should have control over which parts of the ICU dnl namespace they want to use. AC_DEFINE(U_USING_ICU_NAMESPACE,0) diff --git a/build/moz.configure/old.configure b/build/moz.configure/old.configure index 7953ac6232..fa08574833 100644 --- a/build/moz.configure/old.configure +++ b/build/moz.configure/old.configure @@ -226,6 +226,7 @@ def old_configure_options(*options): '--enable-safe-browsing', '--enable-sandbox', '--enable-security-sqlstore', + '--enable-shared-icu', '--enable-shared-media', '--enable-signmar', '--enable-simulator', diff --git a/config/external/icu/moz.build b/config/external/icu/moz.build index ba95cd0fb3..e403f17c78 100644 --- a/config/external/icu/moz.build +++ b/config/external/icu/moz.build @@ -3,8 +3,6 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -Library('icu') - DIRS += [ 'common', 'data', @@ -14,5 +12,8 @@ DIRS += [ if CONFIG['MOZ_ICU_DATA_ARCHIVE']: DIRS += ['stubdata'] USE_LIBS += ['icustubdata'] + Library('icu') else: USE_LIBS += ['icudata'] + SharedLibrary('icu') + SHARED_LIBRARY_NAME = 'icu' + CONFIG['MOZ_ICU_VERSION'] diff --git a/intl/unicharutil/util/moz.build b/intl/unicharutil/util/moz.build index cd32738134..64d455f91c 100644 --- a/intl/unicharutil/util/moz.build +++ b/intl/unicharutil/util/moz.build @@ -24,7 +24,10 @@ include('objs.mozbuild') UNIFIED_SOURCES += intl_unicharutil_util_cppsrcs -Library('unicharutil_external_s') +# This line breaks building ICU as a shared library due to a +# SandboxValidationError from the frontend reader. +if not CONFIG['MOZ_SHARED_ICU']: + Library('unicharutil_external_s') FORCE_STATIC_LIB = True diff --git a/js/src/moz.build b/js/src/moz.build index e14d59b350..115747daaf 100644 --- a/js/src/moz.build +++ b/js/src/moz.build @@ -611,27 +611,21 @@ if CONFIG['JS_SHARED_LIBRARY']: GeckoSharedLibrary('js', linkage=None) SHARED_LIBRARY_NAME = CONFIG['JS_LIBRARY_NAME'] SDK_LIBRARY = True - if CONFIG['MOZ_ICU_DATA_ARCHIVE']: - USE_LIBS += [ - 'icudata', - ] + USE_LIBS += [ + 'icu', + ] else: Library('js') FORCE_STATIC_LIB = True STATIC_LIBRARY_NAME = 'js_static' NO_EXPAND_LIBS = True - -if not CONFIG['MOZ_ICU_DATA_ARCHIVE']: - USE_LIBS += [ - 'icu', - ] -else: - # Linking 'icu' will pull in the stubdata library, - # which the shell doesn't want, so link the other bits. - USE_LIBS += [ - 'icui18n', - 'icuuc', - ] + if CONFIG['MOZ_ICU_DATA_ARCHIVE']: + # Linking 'icu' will pull in the stubdata library, + # which the shell doesn't want, so link the other bits. + USE_LIBS += [ + 'icui18n', + 'icuuc', + ] USE_LIBS += [ 'nspr', diff --git a/old-configure.in b/old-configure.in index aaabbba288..64e0dbc844 100644 --- a/old-configure.in +++ b/old-configure.in @@ -5144,12 +5144,13 @@ AC_SUBST(WIN32_REDIST_DIR) AC_SUBST(WIN_UCRT_REDIST_DIR) dnl ======================================================== -dnl ICU Support +dnl ICU Shared Library Support dnl ======================================================== -if test "$MOZ_WIDGET_TOOLKIT" = "cocoa"; then - USE_ICU=1 -fi +MOZ_ARG_ENABLE_BOOL(shared-icu, +[ --enable-shared-icu Build ICU as a shared library], + MOZ_SHARED_ICU=1, + MOZ_SHARED_ICU=) MOZ_CONFIG_ICU()