feat:support mac intel/arm

#493
This commit is contained in:
samwaf
2025-10-23 17:28:01 +08:00
parent ab1476de04
commit d1e5dc27ca
5 changed files with 181 additions and 7 deletions

View File

@@ -21,10 +21,20 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '1.21.4'
- name: Install dependencies for Windows cross-compilation
- name: Install dependencies for cross-compilation
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential clang llvm
# Install osxcross for macOS cross-compilation
git clone https://github.com/tpoechtrager/osxcross /tmp/osxcross
cd /tmp/osxcross
# Download macOS SDK
wget -O tarballs/MacOSX15.5.sdk.tar.xz https://github.com/joseluisq/macosx-sdks/releases/download/15.5/MacOSX15.5.sdk.tar.xz
# Build osxcross
OSX_VERSION_MIN=10.15 ./build.sh
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
@@ -34,6 +44,8 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CGO_ENABLED: 1
PATH: /tmp/osxcross/target/bin:${{ env.PATH }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
- name: List Folder
@@ -60,11 +72,29 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Check if should build Docker (only for 'all' tags or non-platform-specific tags)
- name: Check if should build Docker
id: check_docker
run: |
TAG_NAME="${GITHUB_REF#refs/tags/}"
echo "Checking tag: $TAG_NAME"
# Check if tag contains platform-specific keywords (but not 'all')
if echo "$TAG_NAME" | grep -qE "(linux|windows|win|macos|darwin|debug|arm64)" && ! echo "$TAG_NAME" | grep -q "all"; then
echo "Platform-specific tag detected, skipping Docker build"
echo "skip_docker=true" >> $GITHUB_OUTPUT
else
echo "Building Docker for all platforms or 'all' tag"
echo "skip_docker=false" >> $GITHUB_OUTPUT
fi
# Set up Docker Buildx
- name: Set up Docker Buildx
if: steps.check_docker.outputs.skip_docker != 'true'
uses: docker/setup-buildx-action@v2
# Build and Push Docker Image for Multi-Arch
- name: Build and Push Docker Image for Multi-Arch
if: steps.check_docker.outputs.skip_docker != 'true'
uses: docker/build-push-action@v5
with:
context: .
@@ -76,6 +106,7 @@ jobs:
${{ env.is_beta == 'false' && 'samwaf/samwaf:latest' || '' }}
# Test the Docker Image (latest)
- name: Test Docker Image (latest)
if: steps.check_docker.outputs.skip_docker != 'true'
run: |
echo "Testing Docker image with 'latest' tag..."
docker run -d --name=samwaf-latest-instance \
@@ -92,6 +123,7 @@ jobs:
docker stop samwaf-latest-instance
docker rm samwaf-latest-instance
- name: Test Docker Image (current tag)
if: steps.check_docker.outputs.skip_docker != 'true'
run: |
echo "Testing Docker image with tag '${{ env.IMAGE_TAG }}'..."
docker run -d --name=samwaf-current-instance \

View File

@@ -24,6 +24,7 @@ builds:
# 正式发布版本 (Release builds)
- id: "samwaf_linux"
binary: "SamWafLinux64"
skip: '{{ if or (contains .Tag "linux") (contains .Tag "all") (contains .Tag "windows") (contains .Tag "win") (contains .Tag "macos") (contains .Tag "darwin") }}{{ and (not (contains .Tag "linux")) (not (contains .Tag "all")) }}{{ else }}false{{ end }}'
env:
- CGO_ENABLED=1
- CC=x86_64-linux-gnu-gcc
@@ -42,6 +43,7 @@ builds:
- -extldflags "-static"
- id: "samwaf_win"
binary: "SamWaf64"
skip: '{{ if or (contains .Tag "linux") (contains .Tag "all") (contains .Tag "windows") (contains .Tag "win") (contains .Tag "macos") (contains .Tag "darwin") }}{{ and (not (contains .Tag "windows")) (not (contains .Tag "win")) (not (contains .Tag "all")) }}{{ else }}false{{ end }}'
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
@@ -60,6 +62,7 @@ builds:
- -extldflags "-static"
- id: "samwaf_linux_arm64"
binary: "SamWafLinuxArm64"
skip: '{{ if or (contains .Tag "linux") (contains .Tag "all") (contains .Tag "windows") (contains .Tag "win") (contains .Tag "macos") (contains .Tag "darwin") }}{{ and (not (contains .Tag "linux")) (not (contains .Tag "arm64")) (not (contains .Tag "all")) }}{{ else }}false{{ end }}'
env:
- CGO_ENABLED=1
- CC=aarch64-linux-gnu-gcc
@@ -76,10 +79,51 @@ builds:
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}
- -s -w
- -extldflags "-static"
- id: "samwaf_darwin_amd64"
binary: "SamWafDarwinAmd64"
skip: '{{ if or (contains .Tag "linux") (contains .Tag "all") (contains .Tag "windows") (contains .Tag "win") (contains .Tag "macos") (contains .Tag "darwin") }}{{ and (not (contains .Tag "macos")) (not (contains .Tag "darwin")) (not (contains .Tag "all")) }}{{ else }}false{{ end }}'
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
- MACOSX_DEPLOYMENT_TARGET=10.15
- CGO_CFLAGS=-Wno-unused-variable
- CGO_LDFLAGS=-mmacosx-version-min=10.15
goos:
- darwin
goarch:
- amd64
ldflags:
- -X SamWaf/global.GWAF_RELEASE=true
- -X SamWaf/global.GWAF_RUNTIME_WIN7_VERSION=false
- -X SamWaf/global.GWAF_RELEASE_VERSION_NAME={{ time "20060102" }}
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}
- -s -w
- id: "samwaf_darwin_arm64"
binary: "SamWafDarwinArm64"
skip: '{{ if or (contains .Tag "linux") (contains .Tag "all") (contains .Tag "windows") (contains .Tag "win") (contains .Tag "macos") (contains .Tag "darwin") }}{{ and (not (contains .Tag "macos")) (not (contains .Tag "darwin")) (not (contains .Tag "all")) }}{{ else }}false{{ end }}'
env:
- CGO_ENABLED=1
- CC=oa64-clang
- CXX=oa64-clang++
- MACOSX_DEPLOYMENT_TARGET=11.0
- CGO_CFLAGS=-Wno-unused-variable
- CGO_LDFLAGS=-mmacosx-version-min=11.0
goos:
- darwin
goarch:
- arm64
ldflags:
- -X SamWaf/global.GWAF_RELEASE=true
- -X SamWaf/global.GWAF_RUNTIME_WIN7_VERSION=false
- -X SamWaf/global.GWAF_RELEASE_VERSION_NAME={{ time "20060102" }}
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}
- -s -w
# Debug版本 (Debug builds for troubleshooting only)
- id: "samwaf_linux_debug"
binary: "SamWafLinux64-DEBUG-SYMBOLS"
skip: '{{ and (not (contains .Tag "linux")) (not (contains .Tag "debug")) (not (contains .Tag "all")) (ne .Env.BUILD_LINUX "true") }}'
env:
- CGO_ENABLED=1
- CC=x86_64-linux-gnu-gcc
@@ -97,6 +141,7 @@ builds:
- -extldflags "-static"
- id: "samwaf_win_debug"
binary: "SamWaf64-DEBUG-SYMBOLS"
skip: '{{ and (not (contains .Tag "windows")) (not (contains .Tag "win")) (not (contains .Tag "debug")) (not (contains .Tag "all")) (ne .Env.BUILD_WINDOWS "true") }}'
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
@@ -114,6 +159,7 @@ builds:
- -extldflags "-static"
- id: "samwaf_linux_arm64_debug"
binary: "SamWafLinuxArm64-DEBUG-SYMBOLS"
skip: '{{ and (not (contains .Tag "linux")) (not (contains .Tag "arm64")) (not (contains .Tag "debug")) (not (contains .Tag "all")) (ne .Env.BUILD_LINUX "true") }}'
env:
- CGO_ENABLED=1
- CC=aarch64-linux-gnu-gcc
@@ -129,6 +175,44 @@ builds:
- -X SamWaf/global.GWAF_RELEASE_VERSION_NAME={{ time "20060102" }}
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}-debug
- -extldflags "-static"
- id: "samwaf_darwin_amd64_debug"
binary: "SamWafDarwinAmd64-DEBUG-SYMBOLS"
skip: '{{ and (not (contains .Tag "macos")) (not (contains .Tag "darwin")) (not (contains .Tag "debug")) (not (contains .Tag "all")) (ne .Env.BUILD_MACOS "true") }}'
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
- MACOSX_DEPLOYMENT_TARGET=10.15
- CGO_CFLAGS=-Wno-unused-variable
- CGO_LDFLAGS=-mmacosx-version-min=10.15
goos:
- darwin
goarch:
- amd64
ldflags:
- -X SamWaf/global.GWAF_RELEASE=true
- -X SamWaf/global.GWAF_RUNTIME_WIN7_VERSION=false
- -X SamWaf/global.GWAF_RELEASE_VERSION_NAME={{ time "20060102" }}
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}-debug
- id: "samwaf_darwin_arm64_debug"
binary: "SamWafDarwinArm64-DEBUG-SYMBOLS"
skip: '{{ and (not (contains .Tag "macos")) (not (contains .Tag "darwin")) (not (contains .Tag "debug")) (not (contains .Tag "all")) (ne .Env.BUILD_MACOS "true") }}'
env:
- CGO_ENABLED=1
- CC=oa64-clang
- CXX=oa64-clang++
- MACOSX_DEPLOYMENT_TARGET=11.0
- CGO_CFLAGS=-Wno-unused-variable
- CGO_LDFLAGS=-mmacosx-version-min=11.0
goos:
- darwin
goarch:
- arm64
ldflags:
- -X SamWaf/global.GWAF_RELEASE=true
- -X SamWaf/global.GWAF_RUNTIME_WIN7_VERSION=false
- -X SamWaf/global.GWAF_RELEASE_VERSION_NAME={{ time "20060102" }}
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}-debug
upx:
- # Whether to enable it or not.
#
@@ -144,7 +228,7 @@ upx:
archives:
- id: "release_archives"
builds: ["samwaf_linux", "samwaf_win", "samwaf_linux_arm64"]
builds: ["samwaf_linux", "samwaf_win", "samwaf_linux_arm64", "samwaf_darwin_amd64", "samwaf_darwin_arm64"]
format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
@@ -160,7 +244,7 @@ archives:
- goos: windows
format: zip
- id: "debug_archives"
builds: ["samwaf_linux_debug", "samwaf_win_debug", "samwaf_linux_arm64_debug"]
builds: ["samwaf_linux_debug", "samwaf_win_debug", "samwaf_linux_arm64_debug", "samwaf_darwin_amd64_debug", "samwaf_darwin_arm64_debug"]
format: tar.gz
# Debug版本使用特殊命名以DEBUG开头便于用户识别和分组
name_template: >-

54
wafupdate/hide_darwin.go Normal file
View File

@@ -0,0 +1,54 @@
//go:build darwin
// +build darwin
package wafupdate
import (
"os"
"path/filepath"
"strings"
"syscall"
"unsafe"
)
const (
UF_HIDDEN = 0x8000 // macOS hidden file flag
)
// hideFile hides a file on macOS using chflags with UF_HIDDEN flag
func hideFile(path string) error {
// Try to use chflags to set the hidden flag
err := chflags(path, UF_HIDDEN)
if err != nil {
// Fallback: rename file with dot prefix (traditional Unix hidden file)
return hideFileByRename(path)
}
return nil
}
// chflags sets file flags on macOS
func chflags(path string, flags int) error {
pathBytes := []byte(path + "\x00") // null-terminated string
_, _, errno := syscall.Syscall(syscall.SYS_CHFLAGS,
uintptr(unsafe.Pointer(&pathBytes[0])),
uintptr(flags),
0)
if errno != 0 {
return errno
}
return nil
}
// hideFileByRename hides file by renaming it with a dot prefix
func hideFileByRename(path string) error {
dir := filepath.Dir(path)
filename := filepath.Base(path)
// Don't rename if already hidden (starts with dot)
if strings.HasPrefix(filename, ".") {
return nil
}
hiddenPath := filepath.Join(dir, "."+filename)
return os.Rename(path, hiddenPath)
}

View File

@@ -1,5 +1,5 @@
//go:build !windows
// +build !windows
//go:build !windows && !darwin
// +build !windows,!darwin
package wafupdate

View File

@@ -566,6 +566,10 @@ func (u *Updater) fetchInfoGithub() error {
platformSuffix = "Linux_x86_64"
case "linux-arm64":
platformSuffix = "Linux_arm64"
case "darwin-amd64":
platformSuffix = "Darwin_x86_64"
case "darwin-arm64":
platformSuffix = "Darwin_arm64"
}
// 查找匹配当前平台的资源同时过滤掉debug版本