Build and cache libhysteria2.so (#4226)

* add submodule apernet/hysteria

* remove libhysteria2 binary from git repo

* libhysteria2.sh

* ignore *.so
This commit is contained in:
ᡠᠵᡠᡳ ᡠᠵᡠ ᠮᠠᠨᡩ᠋ᠠᠨ 2025-01-04 10:49:04 +08:00 committed by GitHub
parent 26bee229a1
commit 7dbda3cee7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 66 additions and 4 deletions

View file

@ -17,6 +17,8 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
submodules: 'true'
- name: Prepare build dir - name: Prepare build dir
run: | run: |
@ -62,7 +64,6 @@ jobs:
cd ${{ github.workspace }}/build/AndroidLibV2rayLite cd ${{ github.workspace }}/build/AndroidLibV2rayLite
bash compile-tun2socks.sh bash compile-tun2socks.sh
tar -xvzf libtun2socks.so.tgz tar -xvzf libtun2socks.so.tgz
cp -r libs/* ${{ github.workspace }}/V2rayNG/app/libs/
env: env:
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
@ -75,7 +76,7 @@ jobs:
- name: Copy libtun2socks - name: Copy libtun2socks
run: | run: |
cp -r ${{ github.workspace }}/build/AndroidLibV2rayLite/libs/* ${{ github.workspace }}/V2rayNG/app/libs/ cp -r ${{ github.workspace }}/build/AndroidLibV2rayLite/libs ${{ github.workspace }}/V2rayNG/app
- name: Download libv2ray - name: Download libv2ray
uses: robinraju/release-downloader@v1 uses: robinraju/release-downloader@v1
@ -85,6 +86,44 @@ jobs:
fileName: 'libv2ray.aar' fileName: 'libv2ray.aar'
out-file-path: V2rayNG/app/libs/ out-file-path: V2rayNG/app/libs/
- name: Restore cached libhysteria2
id: cache-libhysteria2-restore
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/hysteria/libs
key: libhysteria2-${{ runner.os }}-${{ hashFiles('.git/modules/hysteria/HEAD') }}-${{ hashFiles('libhysteria.sh') }}
- name: Fetch Go version from AndroidLibXrayLite
if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true'
run: |
GO_VERSION=$(curl -sL https://github.com/2dust/AndroidLibXrayLite/raw/refs/heads/main/go.mod | sed -n -E 's/.*go ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p')
echo "Go version: $GO_VERSION"
echo "GO_VERSION=$GO_VERSION" >> $GITHUB_ENV
- name: Setup Golang
if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true'
uses: actions/setup-go@v5
with:
go-version: '${{ env.GO_VERSION }}'
- name: Build libhysteria2
if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true'
run: |
bash libhysteria2.sh
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
- name: Save libhysteria2
if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/hysteria/libs
key: libhysteria2-${{ runner.os }}-${{ hashFiles('.git/modules/hysteria/HEAD') }}-${{ hashFiles('libhysteria.sh') }}
- name: Copy libhysteria2
run: |
cp -r ${{ github.workspace }}/hysteria/libs ${{ github.workspace }}/V2rayNG/app
- name: Setup Java - name: Setup Java
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:

3
.gitignore vendored
View file

@ -3,5 +3,4 @@
V2rayNG/app/release/output.json V2rayNG/app/release/output.json
.idea/ .idea/
.gradle/ .gradle/
libtun2socks.so *.so
libhysteria2.so

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "hysteria"]
path = hysteria
url = https://github.com/apernet/hysteria

Binary file not shown.

1
hysteria Submodule

@ -0,0 +1 @@
Subproject commit 15e31d48a09af0835773bd5c62cedbb3fc0e351d

20
libhysteria2.sh Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
targets=(
"aarch64-linux-android21 arm64 arm64-v8a"
"armv7a-linux-androideabi21 arm armeabi-v7a"
"x86_64-linux-android21 amd64 x86_64"
"i686-linux-android21 386 x86"
)
cd "hysteria" || exit
for target in "${targets[@]}"; do
IFS=' ' read -r ndk_target goarch abi <<< "$target"
echo "Building for ${abi} with ${ndk_target} (${goarch})"
CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/${ndk_target}-clang" CGO_ENABLED=1 CGO_LDFLAGS="-Wl,-z,max-page-size=16384" GOOS=android GOARCH=$goarch go build -o libs/$abi/libhysteria2.so -trimpath -ldflags "-s -w -buildid=" ./app
echo "Built libhysteria2.so for ${abi}"
done