Skip to content

Commit

Permalink
libhysteria2.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
UjuiUjuMandan committed Jan 3, 2025
1 parent 62e0511 commit 3bbfad3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
36 changes: 35 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
cd ${{ github.workspace }}/build/AndroidLibV2rayLite
bash compile-tun2socks.sh
tar -xvzf libtun2socks.so.tgz
cp -r libs/* ${{ github.workspace }}/V2rayNG/app/libs/
env:
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}

Expand All @@ -85,6 +84,41 @@ jobs:
fileName: 'libv2ray.aar'
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: |
cd ${{ github.workspace }}/hysteria
go build -v -o libs/$FOLDER/libhysteria2.so -trimpath -ldflags "-s -w -buildid=" ./app
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}

- name: Save libhysteria2
if: steps.cache-libtun2socks-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: Setup Java
uses: actions/setup-java@v4
with:
Expand Down
26 changes: 26 additions & 0 deletions libhysteria2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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"
)

for target in "${targets[@]}"; do
IFS=' ' read -r ndk_target goarch abi <<< "$target"

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
FOLDER=$abi

echo "Building for ${abi} with ${ndk_target} (${goarch})"

cd "hysteria" || exit
go build -v -o libs/$FOLDER/libhysteria2.so -trimpath -ldflags "-s -w -buildid=" ./app

echo "Built libhysteria2.so for ${abi}"
done

0 comments on commit 3bbfad3

Please sign in to comment.