diff --git a/.github/workflows/build-gcc.yml b/.github/workflows/build-gcc.yml index 3877eef..3ce6139 100644 --- a/.github/workflows/build-gcc.yml +++ b/.github/workflows/build-gcc.yml @@ -18,7 +18,7 @@ jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -32,53 +32,61 @@ jobs: repository: zerotier/ZeroTierOne path: ZeroTierOne - - name: Checkout libnatpmp - uses: actions/checkout@v4 - with: - repository: miniupnp/libnatpmp - path: libnatpmp - # Runs a single command using the runners shell - name: Prepare GCC Toolchain run: | sudo apt-get install -qqy gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf g++-aarch64-linux-gnu g++-arm-linux-gnueabihf + rustup target add aarch64-unknown-linux-gnu - - name: Build for aarch64 + sudo dpkg --add-architecture arm64 + sudo mv build/sources.list /etc/apt/sources.list + sudo apt-get update -qqy + sudo apt-get install -qqy libssl-dev:arm64 + + - name: Patch ZeroTier for Cross-Compile + run: | + pip3 install toml + python3 build/build_helper.py + + - name: Build for Aarch64 run: | CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ - cd libnatpmp - make --silent CC=$CC natpmpc-shared - cd .. - cd ZeroTierOne - make --silent -j $(nproc) ZT_SSO_SUPPORTED=0 ZT_STATIC=1 ZT_DEBUG=0 CC=$CC CXX=$CXX LDFLAGS="-L../libnatpmp -s" DEFS="-I../libnatpmp" + mv make-linux.mk.aarch64 make-linux.mk + make clean + make --silent -j $(nproc) ZT_SSO_SUPPORTED=0 ZT_STATIC=1 ZT_DEBUG=0 CC="$CC -w" CXX="$CXX -w" LDFLAGS="-s" cd .. - mkdir -p magisk/zerotier/lib cp ZeroTierOne/zerotier-one magisk/zerotier cd magisk zip -q -r ../zerotier-magisk-aarch64-gcc.zip . - - name: Build for arm + - name: Build for Aarch64 with SSO run: | - PATH=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH - PATH=`pwd`/libnatpmp:$PATH - NDK_ROOT=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64 - - CC=arm-linux-gnueabihf-gcc - CXX=arm-linux-gnueabihf-g++ - - cd libnatpmp - make clean - make CC=$CC natpmpc-shared - cd .. + CC=aarch64-linux-gnu-gcc + CXX=aarch64-linux-gnu-g++ cd ZeroTierOne make clean - # sed -i "s/armv7ve/armv7a/g" make-linux.mk - make -j $(nproc) ZT_SSO_SUPPORTED=0 ZT_STATIC=1 ZT_DEBUG=0 CC=$CC CXX=$CXX LDFLAGS="-L../libnatpmp -s" DEFS="-I../libnatpmp" + make --silent -j $(nproc) ZT_STATIC=1 ZT_DEBUG=0 CC="$CC -w" CXX="$CXX -w" LDFLAGS="-s" + cd .. + + cp ZeroTierOne/zerotier-one magisk/zerotier + cd magisk + zip -q -r ../zerotier-magisk-aarch64-gcc-SSO.zip . + + - name: Build for Arm + run: | + CC=arm-linux-gnueabihf-gcc + CXX=arm-linux-gnueabihf-g++ + FLAGS="-w -fcompare-debug-second" + + cd ZeroTierOne + mv make-linux.mk.arm make-linux.mk + make clean + make --silent -j $(nproc) ZT_SSO_SUPPORTED=0 ZT_STATIC=1 ZT_DEBUG=0 CC="$CC $FLAGS" CXX="$CXX $FLAGS" LDFLAGS="-s" cd .. cp ZeroTierOne/zerotier-one magisk/zerotier/ @@ -87,7 +95,7 @@ jobs: - name: Get Date id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - name: Release uses: softprops/action-gh-release@v2 @@ -95,6 +103,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: files: | + zerotier-magisk-aarch64-gcc-SSO.zip zerotier-magisk-aarch64-gcc.zip zerotier-magisk-arm-gcc.zip tag_name: SNAPSHOT-GCC-${{ steps.date.outputs.date }} @@ -102,5 +111,5 @@ jobs: draft: false prerelease: true - - name: Debugging with tmate - uses: mxschmitt/action-tmate@v3.18 + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v3.18 diff --git a/.github/workflows/build-ndk.yml b/.github/workflows/build-ndk.yml index 8013449..6af5f61 100644 --- a/.github/workflows/build-ndk.yml +++ b/.github/workflows/build-ndk.yml @@ -48,7 +48,12 @@ jobs: wget -qO ndk.zip https://dl.google.com/android/repository/android-ndk-$ndk-linux.zip unzip -qq ndk.zip "android-ndk-$ndk/toolchains/*" && rm ndk.zip -f - - name: Build for aarch64 + - name: Patch ZeroTier for Cross-Compile + run: | + pip3 install toml + python3 build/build_helper.py + + - name: Build for Aarch64 run: | PATH=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH NDK_ROOT=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64 @@ -57,10 +62,12 @@ jobs: CXX=aarch64-linux-android$api_version-clang++ cd libnatpmp + make clean make --silent CC=$CC natpmpc-shared cd .. cd ZeroTierOne + make clean make --silent -j $(nproc) ZT_DEBUG=0 ZT_SSO_SUPPORTED=0 CC=$CC CXX=$CXX LDFLAGS="-L../libnatpmp" DEFS="-I../libnatpmp -D__GLIBC__=0" cd .. @@ -70,37 +77,33 @@ jobs: cd magisk zip -q -r ../zerotier-magisk-aarch64-ndk.zip . - # - name: Build for arm - # run: | - # PATH=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH - # PATH=`pwd`/libnatpmp:$PATH - # NDK_ROOT=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64 + - name: Build for Arm + run: | + PATH=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH + NDK_ROOT=`pwd`/android-ndk-$ndk/toolchains/llvm/prebuilt/linux-x86_64 - # CC=armv7a-linux-androideabi$api_version-clang - # CXX=armv7a-linux-androideabi$api_version-clang++ + CC=armv7a-linux-androideabi$api_version-clang + CXX=armv7a-linux-androideabi$api_version-clang++ - # cd libnatpmp - # make clean - # make CC=$CC natpmpc-shared - # cd .. + cd libnatpmp + make clean + make CC=$CC natpmpc-shared + cd .. - # cd ZeroTierOne - # make clean - # sed -i "s/armv7ve/armv7a/g" make-linux.mk - # make -j $(nproc) ZT_DEBUG=0 ZT_SSO_SUPPORTED=0 CC=$CC CXX=$CXX LDFLAGS="-L../libnatpmp" DEFS="-I../libnatpmp -D__GLIBC__=0" - # cd .. + cd ZeroTierOne + mv make-linux.mk.arm.ndk make-linux.mk + make clean + make -j $(nproc) ZT_DEBUG=0 ZT_SSO_SUPPORTED=0 CC=$CC CXX=$CXX LDFLAGS="-L../libnatpmp" DEFS="-I../libnatpmp -D__GLIBC__=0" + cd .. - # cp ZeroTierOne/zerotier-one magisk/zerotier/ - # cp $NDK_ROOT/sysroot/usr/lib/arm-linux-android/libc++_shared.so magisk/zerotier/lib - # cd magisk - # zip -q -r ../zerotier-magisk-arm-ndk.zip . - - # - name: Debugging with tmate - # uses: mxschmitt/action-tmate@v3.18 + cp ZeroTierOne/zerotier-one magisk/zerotier/ + cp $NDK_ROOT/sysroot/usr/lib/arm-linux-android/libc++_shared.so magisk/zerotier/lib + cd magisk + zip -q -r ../zerotier-magisk-arm-ndk.zip . - name: Get Date id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - name: Release uses: softprops/action-gh-release@v2 @@ -109,7 +112,11 @@ jobs: with: files: | zerotier-magisk-aarch64-ndk.zip + zerotier-magisk-arm-ndk.zip tag_name: SNAPSHOT-NDK-${{ steps.date.outputs.date }} name: SNAPSHOT-NDK-${{ steps.date.outputs.date }} draft: false prerelease: true + + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v3.18 diff --git a/README.md b/README.md index 9e6090a..bb3ac33 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ To restart, execute (in root) `sh /data/adb/zerotier/zerotier.sh restart`; An an ``` /data/adb/zerotier/ | - run/ - | | - pid # zerotier-one pid | | - pipe # pipe to service.sh | | - daemon.log # service.sh log | ` - zerotier.log # zerotier-one log diff --git a/README_ZH.md b/README_ZH.md index 5dc4a38..a794a51 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -33,7 +33,6 @@ ``` /data/adb/zerotier/ | - run/ - | | - pid # zerotier-one pid | | - pipe # pipe to service.sh | | - daemon.log # service.sh log | ` - zerotier.log # zerotier-one log diff --git a/build/build_helper.py b/build/build_helper.py new file mode 100644 index 0000000..394a322 --- /dev/null +++ b/build/build_helper.py @@ -0,0 +1,80 @@ +import toml + +# Patch ZeroTierOne/rustybits/zeroidc/Cargo.toml + +# > +ZeroTierOne/rustybits/zeroidc/Cargo.toml +# [dependencies] +# openssl-sys = {version = ">=0.9", features = ["vendored"]} + +cargo_toml_path = "ZeroTierOne/rustybits/zeroidc/Cargo.toml" +cargo_toml = toml.load(cargo_toml_path) +cargo_toml['dependencies']['openssl-sys'] = { 'version': ">=0.9", 'features': ["vendored"] } +with open(cargo_toml_path, 'w') as f: + toml.dump(cargo_toml, f) + +# ------------------------------------------------------------------------------------------------------- + +# Patch ZeroTierOne/rustybits/zeroidc/.cargo/config.toml + +# > +ZeroTierOne/rustybits/zeroidc/.cargo/config.toml +# [target.armv7-unknown-linux-gnueabihf] +# linker = "arm-linux-gnueabihf-gcc" +# rustflags = ["-C", "target-feature=+crt-static"] +# [target.aarch64-unknown-linux-gnu] +# linker = "aarch64-linux-gnu-gcc" +# rustflags = ["-C", "target-feature=+crt-static"] + +config_toml_path = "ZeroTierOne/rustybits/zeroidc/.cargo/config.toml" +config_toml = toml.load(config_toml_path) +config_toml['target']['armv7-unknown-linux-gnueabihf'] = { "linker": "arm-linux-gnueabihf-gcc" } +config_toml['target']['aarch64-unknown-linux-gnu'] = { "linker": "aarch64-linux-gnu-gcc" } +with open(config_toml_path, 'w') as f: + toml.dump(config_toml, f) + +# ------------------------------------------------------------------------------------------------------- + +# Patch make-linux.mk + +make_linux_path = 'ZeroTierOne/make-linux.mk' +with open(make_linux_path, 'r') as file: + data = file.read() + patch_aarch64 = data.replace( + '$(ZT_CARGO_FLAGS)', '$(ZT_CARGO_FLAGS) --target aarch64-unknown-linux-gnu --quiet' + ).replace( + 'rustybits/target/release/libzeroidc.a', 'rustybits/target/aarch64-unknown-linux-gnu/release/libzeroidc.a' + ) + patch_arm = data.replace( + "$(shell $(CC) -dumpmachine | cut -d '-' -f 1)", 'armhf' + ).replace( + 'override CFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s', + 'override CFLAGS+=-mfloat-abi=hard -march=armv7-a -marm -mfpu=vfp' + ).replace( + 'override CXXFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -fexceptions -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s', + 'override CFLAGS+=-mfloat-abi=hard -march=armv7-a -marm -mfpu=vfp -fexceptions' + ) + patch_arm_ndk = data.replace( + "$(shell $(CC) -dumpmachine | cut -d '-' -f 1)", 'armhf' + ).replace( + 'override CFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s', + 'override CFLAGS+=-mfloat-abi=hard -march=armv7-a -marm -mfpu=vfp' + ).replace( + 'override CXXFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -fexceptions -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s', + 'override CFLAGS+=-mfloat-abi=hard -march=armv7-a -marm -mfpu=vfp -fexceptions' + ) + + with open(make_linux_path + '.aarch64', 'w') as file: + file.write(patch_aarch64) + with open(make_linux_path + '.arm', 'w') as file: + file.write(patch_arm) + with open(make_linux_path + '.arm.ndk', 'w') as file: + file.write(patch_arm_ndk) + +# Patch ZeroTierOne/osdep/OSUtils.cpp + +osutil_path = 'ZeroTierOne/osdep/OSUtils.cpp' +with open(osutil_path, 'r') as file: + data = file.read().replace( + '/var/lib/zerotier-one', '/data/adb/zerotier/home' + ) +with open(osutil_path, 'w') as file: + file.write(data) \ No newline at end of file diff --git a/build/sources.list b/build/sources.list new file mode 100644 index 0000000..a69c48e --- /dev/null +++ b/build/sources.list @@ -0,0 +1,23 @@ +# refer to https://tauri.app/v1/guides/building/linux/#cross-compiling-tauri-applications-for-arm-based-devices + +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy main restricted +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy universe +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates universe +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy multiverse +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse +deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security main restricted +deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security universe +deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security multiverse + +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy universe +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates universe +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy multiverse +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates multiverse +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security universe +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse \ No newline at end of file diff --git a/magisk/service.sh b/magisk/service.sh index e2707ab..4dee64b 100644 --- a/magisk/service.sh +++ b/magisk/service.sh @@ -6,11 +6,13 @@ pipe=/data/adb/zerotier/run/pipe zerotier_log=/data/adb/zerotier/run/zerotier.log daemon_log=/data/adb/zerotier/run/daemon.log network_id_path=/sdcard/Android/zerotier/network_id.txt +temp_output=/data/adb/zerotier/run/temp.out pid=-1 log() { t=`date +"%m-%d %H:%M:%S.%3N"` echo "[$t][$$][L] $1" >> $daemon_log + echo $1 >> $temp_output } _stop() { pid=$(pidof zerotier-one) @@ -35,7 +37,7 @@ _stop() { _join() { nid=$(cat $network_id_path) - ./zerotier-cli -D./home join $nid >> $zerotier_log 2>&1 + ./zerotier-cli join $nid >> $zerotier_log 2>&1 if [ $? -ne 0 ]; then log "join network failed" @@ -50,7 +52,7 @@ _join() { _leave() { nid=$(cat $network_id_path) - ./zerotier-cli -D./home leave $nid >> $zerotier_log 2>&1 + ./zerotier-cli leave $nid >> $zerotier_log 2>&1 if [ $? -ne 0 ]; then log "leave network failed" @@ -62,7 +64,7 @@ _leave() { return 0 } __start() { - nohup ./zerotier-one -d home >> $zerotier_log 2>&1 & + nohup ./zerotier-one -d >> $zerotier_log 2>&1 & sleep 1 @@ -87,8 +89,7 @@ ip rule add from all lookup main pref 1 export LD_LIBRARY_PATH=/data/adb/zerotier/lib __start -sleep 1 -_join +(sleep 20 && _join) & while true do diff --git a/magisk/zerotier/zerotier.sh b/magisk/zerotier/zerotier.sh index d375773..23c7c80 100644 --- a/magisk/zerotier/zerotier.sh +++ b/magisk/zerotier/zerotier.sh @@ -1,5 +1,6 @@ #!/system/bin/sh pipe=/data/adb/zerotier/run/pipe +temp_output=/data/adb/zerotier/run/temp.out if [[ ! -p $pipe ]]; then echo "daemon not running" exit 1