diff --git a/.github/go_ios_cpu_features.patch b/.github/go_ios_cpu_features.patch index 704d2d76..52231b18 100644 --- a/.github/go_ios_cpu_features.patch +++ b/.github/go_ios_cpu_features.patch @@ -21,8 +21,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. --//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd -+//go:build arm64 && !linux && !freebsd && !android && !darwin && !openbsd +-//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd && !windows ++//go:build arm64 && !linux && !freebsd && !android && !darwin && !openbsd && !windows package cpu diff --git a/.github/go_windows_arm64_cpu_features.patch b/.github/go_windows_arm64_cpu_features.patch deleted file mode 100644 index 7c62dca2..00000000 --- a/.github/go_windows_arm64_cpu_features.patch +++ /dev/null @@ -1,94 +0,0 @@ ---- a/src/internal/cpu/cpu_arm64_other.go -+++ b/src/internal/cpu/cpu_arm64_other.go -@@ -2,7 +2,7 @@ - // Use of this source code is governed by a BSD-style - // license that can be found in the LICENSE file. - --//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd -+//go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) && !openbsd && !windows - - package cpu - ---- a/src/internal/cpu/cpu_arm64_windows.go -+++ b/src/internal/cpu/cpu_arm64_windows.go -@@ -0,0 +1,26 @@ -+// Copyright 2026 The Go Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style -+// license that can be found in the LICENSE file. -+ -+//go:build arm64 -+ -+package cpu -+ -+func osInit() { -+ // TODO(brainman): we don't know how to retrieve those bits form user space - leaving them as false for now -+ // https://github.com/golang/go/issues/76791#issuecomment-3877873959 -+ ARM64.HasCPUID = false -+ ARM64.HasDIT = false -+ ARM64.IsNeoverse = false -+ -+ if isProcessorFeaturePresent(_PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) { -+ ARM64.HasAES = true -+ ARM64.HasPMULL = true -+ ARM64.HasSHA1 = true -+ ARM64.HasSHA2 = true -+ } -+ ARM64.HasSHA3 = isProcessorFeaturePresent(_PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE) -+ ARM64.HasCRC32 = isProcessorFeaturePresent(_PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) -+ ARM64.HasSHA512 = isProcessorFeaturePresent(_PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE) -+ ARM64.HasATOMICS = isProcessorFeaturePresent(_PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE) -+} ---- a/src/internal/cpu/cpu_windows.go -+++ b/src/internal/cpu/cpu_windows.go -@@ -0,0 +1,20 @@ -+// Copyright 2026 The Go Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style -+// license that can be found in the LICENSE file. -+ -+package cpu -+ -+import _ "unsafe" // for linkname -+ -+const ( -+ _PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE = 30 -+ _PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE = 31 -+ _PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE = 34 -+ _PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE = 64 -+ _PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE = 65 -+) -+ -+// isProcessorFeaturePresent calls windows IsProcessorFeaturePresent API. -+// -+//go:linkname isProcessorFeaturePresent -+func isProcessorFeaturePresent(processorFeature uint32) bool // Implemented in runtime package. ---- a/src/runtime/os_windows.go -+++ b/src/runtime/os_windows.go -@@ -39,6 +39,7 @@ const ( - //go:cgo_import_dynamic runtime._GetSystemDirectoryA GetSystemDirectoryA%2 "kernel32.dll" - //go:cgo_import_dynamic runtime._GetSystemInfo GetSystemInfo%1 "kernel32.dll" - //go:cgo_import_dynamic runtime._GetThreadContext GetThreadContext%2 "kernel32.dll" -+//go:cgo_import_dynamic runtime._IsProcessorFeaturePresent IsProcessorFeaturePresent%1 "kernel32.dll" - //go:cgo_import_dynamic runtime._SetThreadContext SetThreadContext%2 "kernel32.dll" - //go:cgo_import_dynamic runtime._LoadLibraryExW LoadLibraryExW%3 "kernel32.dll" - //go:cgo_import_dynamic runtime._PostQueuedCompletionStatus PostQueuedCompletionStatus%4 "kernel32.dll" -@@ -96,6 +97,7 @@ var ( - _GetSystemDirectoryA, - _GetSystemInfo, - _GetThreadContext, -+ _IsProcessorFeaturePresent, - _SetThreadContext, - _LoadLibraryExW, - _PostQueuedCompletionStatus, -@@ -261,6 +263,12 @@ func windows_QueryPerformanceFrequency() int64 { - return frequency - } - -+//go:linkname cpu_isProcessorFeaturePresent internal/cpu.isProcessorFeaturePresent -+func cpu_isProcessorFeaturePresent(processorFeature uint32) bool { -+ ret := stdcall(_IsProcessorFeaturePresent, uintptr(processorFeature)) -+ return ret != 0 -+} -+ - func loadOptionalSyscalls() { - bcryptPrimitives := windowsLoadSystemLib(bcryptprimitivesdll[:]) - if bcryptPrimitives == 0 { diff --git a/.github/patch_go_for_windows_arm64.sh b/.github/patch_go_for_windows_arm64.sh deleted file mode 100755 index dfb5f073..00000000 --- a/.github/patch_go_for_windows_arm64.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Go's internal/cpu never detects ARM64 features on windows/arm64 before Go 1.27, -# so crypto/aes, AES-GCM and crypto/sha256 use their generic implementations. -# Backport of https://go.dev/cl/745560 (golang/go#76791). -# -# Remove once the Go release used by the Windows builds includes the fix. - -export GOTOOLCHAIN=local - -GOROOT="$(go env GOROOT)" -PATCH_FILE="$(cd "$(dirname "$0")" && pwd)/go_windows_arm64_cpu_features.patch" - -cd "$GOROOT" -if [[ -f src/internal/cpu/cpu_arm64_windows.go ]]; then - echo "already patched" -else - patch --verbose -p1 < "$PATCH_FILE" -fi - -CPU_FILES="$(GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go list -f '{{.GoFiles}}' internal/cpu)" -echo "internal/cpu files for windows/arm64: $CPU_FILES" -case "$CPU_FILES" in -*cpu_arm64_windows.go*) ;; -*) - echo "patch is not effective" >&2 - exit 1 - ;; -esac diff --git a/.github/setup_go_for_macos1013.sh b/.github/setup_go_for_macos1013.sh index 689a1e32..61893c5f 100755 --- a/.github/setup_go_for_macos1013.sh +++ b/.github/setup_go_for_macos1013.sh @@ -2,11 +2,10 @@ set -euo pipefail -VERSION="1.26.10" +VERSION="1.27.4" PATCH_COMMITS=( - "f080b0c6346eb690c0dc82497b35925f385b35ac" - "2d9c12887c342fb9051d231aa5388743cb7e9cb6" - "367663849c656612fc3c8875ef6e7f6b0c93dbd0" + "042f409b154a743972239baefcfc400d5ff33de5" + "d6ea9ffecf266da2d2793b635a07e7db60a3adaf" ) CURL_ARGS=( -fL @@ -26,13 +25,13 @@ tar -xzf "go${VERSION}.darwin-arm64.tar.gz" mv go go_osx cd go_osx -# these patch URLs only work on golang1.26.x -# that means after golang1.27 release it must be changed -# see: https://github.com/SagerNet/go/commits/release-branch.go1.26/ +# these patch URLs only work on golang1.27.x +# that means after golang1.28 release it must be changed +# see: https://github.com/SagerNet/go/commits/release-branch.go1.27/ # revert: -# 33d3f603c1: "cmd/link/internal/ld: use 12.0.0 OS/SDK versions for macOS linking" # 937368f84e: "crypto/x509: change how we retrieve chains on darwin" -# d90a57ffe8: "cmd/link/internal/ld: unify OS/SDK versions for macOS linking" +# fixes: +# d6ea9ffecf: "cmd/link: lower default macOS version to 10.13" for patch_commit in "${PATCH_COMMITS[@]}"; do curl "${CURL_ARGS[@]}" "https://github.com/SagerNet/go/commit/${patch_commit}.diff" | patch --verbose -p 1 diff --git a/.github/setup_go_for_windows7.sh b/.github/setup_go_for_windows7.sh index e4345c26..fc471f69 100755 --- a/.github/setup_go_for_windows7.sh +++ b/.github/setup_go_for_windows7.sh @@ -2,14 +2,15 @@ set -euo pipefail -VERSION="1.26.10" +VERSION="1.27.4" PATCH_COMMITS=( - "a4ae550aa148b04c9d4890e98bee63aede5c4b53" - "95b851f661584711faa8115b3234a461044f4510" - "b0bf0a863cf218b9bb0d6c013903ab160ae0c39b" - "7c7a2a0d68920f8764d9a3aeae7ad1067a17b3fa" - "ba34356e82f3c12a7303d2231e6ea0e42bbbb3bf" - "472a88edbc2a42feb53fa31d29ab54d33840dca6" + "5bea096a8d38bcc2f7b29a423a2d7a677e7257b4" + "2fd9d96c8897586872cf00e335dad7d0e2d32601" + "51cbeef333241001a1106fbeeb7c7ef80054dac2" + "4fd81ff5c9844620e836e8d2052e082ac26484f0" + "2924464d68627505f876d4d275bf8432dbf81da5" + "5c36850df445d11d557c3d995e15a3ac159749ea" + "51c81072acbed32e4331026bc6ca308a3a495039" ) CURL_ARGS=( -fL @@ -29,18 +30,21 @@ mv go go_win7 cd go_win7 # modify from https://github.com/restic/restic/issues/4636#issuecomment-1896455557 -# these patch URLs only work on golang1.26.x -# that means after golang1.27 release it must be changed -# see: https://github.com/MetaCubeX/go/commits/release-branch.go1.26/ +# these patch URLs only work on golang1.27.x +# that means after golang1.28 release it must be changed +# see: https://github.com/MetaCubeX/go/commits/release-branch.go1.27/ # revert: +# 341b5e2c0261cc059b157f1c7a2a2c4d1f417f0d: "cmd/link: raise minimum windows version to 10" # 693def151adff1af707d82d28f55dba81ceb08e1: "crypto/rand,runtime: switch RtlGenRandom for ProcessPrng" # 7c1157f9544922e96945196b47b95664b1e39108: "net: remove sysSocket fallback for Windows 7" # 48042aa09c2f878c4faa576948b07fe625c4707a: "syscall: remove Windows 7 console handle workaround" # a17d959debdb04cd550016a3501dd09d50cd62e7: "runtime: always use LoadLibraryEx to load system libraries" # fixes: -# bed309eff415bcb3c77dd4bc3277b682b89a388d: "Fix os.RemoveAll not working on Windows7" -# 34b899c2fb39b092db4fa67c4417e41dc046be4b: "Revert \"os: remove 5ms sleep on Windows in (*Process).Wait\"" +# 5c36850df445d11d557c3d995e15a3ac159749ea: "Fix os.RemoveAll not working on Windows7" +# 51c81072acbed32e4331026bc6ca308a3a495039: "Revert \"os: remove 5ms sleep on Windows in (*Process).Wait\"" for patch_commit in "${PATCH_COMMITS[@]}"; do curl "${CURL_ARGS[@]}" "https://github.com/MetaCubeX/go/commit/${patch_commit}.diff" | patch --verbose -p 1 done + +GOTOOLCHAIN=local ./bin/go install cmd/link diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d3e7deb6..7a65ade7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules uses: actions/cache/restore@v4 @@ -145,7 +145,7 @@ jobs: if: ${{ ! matrix.legacy_win7 }} uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules uses: actions/cache/restore@v4 @@ -160,7 +160,7 @@ jobs: with: path: | ~/go/go_win7 - key: go_win7_12610 + key: go_win7_1274 - name: Setup Go for Windows 7 if: matrix.legacy_win7 && steps.cache-go-for-windows7.outputs.cache-hit != 'true' env: @@ -490,7 +490,7 @@ jobs: if: ${{ ! matrix.legacy_osx }} uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules uses: actions/cache/restore@v4 @@ -505,7 +505,7 @@ jobs: with: path: | ~/go/go_osx - key: go_osx_12610 + key: go_osx_1274 - name: Setup Go for macOS 10.13 if: matrix.legacy_osx && steps.cache-go-for-macos1013.outputs.cache-hit != 'true' env: @@ -589,12 +589,8 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - - name: Patch Go for Windows ARM64 - if: matrix.arch == 'arm64' - shell: bash - run: .github/patch_go_for_windows_arm64.sh - name: Cache Go modules uses: actions/cache@v4 with: @@ -696,7 +692,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules uses: actions/cache@v4 @@ -760,7 +756,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules uses: actions/cache/restore@v4 @@ -868,7 +864,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules uses: actions/cache/restore@v4 @@ -981,12 +977,8 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - - name: Patch Go for Windows ARM64 - if: matrix.desktop_arch == 'arm64' - shell: bash - run: .github/patch_go_for_windows_arm64.sh - name: Cache Go modules uses: actions/cache@v4 with: @@ -1097,7 +1089,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules uses: actions/cache@v4 @@ -1271,7 +1263,7 @@ jobs: if: matrix.build uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Patch Go for iOS if: matrix.build && (matrix.platform == 'ios/arm64' || matrix.platform == 'tvos/arm64') @@ -1288,8 +1280,8 @@ jobs: uses: actions/cache@v4 with: path: ~/Library/Caches/go-build - key: libbox-go-build-${{ matrix.artifact }}-1.26.10-${{ hashFiles('go.sum') }} - restore-keys: libbox-go-build-${{ matrix.artifact }}-1.26.10- + key: libbox-go-build-${{ matrix.artifact }}-1.27.4-${{ hashFiles('go.sum') }} + restore-keys: libbox-go-build-${{ matrix.artifact }}-1.27.4- - name: Set tag if: matrix.build run: git tag v${{ needs.calculate_version.outputs.version }} -f @@ -1358,7 +1350,7 @@ jobs: if: matrix.if uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 cache: false - name: Cache Go modules if: matrix.if diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3bd0dfa8..2c9e935e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -55,7 +55,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 - name: Clone cronet-go if: matrix.naive run: | diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 83abc679..a9659954 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -60,7 +60,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: ^1.26 + go-version: ^1.27 - name: Cache go module uses: actions/cache@v4 with: diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f703152b..a03d2eb7 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -29,7 +29,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 - name: Check input version if: github.event_name == 'workflow_dispatch' run: |- @@ -72,7 +72,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.26.10 + go-version: 1.27.4 - name: Clone cronet-go if: matrix.naive run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 66a66a0b..e5449079 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,8 +33,8 @@ jobs: - windows-latest - macos-latest go: - - ~1.25 - ~1.26 + - ~1.27 runs-on: ${{ matrix.os }} steps: - name: Checkout diff --git a/Dockerfile b/Dockerfile index 54c606e1..f12d526c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS builder LABEL maintainer="nekohasekai " COPY . /go/src/github.com/sagernet/sing-box WORKDIR /go/src/github.com/sagernet/sing-box