diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e79433..7bee90b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,8 +33,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: Build - working-directory: scripts - run: bash -x ./build.sh + run: bash -x ./scripts/build.sh - name: Calculate MD5 checksum run: echo "MD5=$(md5sum libcore.aar | cut -d ' ' -f 1)" >> $GITHUB_ENV diff --git a/.gitignore b/.gitignore index e26bbe2..02e5628 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ binary*.go .vscode /debug.go .build +libneko +sing-box diff --git a/README.md b/README.md index c8bde10..4ec4a73 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,5 @@ ## Build ``` -cd ./scripts/ && bash -x ./build.sh +bash -x ./scripts/build.sh ``` diff --git a/go.mod b/go.mod index 28126cd..117b401 100644 --- a/go.mod +++ b/go.mod @@ -88,6 +88,5 @@ require ( lukechampine.com/blake3 v1.3.0 // indirect ) -replace github.com/matsuridayo/libneko => ../libneko - -replace github.com/sagernet/sing-box => ../sing-box +replace github.com/matsuridayo/libneko => ./libneko +replace github.com/sagernet/sing-box => ./sing-box diff --git a/scripts/build.sh b/scripts/build.sh index 73dfec6..8fa70ac 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash +SCRIPT_DIR="$(dirname $(readlink -f $0))" + set -e -source ./env.sh +source $SCRIPT_DIR/env.sh -bash ./sources.sh +bash $SCRIPT_DIR/sources.sh if [ -z "$GOPATH" ]; then GOPATH=$(go env GOPATH) @@ -12,6 +14,9 @@ fi PATH="$PATH:$GOPATH/bin" GOMOBILE_VERSION="v0.0.0-20231127183840-76ac6878050a" + +cd "$SCRIPT_DIR/../" + # Install gomobile if [ ! -f "$GOPATH/bin/gomobile" ]; then go get -v "golang.org/x/mobile@$GOMOBILE_VERSION" @@ -19,13 +24,10 @@ if [ ! -f "$GOPATH/bin/gomobile" ]; then fi gomobile init - -cd .. - gomobile bind -v \ -androidapi 21 \ -trimpath \ -ldflags='-s -w' \ -tags='with_conntrack,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,with_ech' . -rm -v "$GOPATH/bin/gomobile" "$GOPATH/bin/gobind" libcore-sources.jar +rm -v "$GOPATH/bin/gomobile" "$GOPATH/bin/gobind" "$SCRIPT_DIR/../libcore-sources.jar" diff --git a/scripts/sources.sh b/scripts/sources.sh index 7d13f04..b22a568 100644 --- a/scripts/sources.sh +++ b/scripts/sources.sh @@ -4,25 +4,22 @@ set -e COMMIT_SING_BOX="01b72e129794acae89e1c7929d0ba5a63b0e67f8" COMMIT_LIBNEKO="1c47a3af71990a7b2192e03292b4d246c308ef0b" +SCRIPT_DIR="$(dirname $(readlink -f $0))" -if [[ -d ../../sing-box ]]; then - if [[ "$(git -C ../../sing-box rev-parse HEAD)" != "$COMMIT_SING_BOX" ]]; then +if [[ -d "$SCRIPT_DIR/../sing-box" ]]; then + if [[ "$(git -C "$SCRIPT_DIR/../sing-box" rev-parse HEAD)" != "$COMMIT_SING_BOX" ]]; then echo "ERROR: Wrong 'sing-box' commit hash!" fi else - mkdir -v ../../sing-box && cd ../../sing-box - git clone --no-checkout https://github.com/MatsuriDayo/sing-box "$(pwd)" - git -c advice.detachedHead=false checkout "$COMMIT_SING_BOX" - cd - &>/dev/null + git clone --no-checkout https://github.com/MatsuriDayo/sing-box "$SCRIPT_DIR/../sing-box" + git --git-dir="$SCRIPT_DIR/../sing-box/.git" -C "$SCRIPT_DIR/../sing-box" -c advice.detachedHead=false checkout "$COMMIT_SING_BOX" fi -if [[ -d ../../libneko ]]; then - if [[ "$(git -C ../../libneko rev-parse HEAD)" != "$COMMIT_LIBNEKO" ]]; then +if [[ -d "$SCRIPT_DIR/../libneko" ]]; then + if [[ "$(git -C "$SCRIPT_DIR/../libneko" rev-parse HEAD)" != "$COMMIT_LIBNEKO" ]]; then echo "ERROR: Wrong 'libneko' commit hash!" fi else - mkdir -v ../../libneko && cd ../../libneko - git clone --no-checkout https://github.com/MatsuriDayo/libneko "$(pwd)" - git -c advice.detachedHead=false checkout "$COMMIT_LIBNEKO" - cd - &>/dev/null + git clone --no-checkout https://github.com/MatsuriDayo/libneko "$SCRIPT_DIR/../libneko" + git --git-dir="$SCRIPT_DIR/../libneko/.git" -C "$SCRIPT_DIR/../libneko" -c advice.detachedHead=false checkout "$COMMIT_LIBNEKO" fi