Skip to content

Commit d42a1fa

Browse files
committed
ccm: Add usage statistics tracking
1 parent cc84cb7 commit d42a1fa

File tree

10 files changed

+725
-33
lines changed

10 files changed

+725
-33
lines changed

.github/workflows/build.yml

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ jobs:
9393
- { os: windows, arch: "386", legacy_win7: true, legacy_name: "windows-7" }
9494
- { os: windows, arch: arm64 }
9595

96-
- { os: darwin, arch: amd64 }
97-
- { os: darwin, arch: arm64 }
98-
- { os: darwin, arch: amd64, legacy_go124: true, legacy_name: "macos-11" }
99-
10096
- { os: android, arch: arm64, ndk: "aarch64-linux-android21" }
10197
- { os: android, arch: arm, ndk: "armv7a-linux-androideabi21" }
10298
- { os: android, arch: amd64, ndk: "x86_64-linux-android21" }
@@ -285,6 +281,77 @@ jobs:
285281
with:
286282
name: binary-${{ matrix.os }}_${{ matrix.arch }}${{ matrix.goarm && format('v{0}', matrix.goarm) }}${{ matrix.go386 && format('_{0}', matrix.go386) }}${{ matrix.gomips && format('_{0}', matrix.gomips) }}${{ matrix.legacy_name && format('-legacy-{0}', matrix.legacy_name) }}
287283
path: "dist"
284+
build_darwin:
285+
name: Build Darwin binaries
286+
if: github.event_name != 'workflow_dispatch' || inputs.build == 'All' || inputs.build == 'Binary'
287+
runs-on: macos-latest
288+
needs:
289+
- calculate_version
290+
strategy:
291+
matrix:
292+
include:
293+
- { arch: amd64 }
294+
- { arch: arm64 }
295+
- { arch: amd64, legacy_go124: true, legacy_name: "macos-11" }
296+
steps:
297+
- name: Checkout
298+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
299+
with:
300+
fetch-depth: 0
301+
- name: Setup Go
302+
if: ${{ ! matrix.legacy_go124 }}
303+
uses: actions/setup-go@v5
304+
with:
305+
go-version: ^1.25.3
306+
- name: Setup Go 1.24
307+
if: matrix.legacy_go124
308+
uses: actions/setup-go@v5
309+
with:
310+
go-version: ~1.24.6
311+
- name: Set tag
312+
run: |-
313+
git ls-remote --exit-code --tags origin v${{ needs.calculate_version.outputs.version }} || echo "PUBLISHED=false" >> "$GITHUB_ENV"
314+
git tag v${{ needs.calculate_version.outputs.version }} -f
315+
- name: Set build tags
316+
run: |
317+
set -xeuo pipefail
318+
TAGS='with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,badlinkname,tfogo_checklinkname0'
319+
echo "BUILD_TAGS=${TAGS}" >> "${GITHUB_ENV}"
320+
- name: Build
321+
run: |
322+
set -xeuo pipefail
323+
mkdir -p dist
324+
go build -v -trimpath -o dist/sing-box -tags "${BUILD_TAGS}" \
325+
-ldflags '-s -buildid= -X github.com/sagernet/sing-box/constant.Version=${{ needs.calculate_version.outputs.version }} -checklinkname=0' \
326+
./cmd/sing-box
327+
env:
328+
CGO_ENABLED: "1"
329+
GOOS: darwin
330+
GOARCH: ${{ matrix.arch }}
331+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
332+
- name: Set name
333+
run: |-
334+
DIR_NAME="sing-box-${{ needs.calculate_version.outputs.version }}-darwin-${{ matrix.arch }}"
335+
if [[ -n "${{ matrix.legacy_name }}" ]]; then
336+
DIR_NAME="${DIR_NAME}-legacy-${{ matrix.legacy_name }}"
337+
fi
338+
echo "DIR_NAME=${DIR_NAME}" >> "${GITHUB_ENV}"
339+
- name: Archive
340+
run: |
341+
set -xeuo pipefail
342+
cd dist
343+
mkdir -p "${DIR_NAME}"
344+
cp ../LICENSE "${DIR_NAME}"
345+
cp sing-box "${DIR_NAME}"
346+
tar -czvf "${DIR_NAME}.tar.gz" "${DIR_NAME}"
347+
rm -r "${DIR_NAME}"
348+
- name: Cleanup
349+
run: rm dist/sing-box
350+
- name: Upload artifact
351+
uses: actions/upload-artifact@v4
352+
with:
353+
name: binary-darwin_${{ matrix.arch }}${{ matrix.legacy_name && format('-legacy-{0}', matrix.legacy_name) }}
354+
path: "dist"
288355
build_android:
289356
name: Build Android
290357
if: github.event_name != 'workflow_dispatch' || inputs.build == 'All' || inputs.build == 'Android'
@@ -619,6 +686,7 @@ jobs:
619686
needs:
620687
- calculate_version
621688
- build
689+
- build_darwin
622690
- build_android
623691
- build_apple
624692
steps:

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/sagernet/sing-box
33
go 1.24.7
44

55
require (
6+
github.com/anthropics/anthropic-sdk-go v1.14.0
67
github.com/anytls/sing-anytls v0.0.11
78
github.com/caddyserver/certmagic v0.23.0
89
github.com/coder/websocket v1.8.13
@@ -114,6 +115,10 @@ require (
114115
github.com/tailscale/peercred v0.0.0-20250107143737-35a0c7bd7edc // indirect
115116
github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976 // indirect
116117
github.com/tailscale/wireguard-go v0.0.0-20250716170648-1d0488a3d7da // indirect
118+
github.com/tidwall/gjson v1.18.0 // indirect
119+
github.com/tidwall/match v1.1.1 // indirect
120+
github.com/tidwall/pretty v1.2.1 // indirect
121+
github.com/tidwall/sjson v1.2.5 // indirect
117122
github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 // indirect
118123
github.com/x448/float16 v0.8.4 // indirect
119124
github.com/zeebo/blake3 v0.2.4 // indirect

go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa h1:LHTHcTQiSGT7V
88
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
99
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
1010
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
11+
github.com/anthropics/anthropic-sdk-go v1.14.0 h1:EzNQvnZlaDHe2UPkoUySDz3ixRgNbwKdH8KtFpv7pi4=
12+
github.com/anthropics/anthropic-sdk-go v1.14.0/go.mod h1:WTz31rIUHUHqai2UslPpw5CwXrQP3geYBioRV4WOLvE=
1113
github.com/anytls/sing-anytls v0.0.11 h1:w8e9Uj1oP3m4zxkyZDewPk0EcQbvVxb7Nn+rapEx4fc=
1214
github.com/anytls/sing-anytls v0.0.11/go.mod h1:7rjN6IukwysmdusYsrV51Fgu1uW6vsrdd6ctjnEAln8=
1315
github.com/caddyserver/certmagic v0.23.0 h1:CfpZ/50jMfG4+1J/u2LV6piJq4HOfO6ppOnOf7DkFEU=
@@ -218,6 +220,16 @@ github.com/tailscale/wireguard-go v0.0.0-20250716170648-1d0488a3d7da h1:jVRUZPRs
218220
github.com/tailscale/wireguard-go v0.0.0-20250716170648-1d0488a3d7da/go.mod h1:BOm5fXUBFM+m9woLNBoxI9TaBXXhGNP50LX/TGIvGb4=
219221
github.com/tc-hib/winres v0.2.1 h1:YDE0FiP0VmtRaDn7+aaChp1KiF4owBiJa5l964l5ujA=
220222
github.com/tc-hib/winres v0.2.1/go.mod h1:C/JaNhH3KBvhNKVbvdlDWkbMDO9H4fKKDaN7/07SSuk=
223+
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
224+
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
225+
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
226+
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
227+
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
228+
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
229+
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
230+
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
231+
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
232+
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
221233
github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 h1:pyC9PaHYZFgEKFdlp3G8RaCKgVpHZnecvArXvPXcFkM=
222234
github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701/go.mod h1:P3a5rG4X7tI17Nn3aOIAYr5HbIMukwXG0urG0WuL8OA=
223235
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=

include/ccm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build with_ccm
1+
//go:build with_ccm && (!darwin || cgo)
22

33
package include
44

include/ccm_stub_darwin.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//go:build with_ccm && darwin && !cgo
2+
3+
package include
4+
5+
import (
6+
"context"
7+
8+
"github.com/sagernet/sing-box/adapter"
9+
"github.com/sagernet/sing-box/adapter/service"
10+
C "github.com/sagernet/sing-box/constant"
11+
"github.com/sagernet/sing-box/log"
12+
"github.com/sagernet/sing-box/option"
13+
E "github.com/sagernet/sing/common/exceptions"
14+
)
15+
16+
func registerCCMService(registry *service.Registry) {
17+
service.Register[option.CCMServiceOptions](registry, C.TypeCCM, func(ctx context.Context, logger log.ContextLogger, tag string, options option.CCMServiceOptions) (adapter.Service, error) {
18+
return nil, E.New(`CCM requires CGO on darwin, rebuild with CGO_ENABLED=1`)
19+
})
20+
}

option/ccm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type CCMServiceOptions struct {
1111
Users []CCMUser `json:"users,omitempty"`
1212
Headers badoption.HTTPHeader `json:"headers,omitempty"`
1313
Detour string `json:"detour,omitempty"`
14+
UsagesPath string `json:"usages_path,omitempty"`
1415
}
1516

1617
type CCMUser struct {

service/ccm/credential_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build darwin
1+
//go:build darwin && cgo
22

33
package ccm
44

0 commit comments

Comments
 (0)