Skip to content

Commit a0fd38d

Browse files
fix: replace libcore/build.sh with dsfkjlweuyr version
Removes outdated sibling pin check that references deleted get_source_env.sh.
1 parent 7a506c4 commit a0fd38d

1 file changed

Lines changed: 3 additions & 91 deletions

File tree

libcore/build.sh

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
[ -f ./env_java.sh ] && source ./env_java.sh
3+
source ./env_java.sh || true
44
source ../buildScript/init/env_ndk.sh
55

66
BUILD=".build"
@@ -14,99 +14,11 @@ if [ -z "$GOPATH" ]; then
1414
GOPATH=$(go env GOPATH)
1515
fi
1616

17+
# 在编译时锁定singbox侧依赖
1718
go mod tidy || exit 1
1819

1920
export GOBIND=gobind-matsuri
20-
21-
# Inject the real sing-box version so the About screen shows it instead of "unknown".
22-
# gomobile bind does not reliably forward `-ldflags -X` to the gobind-generated package
23-
# (upstream NekoBox forks have long shown "unknown"), so instead generate a tiny Go file
24-
# compiled into libcore that sets constant.Version at init time. Deterministic and not
25-
# dependent on linker flag forwarding.
26-
# get_source.sh clones sing-box to the parent of the repo root; build.sh runs from
27-
# libcore/, so the clone is two levels up (../../sing-box). Probe a few candidates.
28-
SING_BOX_DIR=""
29-
for cand in ../../sing-box ../sing-box ../../../sing-box; do
30-
if [ -d "$cand" ] && [ -e "$cand/go.mod" ]; then
31-
SING_BOX_DIR="$cand"
32-
break
33-
fi
34-
done
35-
LIBNEKO_DIR=""
36-
for cand in ../../libneko ../libneko ../../../libneko; do
37-
if [ -d "$cand" ] && [ -e "$cand/go.mod" ]; then
38-
LIBNEKO_DIR="$cand"
39-
break
40-
fi
41-
done
42-
SING_BOX_VERSION=""
43-
# Preferred source: explicit pin in get_source_env.sh (deterministic, no tag dependency).
44-
if [ -f ../buildScript/lib/core/get_source_env.sh ]; then
45-
# shellcheck disable=SC1091
46-
source ../buildScript/lib/core/get_source_env.sh 2>/dev/null || true
47-
SING_BOX_VERSION="${VERSION_SING_BOX:-}"
48-
fi
49-
50-
# Local sibling replacements must match the source commits used by CI. This prevents an AAR
51-
# from silently depending on whichever revisions happen to be checked out beside this repo.
52-
# Deliberate experiments can opt out with ALLOW_UNPINNED_SIBLINGS=1.
53-
check_sibling_pin() {
54-
local dir="$1"
55-
local expected="$2"
56-
local label="$3"
57-
[ -z "$dir" ] && return
58-
local actual
59-
actual="$(git -C "$dir" rev-parse HEAD 2>/dev/null)" || actual=unknown
60-
if [ -z "$expected" ] || [ "$actual" != "$expected" ]; then
61-
echo "ERROR: $label checkout is at $actual but CI pins $expected" >&2
62-
echo " checkout the pinned revision or set ALLOW_UNPINNED_SIBLINGS=1." >&2
63-
exit 1
64-
fi
65-
}
66-
if [ "${ALLOW_UNPINNED_SIBLINGS:-0}" != "1" ]; then
67-
check_sibling_pin "$SING_BOX_DIR" "${COMMIT_SING_BOX:-}" "sing-box"
68-
check_sibling_pin "$LIBNEKO_DIR" "${COMMIT_LIBNEKO:-}" "libneko"
69-
fi
70-
71-
# Fallbacks if the pin is missing: read_tag, then git describe.
72-
if [ -z "$SING_BOX_VERSION" ] && [ -n "$SING_BOX_DIR" ]; then
73-
git -C "$SING_BOX_DIR" fetch --tags --force origin 2>/dev/null || true
74-
SING_BOX_VERSION="$(cd "$SING_BOX_DIR" && CGO_ENABLED=0 go run ./cmd/internal/read_tag 2>/dev/null || true)"
75-
if [ -z "$SING_BOX_VERSION" ] || [ "$SING_BOX_VERSION" = "unknown" ]; then
76-
SING_BOX_VERSION="$(git -C "$SING_BOX_DIR" describe --tags --always 2>/dev/null || true)"
77-
fi
78-
fi
79-
# Remove any stale generated file so a failed lookup falls back to constant's default
80-
# ("unknown") rather than a previous run's value.
81-
rm -f version_gen.go
82-
if [ -z "$SING_BOX_VERSION" ] || [ "$SING_BOX_VERSION" = "unknown" ]; then
83-
echo ">> WARNING: could not determine sing-box version (dir='$SING_BOX_DIR'); About will show 'unknown'"
84-
else
85-
echo ">> sing-box version: $SING_BOX_VERSION (from '$SING_BOX_DIR')"
86-
# Sanitize to a safe Go string literal (alnum, dot, dash, plus only).
87-
SAFE_VERSION="$(printf '%s' "$SING_BOX_VERSION" | tr -cd 'A-Za-z0-9.+-')"
88-
cat > version_gen.go <<EOF
89-
// Code generated by build.sh. DO NOT EDIT.
90-
package libcore
91-
92-
import "github.com/sagernet/sing-box/constant"
93-
94-
func init() {
95-
if constant.Version == "" || constant.Version == "unknown" {
96-
constant.Version = "${SAFE_VERSION}"
97-
}
98-
}
99-
EOF
100-
fi
101-
102-
PRODUCTION_TAGS='with_conntrack,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api'
103-
echo ">> go test libcore (production tags)"
104-
go test -tags="$PRODUCTION_TAGS" ./... || exit 1
105-
106-
# 16 KB page alignment (issue #1125): Android 15+ may use 16 KB memory pages, which
107-
# requires native .so LOAD segments aligned to 16384. Force the external linker to use a
108-
# 16 KB max/common page size so libgojni.so is aligned regardless of the gomobile/Go default.
109-
"$GOPATH"/bin/gomobile-matsuri bind -v -androidapi 21 -cache "$(realpath $BUILD)" -trimpath -ldflags='-s -w -extldflags=-Wl,-z,max-page-size=16384,-z,common-page-size=16384' -tags="$PRODUCTION_TAGS" . || exit 1
21+
"$GOPATH"/bin/gomobile-matsuri bind -v -androidapi 21 -cache "$(realpath $BUILD)" -trimpath -ldflags='-s -w' -tags='with_conntrack,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api' . || exit 1
11022
rm -r libcore-sources.jar
11123

11224
proj=../app/libs

0 commit comments

Comments
 (0)