Skip to content

Commit d7dbeb7

Browse files
committed
build and publish separate artifacts for NDK 27, 28, and 29 so decouple React Native's lagging toolchain from other downstream users like BabylonNative
1 parent abbf732 commit d7dbeb7

File tree

7 files changed

+195
-56
lines changed

7 files changed

+195
-56
lines changed

package.json

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,38 @@
2929
"bunWebKitRepo": "https://github.com/oven-sh/WebKit.git",
3030
"bunWebKitCommit": "26e6460697dab3e8681489ce67857434b2180e6f",
3131
"icuRelease": "release-74-2",
32-
"icuArchive": "icu4c-74_2-src.tgz"
32+
"icuArchive": "icu4c-74_2-src.tgz",
33+
"ndkVariants": [
34+
{
35+
"id": "ndk27",
36+
"label": "Android NDK r27",
37+
"npmPackage": "jsc-android-ndk27",
38+
"pkgRevisionPrefixes": ["27."],
39+
"buildSuffix": "ndk27",
40+
"distDir": "dist-ndk27",
41+
"distUnstrippedDir": "dist-ndk27.unstripped",
42+
"disableLoopVectorization": true
43+
},
44+
{
45+
"id": "ndk28c",
46+
"label": "Android NDK r28c",
47+
"npmPackage": "jsc-android",
48+
"pkgRevisionPrefixes": ["28.2."],
49+
"buildSuffix": "ndk28",
50+
"distDir": "dist-ndk28",
51+
"distUnstrippedDir": "dist-ndk28.unstripped",
52+
"default": true
53+
},
54+
{
55+
"id": "ndk29",
56+
"label": "Android NDK r29",
57+
"npmPackage": "jsc-android-ndk29",
58+
"pkgRevisionPrefixes": ["29."],
59+
"buildSuffix": "ndk29",
60+
"distDir": "dist-ndk29",
61+
"distUnstrippedDir": "dist-ndk29.unstripped"
62+
}
63+
]
3364
},
3465
"devDependencies": {
3566
"commander": "^12.1.0",

scripts/compile/common.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ process_switch_options() {
2626
}
2727

2828
if ! [[ $ROOTDIR ]]; then ROOTDIR=`pwd`; fi
29+
source $ROOTDIR/scripts/toolchain.sh
2930
ARCH=$JSC_ARCH
3031

3132
TARGETDIR=$ROOTDIR/build/target
@@ -101,8 +102,16 @@ DEBUG_SYMBOL_LEVEL="-g2"
101102
if [[ "$BUILD_TYPE" = "Release" ]]
102103
then
103104
FRAME_POINTER_FLAG="-fomit-frame-pointer"
104-
CFLAGS_BUILD_TYPE="-DNDEBUG -g0 -O2 -flto=thin"
105-
ICU_CFLAGS_BUILD_TYPE="-O2 -flto=thin"
105+
CFLAGS_BUILD_TYPE="-DNDEBUG -g0 -O2"
106+
ICU_CFLAGS_BUILD_TYPE="-O2"
107+
if [[ -n "$JSC_TOOLCHAIN_LTO_FLAG" ]]; then
108+
CFLAGS_BUILD_TYPE="$CFLAGS_BUILD_TYPE $JSC_TOOLCHAIN_LTO_FLAG"
109+
ICU_CFLAGS_BUILD_TYPE="$ICU_CFLAGS_BUILD_TYPE $JSC_TOOLCHAIN_LTO_FLAG"
110+
fi
111+
if [[ -n "$JSC_TOOLCHAIN_RELEASE_CFLAGS" ]]; then
112+
CFLAGS_BUILD_TYPE="$CFLAGS_BUILD_TYPE $JSC_TOOLCHAIN_RELEASE_CFLAGS"
113+
ICU_CFLAGS_BUILD_TYPE="$ICU_CFLAGS_BUILD_TYPE $JSC_TOOLCHAIN_RELEASE_CFLAGS"
114+
fi
106115
else
107116
FRAME_POINTER_FLAG="-fno-omit-frame-pointer"
108117
CFLAGS_BUILD_TYPE=""
@@ -117,9 +126,12 @@ COMMON_LDFLAGS=" \
117126
-Wl,--exclude-libs,libgcc.a \
118127
-Wl,--no-undefined \
119128
-Wl,-z,max-page-size=16384 \
120-
-flto=thin \
121129
"
122130

131+
if [[ "$BUILD_TYPE" = "Release" && -n "$JSC_TOOLCHAIN_RELEASE_LDFLAGS" ]]; then
132+
COMMON_LDFLAGS="$COMMON_LDFLAGS $JSC_TOOLCHAIN_RELEASE_LDFLAGS"
133+
fi
134+
123135
COMMON_CFLAGS=" \
124136
-fstack-protector \
125137
-ffunction-sections \
@@ -132,7 +144,6 @@ $FRAME_POINTER_FLAG \
132144
-DCUSTOMIZE_REACT_NATIVE \
133145
$SWITCH_COMMON_CFLAGS_INTL \
134146
$CFLAGS_BUILD_TYPE \
135-
-Wno-pass-failed=loop-vectorize \
136147
-D__ANDROID_MIN_SDK_VERSION__=${ANDROID_API} \
137148
"
138149

scripts/env.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22

33
export ROOTDIR=$PWD
44

5+
BUILD_VARIANT_SUFFIX=""
6+
if [[ -n "$JSC_BUILD_VARIANT" ]]; then
7+
BUILD_VARIANT_SUFFIX="-$JSC_BUILD_VARIANT"
8+
fi
9+
510
# Intermediated build target dir
6-
export TARGETDIR=$ROOTDIR/build/target
11+
export TARGETDIR=${TARGETDIR:-$ROOTDIR/build/target${BUILD_VARIANT_SUFFIX}}
712

813
# JSC shared library install dir
9-
export INSTALL_DIR=$ROOTDIR/build/compiled
14+
export INSTALL_DIR=${INSTALL_DIR:-$ROOTDIR/build/compiled${BUILD_VARIANT_SUFFIX}}
1015

1116
# JSC unstripped shared library install dir
12-
export INSTALL_UNSTRIPPED_DIR=$ROOTDIR/build/compiled.unstripped
17+
export INSTALL_UNSTRIPPED_DIR=${INSTALL_UNSTRIPPED_DIR:-$ROOTDIR/build/compiled.unstripped${BUILD_VARIANT_SUFFIX}}
1318

1419
# CPP runtime shared library install dir
15-
export INSTALL_CPPRUNTIME_DIR=$ROOTDIR/build/cppruntime
20+
export INSTALL_CPPRUNTIME_DIR=${INSTALL_CPPRUNTIME_DIR:-$ROOTDIR/build/cppruntime${BUILD_VARIANT_SUFFIX}}
1621

1722
# Install dir for i18n build variants
1823
export INSTALL_DIR_I18N_true=$INSTALL_DIR/intl

scripts/info.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ ROOTDIR=$PWD
55
WEBKIT_REPO="${npm_package_config_bunWebKitRepo:-https://github.com/oven-sh/WebKit.git}"
66
WEBKIT_COMMIT="${npm_package_config_bunWebKitCommit}"
77

8+
export JSC_TOOLCHAIN_SUPPRESS_LOG=1
9+
source $ROOTDIR/scripts/toolchain.sh
10+
unset JSC_TOOLCHAIN_SUPPRESS_LOG
11+
812
export REVISION=$(node -e "console.log(require('./package.json').version.split('.')[0])")
913
CONFIG=$(node -e "console.log(JSON.stringify(require('$ROOTDIR/package.json').config, null, 2))")
1014

@@ -27,5 +31,11 @@ printf "\n\n\n\n\n\t\t\tRevision: \x1B[32m$REVISION\x1B[0m\n\n\n"
2731
printf "WebKit repository:\n%s @ %s\n\n" "$WEBKIT_REPO" "${WEBKIT_COMMIT:-unknown}"
2832
printf "Upstream URL:\n%s\n\n" "$WEBKIT_URL"
2933
printf "Config:\n%s\n\n" "$CONFIG"
34+
printf "NDK variant: %s\n" "${JSC_TOOLCHAIN_VARIANT:-unknown}"
35+
if [[ -n "$JSC_TOOLCHAIN_NDK_REVISION" ]]; then
36+
printf "NDK revision: %s\n\n" "$JSC_TOOLCHAIN_NDK_REVISION"
37+
else
38+
printf "\n"
39+
fi
3040
printf "AppleWebKit version components:\n%s\n\n" "$APPLE_VERSION"
3141
printf "Size:\n$SIZE\n\n"

scripts/publish.js

Lines changed: 89 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const path = require('path');
1010
const rimraf = require('rimraf');
1111
const semver = require('semver');
1212

13-
if (!semver.satisfies(process.versions.node, '>= 10.12.0')) {
14-
console.log('Please execute this script with node version >= 10.12.0');
13+
if (!semver.satisfies(process.versions.node, '>= 16.7.0')) {
14+
console.log('Please execute this script with node version >= 16.7.0');
1515
process.exit(1);
1616
}
1717

@@ -23,49 +23,94 @@ commander
2323

2424
const artifactZipFile = verifyFile(commander.args[0], '<artifact_zip_file>');
2525
const rootDir = path.dirname(__dirname);
26+
const pkgJsonPath = path.join(rootDir, 'package.json');
27+
const packageTemplate = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
2628
const workDir = path.join(rootDir, 'build', 'publish');
2729
const distDir = path.join(rootDir, 'dist');
30+
2831
if (fs.existsSync(workDir)) {
2932
rimraf.sync(workDir);
3033
}
3134
fs.mkdirSync(workDir, {recursive: true});
3235

3336
child_process.execFileSync('unzip', [artifactZipFile, '-d', workDir]);
3437

35-
// Publish standard package
36-
console.log('\n\n========== Publish standard package ==========');
37-
createPatchedContext(rootDir, '', () => {
38-
if (fs.existsSync(distDir)) {
39-
rimraf.sync(distDir);
40-
}
41-
fs.renameSync(path.join(workDir, 'dist'), distDir);
42-
const publishArgs = ['publish', '--tag', commander.tag];
43-
if (commander.dryRun) {
44-
publishArgs.push('--dry-run');
45-
}
46-
child_process.execFileSync('npm', publishArgs);
47-
});
38+
const variantList = Array.isArray(packageTemplate.config?.ndkVariants)
39+
? packageTemplate.config.ndkVariants
40+
: [];
4841

49-
// Publish unstripped package
50-
// 1. Add suffix in version, e.g. 245459.0.0-unstripped
51-
// 2. Add suffix in tag, e.g. latest-unstripped
52-
// 3. Get unstripped distribution from dist.unstripped/ in CI archive.zip
53-
console.log('\n\n========== Publish unstripped package ==========');
54-
createPatchedContext(rootDir, 'unstripped', () => {
55-
if (fs.existsSync(distDir)) {
56-
rimraf.sync(distDir);
57-
}
58-
fs.renameSync(path.join(workDir, 'dist.unstripped'), distDir);
59-
const publishArgs = ['publish', '--tag', `${commander.tag}-unstripped`];
60-
if (commander.dryRun) {
61-
publishArgs.push('--dry-run');
62-
}
63-
child_process.execFileSync('npm', publishArgs);
42+
const variants =
43+
variantList.length > 0
44+
? [...variantList].sort((a, b) => {
45+
const aDefault = a && a.default ? 1 : 0;
46+
const bDefault = b && b.default ? 1 : 0;
47+
return bDefault - aDefault;
48+
})
49+
: [
50+
{
51+
id: 'default',
52+
npmPackage: packageTemplate.name,
53+
distDir: 'dist',
54+
distUnstrippedDir: 'dist.unstripped',
55+
},
56+
];
57+
58+
variants.forEach((variant) => {
59+
publishVariant(variant);
6460
});
6561

6662
// ---------------------------------------------------------------------------
6763
// Helper functions
6864
// ---------------------------------------------------------------------------
65+
function publishVariant(variant) {
66+
const displayName = variant?.id || 'default';
67+
console.log(`\n\n========== Publish ${displayName} package ==========`); // eslint-disable-line no-console
68+
69+
publishVariantFlavor(variant, {
70+
sourceDirName: variant.distDir || 'dist',
71+
versionSuffix: '',
72+
tagSuffix: '',
73+
});
74+
75+
publishVariantFlavor(variant, {
76+
sourceDirName: variant.distUnstrippedDir || 'dist.unstripped',
77+
versionSuffix: 'unstripped',
78+
tagSuffix: '-unstripped',
79+
});
80+
}
81+
82+
function publishVariantFlavor(variant, {sourceDirName, versionSuffix, tagSuffix}) {
83+
if (!sourceDirName) {
84+
return;
85+
}
86+
87+
const sourceDir = path.join(workDir, sourceDirName);
88+
if (!fs.existsSync(sourceDir)) {
89+
console.warn(
90+
`Skipping ${variant?.id || 'default'}${tagSuffix ? ` (${tagSuffix.replace('-', '')})` : ''} - missing directory ${sourceDirName}`,
91+
);
92+
return;
93+
}
94+
95+
createPatchedContext(rootDir, {variant, versionSuffix}, () => {
96+
if (fs.existsSync(distDir)) {
97+
rimraf.sync(distDir);
98+
}
99+
copyDir(sourceDir, distDir);
100+
const publishTag = tagSuffix ? `${commander.tag}${tagSuffix}` : commander.tag;
101+
const publishArgs = ['publish', '--tag', publishTag];
102+
if (commander.dryRun) {
103+
publishArgs.push('--dry-run');
104+
}
105+
child_process.execFileSync('npm', publishArgs, {stdio: 'inherit'});
106+
});
107+
}
108+
109+
function copyDir(source, destination) {
110+
fs.mkdirSync(path.dirname(destination), {recursive: true});
111+
fs.cpSync(source, destination, {recursive: true, force: true});
112+
}
113+
69114
function verifyFile(filePath, argName) {
70115
if (filePath == null) {
71116
console.error(`Error: ${argName} is required`);
@@ -88,12 +133,25 @@ function verifyFile(filePath, argName) {
88133
return filePath;
89134
}
90135

91-
function createPatchedContext(rootDir, versionSuffix, wrappedRunner) {
136+
function createPatchedContext(rootDir, options, wrappedRunner) {
137+
const {versionSuffix, variant} = options || {};
92138
const configPath = path.join(rootDir, 'package.json');
93139
const origConfig = fs.readFileSync(configPath);
94140

95141
function enter() {
96142
const patchedConfig = JSON.parse(origConfig);
143+
if (variant) {
144+
if (variant.npmPackage) {
145+
patchedConfig.name = variant.npmPackage;
146+
}
147+
patchedConfig.config = patchedConfig.config || {};
148+
if (variant.id) {
149+
patchedConfig.config.selectedNdkVariant = variant.id;
150+
}
151+
if (variant.npmPackage) {
152+
patchedConfig.config.selectedNdkPackage = variant.npmPackage;
153+
}
154+
}
97155
if (versionSuffix) {
98156
patchedConfig.version += '-' + versionSuffix;
99157
}

scripts/start.sh

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ if [[ -z "$ANDROID_NDK" || ! -d "$ANDROID_NDK" ]]; then
1616
export ANDROID_NDK="$DEFAULT_ANDROID_NDK"
1717
fi
1818

19+
export JSC_TOOLCHAIN_SUPPRESS_LOG=1
20+
source $ROOTDIR/scripts/toolchain.sh
21+
unset JSC_TOOLCHAIN_SUPPRESS_LOG
22+
1923
if [[ -z "$JAVA_HOME" || ! -x "$JAVA_HOME/bin/java" ]]; then
2024
if [[ "$(uname -s)" == "Darwin" ]]; then
2125
if command -v brew >/dev/null 2>&1; then
@@ -37,6 +41,17 @@ export JSC_VERSION=${npm_package_version}
3741
export BUILD_TYPE=Release
3842
# export BUILD_TYPE=Debug
3943

44+
STRIPPED_DIST_DIR=${JSC_DIST_DIR:-${ROOTDIR}/dist-ndk28}
45+
UNSTRIPPED_DIST_DIR=${JSC_DIST_UNSTRIPPED_DIR:-${ROOTDIR}/dist-ndk28.unstripped}
46+
47+
printf "Building with Android NDK variant: %s\n" "${JSC_TOOLCHAIN_VARIANT}"
48+
if [[ -n "$JSC_TOOLCHAIN_NDK_REVISION" ]]; then
49+
printf "Detected Android NDK revision: %s\n" "${JSC_TOOLCHAIN_NDK_REVISION}"
50+
fi
51+
printf "Using distribution directories:\n"
52+
printf " stripped : %s\n" "$STRIPPED_DIST_DIR"
53+
printf " unstripped : %s\n" "$UNSTRIPPED_DIST_DIR"
54+
4055
SCRIPT_DIR=$(cd `dirname $0`; pwd)
4156

4257
patchAndMakeICU() {
@@ -55,23 +70,28 @@ patchAndMakeICU() {
5570

5671
if [[ "$BUILD_TYPE" = "Release" ]]
5772
then
58-
local LTO_FLAG
59-
local EXTRA_FLAGS=""
73+
local opt_flags="-O2"
74+
local lto_flag=""
6075
if [[ $HAS_CLANG -eq 1 ]]; then
61-
LTO_FLAG="-flto=thin"
62-
EXTRA_FLAGS="-Wno-pass-failed=loop-vectorize"
63-
else
64-
LTO_FLAG="-flto"
76+
lto_flag="$JSC_TOOLCHAIN_LTO_FLAG"
77+
elif [[ -n "$JSC_TOOLCHAIN_LTO_FLAG" ]]; then
78+
lto_flag="-flto"
6579
fi
66-
67-
local OPT_FLAGS="-O2 $LTO_FLAG"
68-
if [[ -n "$EXTRA_FLAGS" ]]; then
69-
OPT_FLAGS="$OPT_FLAGS $EXTRA_FLAGS"
80+
if [[ -n "$lto_flag" ]]; then
81+
opt_flags="$opt_flags $lto_flag"
82+
fi
83+
if [[ -n "$JSC_TOOLCHAIN_RELEASE_CFLAGS" ]]; then
84+
opt_flags="$opt_flags $JSC_TOOLCHAIN_RELEASE_CFLAGS"
7085
fi
7186

72-
CFLAGS="$OPT_FLAGS"
73-
CXXFLAGS="-std=c++20 $OPT_FLAGS"
74-
LDFLAGS="$LTO_FLAG"
87+
CFLAGS="$opt_flags"
88+
CXXFLAGS="-std=c++20 $opt_flags"
89+
90+
local ldflags="$JSC_TOOLCHAIN_RELEASE_LDFLAGS"
91+
if [[ $HAS_CLANG -eq 0 && "$ldflags" == "-flto=thin" ]]; then
92+
ldflags="-flto"
93+
fi
94+
LDFLAGS="$ldflags"
7595
else
7696
CFLAGS="-g2"
7797
CXXFLAGS="-std=c++20"
@@ -180,14 +200,14 @@ if [[ "${SKIP_INTL}" != "1" ]]; then
180200
fi
181201

182202
printf "\n\n\t\t===================== create stripped distributions =====================\n\n"
183-
export DISTDIR=${ROOTDIR}/dist
203+
export DISTDIR=${STRIPPED_DIST_DIR}
184204
copyHeaders ${DISTDIR}
185205
createAAR "jsc-android" ${DISTDIR} ${INSTALL_DIR_I18N_false} "false"
186206
createAAR "jsc-android" ${DISTDIR} ${INSTALL_DIR_I18N_true} "true"
187207
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
188208

189209
printf "\n\n\t\t===================== create unstripped distributions =====================\n\n"
190-
export DISTDIR=${ROOTDIR}/dist.unstripped
210+
export DISTDIR=${UNSTRIPPED_DIST_DIR}
191211
copyHeaders ${DISTDIR}
192212
createAAR "jsc-android" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_false} "false"
193213
createAAR "jsc-android" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_true} "true"

0 commit comments

Comments
 (0)