|  | 
| 1 |  | -#!/bin/bash | 
| 2 |  | - | 
| 3 |  | -# In order to cross-compile node for Android using NDK, run: | 
| 4 |  | -#   source android-configure <path_to_ndk> [arch] | 
| 5 |  | -# | 
| 6 |  | -# By running android-configure with source, will allow environment variables to | 
| 7 |  | -# be persistent in current session. This is useful for installing native node | 
| 8 |  | -# modules with npm. Also, don't forget to set the arch in npm config using | 
| 9 |  | -# 'npm config set arch=<arch>' | 
| 10 |  | - | 
| 11 |  | -if [ $# -ne 3 ]; then | 
| 12 |  | -  echo "$0 should have 3 parameters: ndk_path, target_arch and sdk_version" | 
| 13 |  | -  return 1 | 
| 14 |  | -fi | 
| 15 |  | - | 
| 16 |  | -NDK_PATH=$1 | 
| 17 |  | -ARCH="$2" | 
| 18 |  | -ANDROID_SDK_VERSION=$3 | 
| 19 |  | - | 
| 20 |  | -if [ $ANDROID_SDK_VERSION -lt 24 ]; then | 
| 21 |  | -  echo "$ANDROID_SDK_VERSION should equal or later than 24 (Android 7.0)" | 
| 22 |  | -fi | 
| 23 |  | - | 
| 24 |  | -case $ARCH in | 
| 25 |  | -    arm) | 
| 26 |  | -        DEST_CPU="arm" | 
| 27 |  | -        TOOLCHAIN_NAME="armv7a-linux-androideabi" | 
| 28 |  | -        ;; | 
| 29 |  | -    x86) | 
| 30 |  | -        DEST_CPU="ia32" | 
| 31 |  | -        TOOLCHAIN_NAME="i686-linux-android" | 
| 32 |  | -        ;; | 
| 33 |  | -    x86_64) | 
| 34 |  | -        DEST_CPU="x64" | 
| 35 |  | -        TOOLCHAIN_NAME="x86_64-linux-android" | 
| 36 |  | -        ARCH="x64" | 
| 37 |  | -        ;; | 
| 38 |  | -    arm64|aarch64) | 
| 39 |  | -        DEST_CPU="arm64" | 
| 40 |  | -        TOOLCHAIN_NAME="aarch64-linux-android" | 
| 41 |  | -        ARCH="arm64" | 
| 42 |  | -        ;; | 
| 43 |  | -    *) | 
| 44 |  | -        echo "Unsupported architecture provided: $ARCH" | 
| 45 |  | -        return 1 | 
| 46 |  | -        ;; | 
| 47 |  | -esac | 
| 48 |  | - | 
| 49 |  | -HOST_OS="linux" | 
| 50 |  | -HOST_ARCH="x86_64" | 
| 51 |  | -export CC_host=$(command -v gcc) | 
| 52 |  | -export CXX_host=$(command -v g++) | 
| 53 |  | - | 
| 54 |  | -host_gcc_version=$($CC_host --version | grep gcc | awk '{print $NF}') | 
| 55 |  | -major=$(echo $host_gcc_version | awk -F . '{print $1}') | 
| 56 |  | -minor=$(echo $host_gcc_version | awk -F . '{print $2}') | 
| 57 |  | -if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || ( [ $major -eq 6 ] && [ $minor -lt 3 ] ); then | 
| 58 |  | -  echo "host gcc $host_gcc_version is too old, need gcc 6.3.0" | 
| 59 |  | -  return 1 | 
| 60 |  | -fi | 
| 61 |  | - | 
| 62 |  | -SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION" | 
| 63 |  | -TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH | 
| 64 |  | - | 
| 65 |  | -export PATH=$TOOLCHAIN/bin:$PATH | 
| 66 |  | -export CC=$TOOLCHAIN/bin/$SUFFIX-clang | 
| 67 |  | -export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++ | 
| 68 |  | - | 
| 69 |  | - | 
| 70 |  | -GYP_DEFINES="target_arch=$ARCH" | 
| 71 |  | -GYP_DEFINES+=" v8_target_arch=$ARCH" | 
| 72 |  | -GYP_DEFINES+=" android_target_arch=$ARCH" | 
| 73 |  | -GYP_DEFINES+=" host_os=$HOST_OS OS=android" | 
| 74 |  | -export GYP_DEFINES | 
| 75 |  | - | 
| 76 |  | -if [ -f "configure" ]; then | 
| 77 |  | -    ./configure \ | 
| 78 |  | -        --dest-cpu=$DEST_CPU \ | 
| 79 |  | -        --dest-os=android \ | 
| 80 |  | -        --without-snapshot \ | 
| 81 |  | -        --openssl-no-asm \ | 
| 82 |  | -        --cross-compiling | 
| 83 |  | -fi | 
|  | 1 | +#!/bin/sh | 
|  | 2 | + | 
|  | 3 | +# Locate an acceptable Python interpreter and then re-execute the script. | 
|  | 4 | +# Note that the mix of single and double quotes is intentional, | 
|  | 5 | +# as is the fact that the ] goes on a new line. | 
|  | 6 | +_=[ 'exec' '/bin/sh' '-c' ''' | 
|  | 7 | +command -v python3.10 >/dev/null && exec python3.10 "$0" "$@" | 
|  | 8 | +command -v python3.9 >/dev/null && exec python3.9 "$0" "$@" | 
|  | 9 | +command -v python3.8 >/dev/null && exec python3.8 "$0" "$@" | 
|  | 10 | +command -v python3.7 >/dev/null && exec python3.7 "$0" "$@" | 
|  | 11 | +command -v python3.6 >/dev/null && exec python3.6 "$0" "$@" | 
|  | 12 | +command -v python3 >/dev/null && exec python3 "$0" "$@" | 
|  | 13 | +exec python "$0" "$@" | 
|  | 14 | +''' "$0" "$@" | 
|  | 15 | +] | 
|  | 16 | +del _ | 
|  | 17 | + | 
|  | 18 | +import sys | 
|  | 19 | +try: | 
|  | 20 | +  from shutil import which | 
|  | 21 | +except ImportError: | 
|  | 22 | +  from distutils.spawn import find_executable as which | 
|  | 23 | + | 
|  | 24 | +print('Node.js android configure: Found Python {}.{}.{}...'.format(*sys.version_info)) | 
|  | 25 | +acceptable_pythons = ((3, 10), (3, 9), (3, 8), (3, 7), (3, 6)) | 
|  | 26 | +if sys.version_info[:2] in acceptable_pythons: | 
|  | 27 | +  import android_configure | 
|  | 28 | +else: | 
|  | 29 | +  python_cmds = ['python{}.{}'.format(*vers) for vers in acceptable_pythons] | 
|  | 30 | +  sys.stderr.write('Please use {}.\n'.format(' or '.join(python_cmds))) | 
|  | 31 | +  for python_cmd in python_cmds: | 
|  | 32 | +      python_cmd_path = which(python_cmd) | 
|  | 33 | +      if python_cmd_path and 'pyenv/shims' not in python_cmd_path: | 
|  | 34 | +        sys.stderr.write('\t{} {}\n'.format(python_cmd_path, ' '.join(sys.argv[:1]))) | 
|  | 35 | +  sys.exit(1) | 
0 commit comments