Skip to content

Commit 42e24f0

Browse files
committed
Add naiveproxy
1 parent 76d447d commit 42e24f0

File tree

20 files changed

+1486
-489
lines changed

20 files changed

+1486
-489
lines changed

.github/CRONET_GO_VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
412939539ebb2d273471120195b4531136b0ecac

.github/update_cronet.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
SCRIPT_DIR=$(dirname "$0")
6+
PROJECTS=$SCRIPT_DIR/../..
7+
8+
git -C $PROJECTS/cronet-go fetch origin main
9+
git -C $PROJECTS/cronet-go fetch origin go
10+
go get -x github.com/sagernet/cronet-go/all@$(git -C $PROJECTS/cronet-go rev-parse origin/go)
11+
go mod tidy
12+
git -C $PROJECTS/cronet-go rev-parse origin/HEAD > "$SCRIPT_DIR/CRONET_GO_VERSION"

.github/workflows/build.yml

Lines changed: 197 additions & 34 deletions
Large diffs are not rendered by default.

.github/workflows/docker.yml

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Publish Docker Images
22

33
on:
4+
push:
5+
branches:
6+
- main-next
7+
- dev-next
48
release:
59
types:
610
- published
@@ -13,8 +17,134 @@ env:
1317
REGISTRY_IMAGE: ghcr.io/sagernet/sing-box
1418

1519
jobs:
16-
build:
20+
build_binary:
21+
name: Build binary
1722
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: true
25+
matrix:
26+
include:
27+
# Naive-enabled builds (musl)
28+
- { arch: amd64, naive: true, docker_platform: "linux/amd64" }
29+
- { arch: arm64, naive: true, docker_platform: "linux/arm64" }
30+
- { arch: "386", naive: true, docker_platform: "linux/386" }
31+
- { arch: arm, goarm: "7", naive: true, docker_platform: "linux/arm/v7" }
32+
# Non-naive builds
33+
- { arch: arm, goarm: "6", docker_platform: "linux/arm/v6" }
34+
- { arch: ppc64le, docker_platform: "linux/ppc64le" }
35+
- { arch: riscv64, docker_platform: "linux/riscv64" }
36+
- { arch: s390x, docker_platform: "linux/s390x" }
37+
steps:
38+
- name: Get commit to build
39+
id: ref
40+
run: |-
41+
if [[ -z "${{ github.event.inputs.tag }}" ]]; then
42+
ref="${{ github.ref_name }}"
43+
else
44+
ref="${{ github.event.inputs.tag }}"
45+
fi
46+
echo "ref=$ref"
47+
echo "ref=$ref" >> $GITHUB_OUTPUT
48+
- name: Checkout
49+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
50+
with:
51+
ref: ${{ steps.ref.outputs.ref }}
52+
fetch-depth: 0
53+
- name: Setup Go
54+
uses: actions/setup-go@v5
55+
with:
56+
go-version: ^1.25.4
57+
- name: Clone cronet-go
58+
if: matrix.naive
59+
run: |
60+
set -xeuo pipefail
61+
CRONET_GO_VERSION=$(cat .github/CRONET_GO_VERSION)
62+
git init ~/cronet-go
63+
git -C ~/cronet-go remote add origin https://github.com/sagernet/cronet-go.git
64+
git -C ~/cronet-go fetch --depth=1 origin "$CRONET_GO_VERSION"
65+
git -C ~/cronet-go checkout FETCH_HEAD
66+
git -C ~/cronet-go submodule update --init --recursive --depth=1
67+
- name: Cache Chromium toolchain
68+
if: matrix.naive
69+
id: cache-chromium-toolchain
70+
uses: actions/cache@v4
71+
with:
72+
path: |
73+
~/cronet-go/naiveproxy/src/third_party/llvm-build/Release+Asserts
74+
~/cronet-go/naiveproxy/src/out/sysroot-build
75+
key: chromium-toolchain-${{ matrix.arch }}-musl-${{ hashFiles('.github/CRONET_GO_VERSION') }}
76+
- name: Download Chromium toolchain
77+
if: matrix.naive
78+
run: |
79+
set -xeuo pipefail
80+
cd ~/cronet-go
81+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} --libc=musl download-toolchain
82+
- name: Set Chromium toolchain environment
83+
if: matrix.naive
84+
run: |
85+
set -xeuo pipefail
86+
cd ~/cronet-go
87+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} --libc=musl env >> $GITHUB_ENV
88+
- name: Set build tags
89+
run: |
90+
set -xeuo pipefail
91+
TAGS='with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,badlinkname,tfogo_checklinkname0'
92+
if [[ "${{ matrix.naive }}" == "true" ]]; then
93+
TAGS="${TAGS},with_naive_outbound,with_musl"
94+
fi
95+
echo "BUILD_TAGS=${TAGS}" >> "${GITHUB_ENV}"
96+
- name: Set version
97+
run: |
98+
set -xeuo pipefail
99+
VERSION=$(go run ./cmd/internal/read_tag)
100+
echo "VERSION=${VERSION}" >> "${GITHUB_ENV}"
101+
- name: Build (naive)
102+
if: matrix.naive
103+
run: |
104+
set -xeuo pipefail
105+
go build -v -trimpath -o sing-box -tags "${BUILD_TAGS}" \
106+
-ldflags "-X \"github.com/sagernet/sing-box/constant.Version=${VERSION}\" -s -w -buildid= -checklinkname=0" \
107+
./cmd/sing-box
108+
env:
109+
CGO_ENABLED: "1"
110+
GOOS: linux
111+
GOARCH: ${{ matrix.arch }}
112+
GOARM: ${{ matrix.goarm }}
113+
- name: Build (non-naive)
114+
if: ${{ ! matrix.naive }}
115+
run: |
116+
set -xeuo pipefail
117+
go build -v -trimpath -o sing-box -tags "${BUILD_TAGS}" \
118+
-ldflags "-X \"github.com/sagernet/sing-box/constant.Version=${VERSION}\" -s -w -buildid= -checklinkname=0" \
119+
./cmd/sing-box
120+
env:
121+
CGO_ENABLED: "0"
122+
GOOS: linux
123+
GOARCH: ${{ matrix.arch }}
124+
GOARM: ${{ matrix.goarm }}
125+
- name: Prepare artifact
126+
run: |
127+
platform=${{ matrix.docker_platform }}
128+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
129+
# Rename binary to include arch info for Dockerfile.binary
130+
BINARY_NAME="sing-box-${{ matrix.arch }}"
131+
if [[ -n "${{ matrix.goarm }}" ]]; then
132+
BINARY_NAME="${BINARY_NAME}v${{ matrix.goarm }}"
133+
fi
134+
mv sing-box "${BINARY_NAME}"
135+
echo "BINARY_NAME=${BINARY_NAME}" >> $GITHUB_ENV
136+
- name: Upload binary
137+
uses: actions/upload-artifact@v4
138+
with:
139+
name: binary-${{ env.PLATFORM_PAIR }}
140+
path: ${{ env.BINARY_NAME }}
141+
if-no-files-found: error
142+
retention-days: 1
143+
build_docker:
144+
name: Build Docker image
145+
runs-on: ubuntu-latest
146+
needs:
147+
- build_binary
18148
strategy:
19149
fail-fast: true
20150
matrix:
@@ -47,6 +177,16 @@ jobs:
47177
run: |
48178
platform=${{ matrix.platform }}
49179
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
180+
- name: Download binary
181+
uses: actions/download-artifact@v5
182+
with:
183+
name: binary-${{ env.PLATFORM_PAIR }}
184+
path: .
185+
- name: Prepare binary
186+
run: |
187+
# Find and make the binary executable
188+
chmod +x sing-box-*
189+
ls -la sing-box-*
50190
- name: Setup QEMU
51191
uses: docker/setup-qemu-action@v3
52192
- name: Setup Docker Buildx
@@ -68,8 +208,7 @@ jobs:
68208
with:
69209
platforms: ${{ matrix.platform }}
70210
context: .
71-
build-args: |
72-
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
211+
file: Dockerfile.binary
73212
labels: ${{ steps.meta.outputs.labels }}
74213
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
75214
- name: Export digest
@@ -87,7 +226,7 @@ jobs:
87226
merge:
88227
runs-on: ubuntu-latest
89228
needs:
90-
- build
229+
- build_docker
91230
steps:
92231
- name: Get commit to build
93232
id: ref
@@ -121,13 +260,15 @@ jobs:
121260
username: ${{ github.repository_owner }}
122261
password: ${{ secrets.GITHUB_TOKEN }}
123262
- name: Create manifest list and push
263+
if: github.event_name != 'push'
124264
working-directory: /tmp/digests
125265
run: |
126266
docker buildx imagetools create \
127267
-t "${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.latest }}" \
128268
-t "${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.ref }}" \
129269
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
130270
- name: Inspect image
271+
if: github.event_name != 'push'
131272
run: |
132273
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.latest }}
133274
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.ref }}

.github/workflows/linux.yml

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Build Linux Packages
22

33
on:
4+
push:
5+
branches:
6+
- main-next
7+
- dev-next
48
workflow_dispatch:
59
inputs:
610
version:
@@ -52,11 +56,13 @@ jobs:
5256
strategy:
5357
matrix:
5458
include:
55-
- { os: linux, arch: amd64, debian: amd64, rpm: x86_64, pacman: x86_64 }
56-
- { os: linux, arch: "386", debian: i386, rpm: i386 }
59+
# Naive-enabled builds (musl)
60+
- { os: linux, arch: amd64, naive: true, debian: amd64, rpm: x86_64, pacman: x86_64 }
61+
- { os: linux, arch: arm64, naive: true, debian: arm64, rpm: aarch64, pacman: aarch64 }
62+
- { os: linux, arch: "386", naive: true, debian: i386, rpm: i386 }
63+
- { os: linux, arch: arm, goarm: "7", naive: true, debian: armhf, rpm: armv7hl, pacman: armv7hl }
64+
# Non-naive builds (unsupported architectures)
5765
- { os: linux, arch: arm, goarm: "6", debian: armel, rpm: armv6hl }
58-
- { os: linux, arch: arm, goarm: "7", debian: armhf, rpm: armv7hl, pacman: armv7hl }
59-
- { os: linux, arch: arm64, debian: arm64, rpm: aarch64, pacman: aarch64 }
6066
- { os: linux, arch: mips64le, debian: mips64el, rpm: mips64el }
6167
- { os: linux, arch: mipsle, debian: mipsel, rpm: mipsel }
6268
- { os: linux, arch: s390x, debian: s390x, rpm: s390x }
@@ -72,12 +78,37 @@ jobs:
7278
uses: actions/setup-go@v5
7379
with:
7480
go-version: ^1.25.4
75-
- name: Setup Android NDK
76-
if: matrix.os == 'android'
77-
uses: nttld/setup-ndk@v1
81+
- name: Clone cronet-go
82+
if: matrix.naive
83+
run: |
84+
set -xeuo pipefail
85+
CRONET_GO_VERSION=$(cat .github/CRONET_GO_VERSION)
86+
git init ~/cronet-go
87+
git -C ~/cronet-go remote add origin https://github.com/sagernet/cronet-go.git
88+
git -C ~/cronet-go fetch --depth=1 origin "$CRONET_GO_VERSION"
89+
git -C ~/cronet-go checkout FETCH_HEAD
90+
git -C ~/cronet-go submodule update --init --recursive --depth=1
91+
- name: Cache Chromium toolchain
92+
if: matrix.naive
93+
id: cache-chromium-toolchain
94+
uses: actions/cache@v4
7895
with:
79-
ndk-version: r28
80-
local-cache: true
96+
path: |
97+
~/cronet-go/naiveproxy/src/third_party/llvm-build/Release+Asserts
98+
~/cronet-go/naiveproxy/src/out/sysroot-build
99+
key: chromium-toolchain-${{ matrix.arch }}-musl-${{ hashFiles('.github/CRONET_GO_VERSION') }}
100+
- name: Download Chromium toolchain
101+
if: matrix.naive
102+
run: |
103+
set -xeuo pipefail
104+
cd ~/cronet-go
105+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} --libc=musl download-toolchain
106+
- name: Set Chromium toolchain environment
107+
if: matrix.naive
108+
run: |
109+
set -xeuo pipefail
110+
cd ~/cronet-go
111+
go run ./cmd/build-naive --target=linux/${{ matrix.arch }} --libc=musl env >> $GITHUB_ENV
81112
- name: Set tag
82113
run: |-
83114
git ls-remote --exit-code --tags origin v${{ needs.calculate_version.outputs.version }} || echo "PUBLISHED=false" >> "$GITHUB_ENV"
@@ -86,8 +117,26 @@ jobs:
86117
run: |
87118
set -xeuo pipefail
88119
TAGS='with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,badlinkname,tfogo_checklinkname0'
120+
if [[ "${{ matrix.naive }}" == "true" ]]; then
121+
TAGS="${TAGS},with_naive_outbound,with_musl"
122+
fi
89123
echo "BUILD_TAGS=${TAGS}" >> "${GITHUB_ENV}"
90-
- name: Build
124+
- name: Build (naive)
125+
if: matrix.naive
126+
run: |
127+
set -xeuo pipefail
128+
mkdir -p dist
129+
go build -v -trimpath -o dist/sing-box -tags "${BUILD_TAGS}" \
130+
-ldflags '-s -buildid= -X github.com/sagernet/sing-box/constant.Version=${{ needs.calculate_version.outputs.version }} -checklinkname=0' \
131+
./cmd/sing-box
132+
env:
133+
CGO_ENABLED: "1"
134+
GOOS: linux
135+
GOARCH: ${{ matrix.arch }}
136+
GOARM: ${{ matrix.goarm }}
137+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138+
- name: Build (non-naive)
139+
if: ${{ ! matrix.naive }}
91140
run: |
92141
set -xeuo pipefail
93142
mkdir -p dist
@@ -185,5 +234,6 @@ jobs:
185234
path: dist
186235
merge-multiple: true
187236
- name: Publish packages
237+
if: github.event_name != 'push'
188238
run: |-
189239
ls dist | xargs -I {} curl -F "package=@dist/{}" https://${{ secrets.FURY_TOKEN }}@push.fury.io/sagernet/

Dockerfile.binary

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM alpine
2+
ARG TARGETARCH
3+
ARG TARGETVARIANT
4+
LABEL maintainer="nekohasekai <[email protected]>"
5+
RUN set -ex \
6+
&& apk add --no-cache --upgrade bash tzdata ca-certificates nftables
7+
COPY sing-box-${TARGETARCH}${TARGETVARIANT} /usr/local/bin/sing-box
8+
ENTRYPOINT ["sing-box"]

cmd/internal/build_libbox/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func init() {
6262
sharedFlags = append(sharedFlags, "-ldflags", "-X github.com/sagernet/sing-box/constant.Version="+currentTag+" -s -w -buildid= -checklinkname=0")
6363
debugFlags = append(debugFlags, "-ldflags", "-X github.com/sagernet/sing-box/constant.Version="+currentTag+" -checklinkname=0")
6464

65-
sharedTags = append(sharedTags, "with_gvisor", "with_quic", "with_wireguard", "with_utls", "with_clash_api", "with_conntrack", "badlinkname", "tfogo_checklinkname0")
65+
sharedTags = append(sharedTags, "with_gvisor", "with_quic", "with_wireguard", "with_utls", "with_naive_outbound", "with_clash_api", "with_conntrack", "badlinkname", "tfogo_checklinkname0")
6666
macOSTags = append(macOSTags, "with_dhcp")
6767
memcTags = append(memcTags, "with_tailscale")
6868
notMemcTags = append(notMemcTags, "with_low_memory")

go.mod

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ require (
2525
github.com/sagernet/asc-go v0.0.0-20241217030726-d563060fe4e1
2626
github.com/sagernet/bbolt v0.0.0-20231014093535-ea5cb2fe9f0a
2727
github.com/sagernet/cors v1.2.1
28+
github.com/sagernet/cronet-go v0.0.1-140.0.7339.123-1
29+
github.com/sagernet/cronet-go/all v0.0.0-20251212080202-2e07958cfff6
2830
github.com/sagernet/fswatch v0.1.1
2931
github.com/sagernet/gomobile v0.1.8
3032
github.com/sagernet/gvisor v0.0.0-20250811.0-sing-box-mod.1
@@ -73,6 +75,7 @@ require (
7375
github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa // indirect
7476
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 // indirect
7577
github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e // indirect
78+
github.com/ebitengine/purego v0.9.1 // indirect
7679
github.com/fsnotify/fsnotify v1.7.0 // indirect
7780
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
7881
github.com/gaissmai/bart v0.18.0 // indirect
@@ -104,6 +107,24 @@ require (
104107
github.com/prometheus-community/pro-bing v0.4.0 // indirect
105108
github.com/quic-go/qpack v0.6.0 // indirect
106109
github.com/safchain/ethtool v0.3.0 // indirect
110+
github.com/sagernet/cronet-go/lib/android_386 v0.0.0-20251212075915-914a764300d6 // indirect
111+
github.com/sagernet/cronet-go/lib/android_amd64 v0.0.0-20251212075915-914a764300d6 // indirect
112+
github.com/sagernet/cronet-go/lib/android_arm v0.0.0-20251212075915-914a764300d6 // indirect
113+
github.com/sagernet/cronet-go/lib/android_arm64 v0.0.0-20251212075915-914a764300d6 // indirect
114+
github.com/sagernet/cronet-go/lib/darwin_amd64 v0.0.0-20251212075915-914a764300d6 // indirect
115+
github.com/sagernet/cronet-go/lib/darwin_arm64 v0.0.0-20251212075915-914a764300d6 // indirect
116+
github.com/sagernet/cronet-go/lib/ios_arm64 v0.0.0-20251212075915-914a764300d6 // indirect
117+
github.com/sagernet/cronet-go/lib/linux_386 v0.0.0-20251212075915-914a764300d6 // indirect
118+
github.com/sagernet/cronet-go/lib/linux_386_musl v0.0.0-20251212075915-914a764300d6 // indirect
119+
github.com/sagernet/cronet-go/lib/linux_amd64 v0.0.0-20251212075915-914a764300d6 // indirect
120+
github.com/sagernet/cronet-go/lib/linux_amd64_musl v0.0.0-20251212075915-914a764300d6 // indirect
121+
github.com/sagernet/cronet-go/lib/linux_arm v0.0.0-20251212075915-914a764300d6 // indirect
122+
github.com/sagernet/cronet-go/lib/linux_arm64 v0.0.0-20251212075915-914a764300d6 // indirect
123+
github.com/sagernet/cronet-go/lib/linux_arm64_musl v0.0.0-20251212075915-914a764300d6 // indirect
124+
github.com/sagernet/cronet-go/lib/linux_arm_musl v0.0.0-20251212075915-914a764300d6 // indirect
125+
github.com/sagernet/cronet-go/lib/windows_386 v0.0.0-20251212075915-914a764300d6 // indirect
126+
github.com/sagernet/cronet-go/lib/windows_amd64 v0.0.0-20251212075915-914a764300d6 // indirect
127+
github.com/sagernet/cronet-go/lib/windows_arm64 v0.0.0-20251212075915-914a764300d6 // indirect
107128
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a // indirect
108129
github.com/sagernet/nftables v0.3.0-beta.4 // indirect
109130
github.com/spf13/pflag v1.0.6 // indirect

0 commit comments

Comments
 (0)