mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
Only copy the relevant wavesrv binary when packaging for a specific architecture (#316)
This change shaves ~20 MB off the download size by only copying over the wavesrv binary that is relevant for whichever architecture we're currently packaging. This is only relevant for macOS at the moment, though it can also apply to Windows when we get multi-arch builds working. This required renaming our Go binaries from .amd64 to .x64 to comply with electron-builder's naming conventions.
This commit is contained in:
+6
-4
@@ -97,11 +97,11 @@ tasks:
|
||||
vars:
|
||||
- ARCHS
|
||||
cmds:
|
||||
- cmd: CGO_ENABLED=1 GOARCH={{.ARCH}} go build -tags "osusergo,netgo,sqlite_omit_load_extension" -ldflags "{{.GO_LDFLAGS}} -X main.BuildTime=$({{.DATE}} +'%Y%m%d%H%M') -X main.WaveVersion={{.VERSION}}" -o dist/bin/wavesrv.{{.ARCH}}{{exeExt}} cmd/server/main-server.go
|
||||
- cmd: CGO_ENABLED=1 GOARCH={{.GOARCH}} go build -tags "osusergo,netgo,sqlite_omit_load_extension" -ldflags "{{.GO_LDFLAGS}} -X main.BuildTime=$({{.DATE}} +'%Y%m%d%H%M') -X main.WaveVersion={{.VERSION}}" -o dist/bin/wavesrv.{{if eq .GOARCH "amd64"}}x64{{else}}{{.GOARCH}}{{end}}{{exeExt}} cmd/server/main-server.go
|
||||
for:
|
||||
var: ARCHS
|
||||
split: ","
|
||||
as: ARCH
|
||||
as: GOARCH
|
||||
sources:
|
||||
- "cmd/server/*.go"
|
||||
- "pkg/**/*.go"
|
||||
@@ -159,6 +159,8 @@ tasks:
|
||||
vars:
|
||||
EXT:
|
||||
sh: echo {{if eq .GOOS "windows"}}.exe{{end}}
|
||||
NORMALIZEDARCH:
|
||||
sh: echo {{if eq .GOARCH "amd64"}}x64{{else}}{{.GOARCH}}{{end}}
|
||||
requires:
|
||||
vars:
|
||||
- GOOS
|
||||
@@ -168,9 +170,9 @@ tasks:
|
||||
- "cmd/wsh/**/*.go"
|
||||
- "pkg/**/*.go"
|
||||
generates:
|
||||
- dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.GOARCH}}{{.EXT}}
|
||||
- dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.NORMALIZEDARCH}}{{.EXT}}
|
||||
cmds:
|
||||
- (CGO_ENABLED=0 GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -ldflags="-s -w -X main.BuildTime=$({{.DATE}} +'%Y%m%d%H%M') -X main.WaveVersion={{.VERSION}}" -o dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.GOARCH}}{{.EXT}} cmd/wsh/main-wsh.go)
|
||||
- (CGO_ENABLED=0 GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -ldflags="-s -w -X main.BuildTime=$({{.DATE}} +'%Y%m%d%H%M') -X main.WaveVersion={{.VERSION}}" -o dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.NORMALIZEDARCH}}{{.EXT}} cmd/wsh/main-wsh.go)
|
||||
deps:
|
||||
- go:mod:tidy
|
||||
internal: true
|
||||
|
||||
@@ -17,7 +17,7 @@ const config = {
|
||||
{
|
||||
from: "./dist",
|
||||
to: "./dist",
|
||||
filter: ["**/*"],
|
||||
filter: ["**/*", "!bin/*", "bin/wavesrv.${arch}*", "bin/wsh*"],
|
||||
},
|
||||
{
|
||||
from: ".",
|
||||
@@ -51,10 +51,17 @@ const config = {
|
||||
teamId: process.env.APPLE_TEAM_ID,
|
||||
}
|
||||
: false,
|
||||
mergeASARs: true,
|
||||
singleArchFiles: "dist/bin/wavesrv.*",
|
||||
binaries: fs
|
||||
.readdirSync("dist/bin", { recursive: true, withFileTypes: true })
|
||||
.readdirSync("./dist/bin", { recursive: true, withFileTypes: true })
|
||||
.filter((f) => f.isFile() && (f.name.startsWith("wavesrv") || f.name.includes("darwin")))
|
||||
.map((f) => path.resolve(f.parentPath, f.name)),
|
||||
.map((f) => {
|
||||
const resolvedPath = path.resolve(f.parentPath ?? f.path, f.name);
|
||||
console.log("resolvedPath", resolvedPath);
|
||||
return resolvedPath;
|
||||
})
|
||||
.filter((path) => path),
|
||||
},
|
||||
linux: {
|
||||
executableName: pkg.productName,
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ if (isDevVite) {
|
||||
|
||||
app.setName(isDev ? "TheNextWave (Dev)" : "TheNextWave");
|
||||
const unamePlatform = process.platform;
|
||||
const unameArch: string = process.arch === "x64" ? "amd64" : process.arch;
|
||||
const unameArch: string = process.arch;
|
||||
keyutil.setKeyUtilPlatform(unamePlatform);
|
||||
|
||||
ipcMain.on("get-is-dev", (event) => {
|
||||
|
||||
@@ -193,7 +193,7 @@ func GetClientArch(client *ssh.Client) (string, error) {
|
||||
formatted := strings.ToLower(string(out))
|
||||
formatted = strings.TrimSpace(formatted)
|
||||
if formatted == "x86_64" {
|
||||
return "amd64", nil
|
||||
return "x64", nil
|
||||
}
|
||||
return formatted, nil
|
||||
}
|
||||
|
||||
@@ -209,12 +209,19 @@ func GetZshZDotDir() string {
|
||||
return filepath.Join(wavebase.GetWaveHomeDir(), ZshIntegrationDir)
|
||||
}
|
||||
|
||||
func GetWshBinaryPath(version string, goos string, goarch string) string {
|
||||
func GetWshBaseName(version string, goos string, goarch string) string {
|
||||
ext := ""
|
||||
if goarch == "amd64" {
|
||||
goarch = "x64"
|
||||
}
|
||||
if goos == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
return filepath.Join(os.Getenv(WaveAppPathVarName), AppPathBinDir, fmt.Sprintf("wsh-%s-%s.%s%s", version, goos, goarch, ext))
|
||||
return fmt.Sprintf("wsh-%s-%s.%s%s", version, goos, goarch, ext)
|
||||
}
|
||||
|
||||
func GetWshBinaryPath(version string, goos string, goarch string) string {
|
||||
return filepath.Join(os.Getenv(WaveAppPathVarName), AppPathBinDir, GetWshBaseName(version, goos, goarch))
|
||||
}
|
||||
|
||||
func InitRcFiles(waveHome string, wshBinDir string) error {
|
||||
@@ -288,6 +295,7 @@ func initCustomShellStartupFilesInternal() error {
|
||||
}
|
||||
|
||||
// copy the correct binary to bin
|
||||
wshBaseName := GetWshBaseName(wavebase.WaveVersion, runtime.GOOS, runtime.GOARCH)
|
||||
wshFullPath := GetWshBinaryPath(wavebase.WaveVersion, runtime.GOOS, runtime.GOARCH)
|
||||
if _, err := os.Stat(wshFullPath); err != nil {
|
||||
log.Printf("error (non-fatal), could not resolve wsh binary %q: %v\n", wshFullPath, err)
|
||||
@@ -301,14 +309,10 @@ func initCustomShellStartupFilesInternal() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error copying wsh binary to bin: %v", err)
|
||||
}
|
||||
log.Printf("wsh binary successfully %q copied to %q\n", computeWshBaseName(), wshDstPath)
|
||||
log.Printf("wsh binary successfully %q copied to %q\n", wshBaseName, wshDstPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
func computeWshBaseName() string {
|
||||
return fmt.Sprintf("wsh-%s-%s.%s", wavebase.WaveVersion, runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
func toPwshEnvVarRef(input string) string {
|
||||
return strings.Replace(input, "$", "$env:", -1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user