用wails进行go的app打包,简单列一个模版,测试需要再拿来用。
Makefile
# 应用程序名称和版本信息
APP_NAME := app-client
VERSION := 1.0.0
GIT_HASH := $(shell git rev-parse --short HEAD)
BUILD_TIME := $(shell date +%Y-%m-%dT%H:%M:%S)
IDENTIFIER := www.mine.app
PKG_OUTPUT := build/$(APP_NAME)-$(VERSION)# 编译标记
LDFLAGS := -ldflags="-X 'main.AppName=$(APP_NAME)' -X 'main.Version=$(VERSION)' -X 'main.GitHash=$(GIT_HASH)' -X 'main.BuildTime=$(BUILD_TIME)'"# Wails 命令
WAILS := wails# 默认目标
.PHONY: all
all: clean build package# 清理旧的构建文件
.PHONY: clean
clean:@echo "Cleaning build directory..."rm -rf build# 生成静态文件(如需要)
.PHONY: static-generated
static-generated:statik -src=./configs# 运行开发模式
.PHONY: dev
dev:$(WAILS) dev -s# 各个平台和架构的构建目标
.PHONY: build
build: mac_amd64 mac_arm64 mac_universal windows_amd64 windows_arm64 linux_amd64 linux_arm64# 构建 macOS 版本
.PHONY: mac_amd64
mac_amd64:@echo "Building macOS AMD64 version with Git Hash: $(GIT_HASH)"GOOS=darwin GOARCH=amd64 $(WAILS) build -platform darwin/amd64 $(LDFLAGS) -o build/$(APP_NAME)-macOS-AMD64.PHONY: mac_arm64
mac_arm64:@echo "Building macOS ARM64 version with Git Hash: $(GIT_HASH)"GOOS=darwin GOARCH=arm64 $(WAILS) build -platform darwin/arm64 $(LDFLAGS) -o build/$(APP_NAME)-macOS-ARM64.PHONY: mac_universal
mac_universal:@echo "Building macOS Universal version (AMD64 + ARM64) with Git Hash: $(GIT_HASH)"GOOS=darwin GOARCH=arm64 $(WAILS) build -platform darwin/universal $(LDFLAGS) -o build/$(APP_NAME)-macOS-Universal# 构建 Windows 版本
.PHONY: windows_amd64
windows_amd64:@echo "Building Windows AMD64 version with Git Hash: $(GIT_HASH)"GOOS=windows GOARCH=amd64 $(WAILS) build -platform windows/amd64 $(LDFLAGS) -o build/$(APP_NAME)-Windows-AMD64.exe.PHONY: windows_arm64
windows_arm64:@echo "Building Windows ARM64 version with Git Hash: $(GIT_HASH)"GOOS=windows GOARCH=arm64 $(WAILS) build -platform windows/arm64 $(LDFLAGS) -o build/$(APP_NAME)-Windows-ARM64.exe# 构建 Linux 版本
.PHONY: linux_amd64
linux_amd64:@echo "Building Linux AMD64 version with Git Hash: $(GIT_HASH)"GOOS=linux GOARCH=amd64 $(WAILS) build -platform linux/amd64 $(LDFLAGS) -o build/$(APP_NAME)-Linux-AMD64.PHONY: linux_arm64
linux_arm64:@echo "Building Linux ARM64 version with Git Hash: $(GIT_HASH)"GOOS=linux GOARCH=arm64 $(WAILS) build -platform linux/arm64 $(LDFLAGS) -o build/$(APP_NAME)-Linux-ARM64# 打包目标:打包所有平台和架构的应用
.PHONY: package
package: package_mac package_windows package_linux# macOS 打包
.PHONY: package_mac
package_mac: mac_amd64 mac_arm64 mac_universal@echo "Packaging macOS versions..."hdiutil create -volname "$(APP_NAME) AMD64" -srcfolder build/$(APP_NAME)-macOS-AMD64 -ov -format UDZO $(PKG_OUTPUT)-macOS-AMD64.dmghdiutil create -volname "$(APP_NAME) ARM64" -srcfolder build/$(APP_NAME)-macOS-ARM64 -ov -format UDZO $(PKG_OUTPUT)-macOS-ARM64.dmghdiutil create -volname "$(APP_NAME) Universal" -srcfolder build/$(APP_NAME)-macOS-Universal -ov -format UDZO $(PKG_OUTPUT)-macOS-Universal.dmg# Windows 打包
.PHONY: package_windows
package_windows: windows_amd64 windows_arm64@echo "Packaging Windows versions..."zip -j $(PKG_OUTPUT)-Windows-AMD64.zip build/$(APP_NAME)-Windows-AMD64.exezip -j $(PKG_OUTPUT)-Windows-ARM64.zip build/$(APP_NAME)-Windows-ARM64.exe# Linux 打包
.PHONY: package_linux
package_linux: linux_amd64 linux_arm64@echo "Packaging Linux versions..."tar -czvf $(PKG_OUTPUT)-Linux-AMD64.tar.gz -C build $(APP_NAME)-Linux-AMD64tar -czvf $(PKG_OUTPUT)-Linux-ARM64.tar.gz -C build $(APP_NAME)-Linux-ARM64# 帮助信息
.PHONY: help
help:@echo "Available targets:"@echo " all : Clean, build, and package the app for all platforms and architectures"@echo " build : Build the app for all platforms and architectures with version and Git hash"@echo " clean : Clean the build directory"@echo " mac_amd64 : Build macOS AMD64 version"@echo " mac_arm64 : Build macOS ARM64 version"@echo " mac_universal : Build macOS Universal version (AMD64 + ARM64)"@echo " windows_amd64 : Build Windows AMD64 version"@echo " windows_arm64 : Build Windows ARM64 version"@echo " linux_amd64 : Build Linux AMD64 version"@echo " linux_arm64 : Build Linux ARM64 version"@echo " package : Package the built apps into distributable files"@echo " package_mac : Package macOS apps"@echo " package_windows : Package Windows apps"@echo " package_linux : Package Linux apps"
说明
- 改进打包命名:每个平台和架构的包文件有统一命名格式,方便分发。
- 打包命令分离:每个平台(macOS、Windows、Linux)的打包命令都分离为单独的目标,避免文件路径冲突。
- 包格式适配:macOS 使用
dmg
,Windows 使用zip
,Linux 使用tar.gz
,更符合各平台的分发标准。 - 文件路径清晰:各个平台的打包文件路径与文件名一致,避免可能的路径错误。