mirror of
https://github.com/NoCrypt/migu.git
synced 2026-05-05 17:58:59 +00:00
feat(capacitor): utp native build
This commit is contained in:
parent
ee480d992b
commit
499d8aadbe
5 changed files with 79 additions and 55 deletions
|
|
@ -1,48 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# instructions
|
|
||||||
# Install Android NDK
|
|
||||||
# Set $ANDROID_NDK_PATH (example: ~/Android/Sdk/ndk/26.1.10909125)
|
|
||||||
# install other npm packages like normal
|
|
||||||
# run this script
|
|
||||||
|
|
||||||
toolchain_target_arch=aarch64
|
|
||||||
node_target_arch=arm64
|
|
||||||
android_api_level=22
|
|
||||||
toolchain_folder=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin
|
|
||||||
export LIBNODE_PATH=$(pwd)/git_modules/nodejs-mobile
|
|
||||||
|
|
||||||
export PATH=$toolchain_folder:$PATH
|
|
||||||
|
|
||||||
export CC=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang
|
|
||||||
export CXX=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang++
|
|
||||||
export LINK=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang++
|
|
||||||
export AR=$toolchain_folder/llvm-ar
|
|
||||||
|
|
||||||
export npm_config_verbose=1
|
|
||||||
export npm_config_nodedir=${LIBNODE_PATH}
|
|
||||||
export npm_config_node_gyp=$(pwd)/../node_modules/nodejs-mobile-gyp/bin/node-gyp.js
|
|
||||||
export npm_config_arch=${node_target_arch}
|
|
||||||
export npm_config_plaform=android
|
|
||||||
export npm_config_format=make-android
|
|
||||||
export npm_gyp_defines="target_arch=$node_target_arch v8_target_arch=$node_target_arch android_target_arch=$node_target_arch host_os=linux OS=android"
|
|
||||||
|
|
||||||
#mv node_modules ../node_modules.bak
|
|
||||||
# --from-from-source is used by node-pre-gyp
|
|
||||||
cd public/nodejs
|
|
||||||
npm rebuild --build-from-source
|
|
||||||
# Remove executable permissions from native node modules
|
|
||||||
# find node_modules -iname '*.node' -exec chmod -x '{}' \;
|
|
||||||
|
|
||||||
# buildroot=$(pwd)/ncc
|
|
||||||
# target=arm64-android
|
|
||||||
|
|
||||||
# buildpath="${buildroot}/${target}"
|
|
||||||
# if [ ! -d "${buildpath}" ]; then
|
|
||||||
# mkdir -p "${buildpath}"
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# ncc build --source-map -d --asset-builds --target es2022 -o ${buildpath} src/offline.ts
|
|
||||||
|
|
||||||
# rm -rf node_modules
|
|
||||||
# mv ../node_modules.bak node_modules
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "capacitor",
|
"name": "capacitor",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "cd public/nodejs/ && npm install",
|
"postinstall": "cd public/nodejs/ && npm install && docker build -t android-build:latest . && docker run -v ${PWD}:/app/ -it android-build:latest /bin/bash /app/setup-deps.sh",
|
||||||
"build:app": "cross-env NODE_ENV=production run-s build:web build:assets build:android",
|
"build:app": "cross-env NODE_ENV=production run-s build:web build:assets build:android",
|
||||||
"build:web": "webpack build",
|
"build:web": "webpack build",
|
||||||
"build:android": "cap build android",
|
"build:android": "cap build android",
|
||||||
|
|
|
||||||
23
capacitor/public/nodejs/Dockerfile
Normal file
23
capacitor/public/nodejs/Dockerfile
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
FROM alpine:3.19 AS worker
|
||||||
|
|
||||||
|
RUN apk add curl unzip
|
||||||
|
RUN curl -L https://github.com/nodejs-mobile/nodejs-mobile/releases/download/v18.17.2/nodejs-mobile-v18.17.2-android.zip -o libnode.zip
|
||||||
|
RUN unzip libnode.zip
|
||||||
|
|
||||||
|
FROM saschpe/android-ndk:33-jdk17.0.8_7-ndk25.2.9519653-cmake3.22.1
|
||||||
|
|
||||||
|
COPY --from=worker ./nodejs-mobile* /opt/libnode
|
||||||
|
ENV LIBNODE_PATH=/opt/libnode
|
||||||
|
|
||||||
|
# Install nodejs 18 (same version as nodejs-mobile)
|
||||||
|
ARG NODE_MAJOR=18
|
||||||
|
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y ca-certificates curl gnupg make
|
||||||
|
RUN mkdir -p /etc/apt/keyrings
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
||||||
|
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install nodejs -y
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
54
capacitor/public/nodejs/setup-deps.sh
Normal file
54
capacitor/public/nodejs/setup-deps.sh
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# instructions
|
||||||
|
# Install Android NDK
|
||||||
|
# Set $ANDROID_NDK_PATH (example: ~/Android/Sdk/ndk/26.1.10909125)
|
||||||
|
# Download and extract android .zip for nodejs-mobile from https://github.com/nodejs-mobile/nodejs-mobile/releases/tag/v18.17.2
|
||||||
|
# Update LIBNODE_PATH
|
||||||
|
# npm install nodejs-mobile-gyp
|
||||||
|
# install other npm packages like normal
|
||||||
|
# run this script
|
||||||
|
|
||||||
|
if [ -d "node_modules" ]; then
|
||||||
|
echo "node_modules already exists, skipping npm install"
|
||||||
|
else
|
||||||
|
npm install
|
||||||
|
fi
|
||||||
|
|
||||||
|
toolchain_folder=$NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin
|
||||||
|
export PATH=$toolchain_folder:$PATH
|
||||||
|
|
||||||
|
toolchain_target_archs=(armv7a aarch64 x86_64)
|
||||||
|
node_target_arch=(arm arm64 x64)
|
||||||
|
android_api_levels=(eabi24 "24" "24")
|
||||||
|
|
||||||
|
for ((i=0;i<${#toolchain_target_archs[@]};i++)); do
|
||||||
|
toolchain_target_arch=${toolchain_target_archs[i]}
|
||||||
|
node_target_arch=${node_target_arch[i]}
|
||||||
|
android_api_level=${android_api_levels[i]}
|
||||||
|
|
||||||
|
export CC=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang
|
||||||
|
export CXX=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang++
|
||||||
|
export LINK=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang++
|
||||||
|
export AR=$toolchain_folder/llvm-ar
|
||||||
|
|
||||||
|
export npm_config_verbose=1
|
||||||
|
export npm_config_nodedir=${LIBNODE_PATH}
|
||||||
|
export npm_config_node_gyp=$(pwd)/node_modules/nodejs-mobile-gyp/bin/node-gyp.js
|
||||||
|
export npm_config_arch=${node_target_arch}
|
||||||
|
export npm_config_plaform=android
|
||||||
|
export npm_config_format=make-android
|
||||||
|
export npm_gyp_defines="target_arch=$node_target_arch v8_target_arch=$node_target_arch android_target_arch=$node_target_arch host_os=linux OS=android"
|
||||||
|
|
||||||
|
# --from-from-source is used by node-pre-gyp
|
||||||
|
echo "Rebuilding for $node_target_arch"
|
||||||
|
npm rebuild --build-from-source
|
||||||
|
|
||||||
|
for file in node_modules/*/build/Release/*.node; do
|
||||||
|
package=$(echo "$file" | cut -f 2 -d "/")
|
||||||
|
echo "moving prebuild for $package ($file)"
|
||||||
|
mkdir "node_modules/$package/prebuilds/android-$node_target_arch"
|
||||||
|
mv $file "node_modules/$package/prebuilds/android-$node_target_arch/node.napi.node"
|
||||||
|
rm -r "node_modules/$package/build/"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
@ -122,12 +122,7 @@ function getFocusableElementPositions () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isInViewport ({ top, left, bottom, right }) {
|
function isInViewport ({ top, left, bottom, right }) {
|
||||||
return (
|
return top >= 0 && left >= 0 && bottom <= window.innerHeight && right <= window.innerWidth
|
||||||
top >= 0 &&
|
|
||||||
left >= 0 &&
|
|
||||||
bottom <= window.innerHeight &&
|
|
||||||
right <= window.innerWidth
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// function isVisible ({ top, left, bottom, right }, element) {
|
// function isVisible ({ top, left, bottom, right }, element) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue