mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-09 05:49:54 +00:00
feat: improve build scripts
This commit is contained in:
parent
7cc5e9e41a
commit
904a197af9
31
build.ps1
31
build.ps1
@ -1,13 +1,32 @@
|
|||||||
# Hysteria local build script for Windows (PowerShell)
|
# Hysteria build script for Windows (PowerShell)
|
||||||
|
|
||||||
$platforms = @("windows/amd64", "linux/amd64", "darwin/amd64")
|
# Environment variable options:
|
||||||
$ldflags = "-s -w"
|
# - HY_APP_VERSION: App version
|
||||||
|
# - HY_APP_COMMIT: App commit hash
|
||||||
|
# - HY_APP_PLATFORMS: Platforms to build for (e.g. "windows/amd64,linux/amd64,darwin/amd64")
|
||||||
|
|
||||||
if (!(Get-Command go -ErrorAction SilentlyContinue)) {
|
if (!(Get-Command go -ErrorAction SilentlyContinue)) {
|
||||||
Write-Host "Error: go is not installed." -ForegroundColor Red
|
Write-Host "Error: go is not installed." -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ldflags = "-s -w -X 'main.appDate=$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")'"
|
||||||
|
if ($env:HY_APP_VERSION) {
|
||||||
|
$ldflags += " -X 'main.appVersion=$($env:HY_APP_VERSION)'"
|
||||||
|
}
|
||||||
|
if ($env:HY_APP_COMMIT) {
|
||||||
|
$ldflags += " -X 'main.appCommit=$($env:HY_APP_COMMIT)'"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($env:HY_APP_PLATFORMS) {
|
||||||
|
$platforms = $env:HY_APP_PLATFORMS.Split(",")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$goos = go env GOOS
|
||||||
|
$goarch = go env GOARCH
|
||||||
|
$platforms = @("$goos/$goarch")
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-Path build) {
|
if (Test-Path build) {
|
||||||
Remove-Item -Recurse -Force build
|
Remove-Item -Recurse -Force build
|
||||||
}
|
}
|
||||||
@ -23,7 +42,11 @@ foreach ($platform in $platforms) {
|
|||||||
if ($env:GOOS -eq "windows") {
|
if ($env:GOOS -eq "windows") {
|
||||||
$output = "$output.exe"
|
$output = "$output.exe"
|
||||||
}
|
}
|
||||||
go build -o $output -ldflags $ldflags ./cmd/
|
go build -o $output -tags=gpl -ldflags $ldflags -trimpath ./cmd/
|
||||||
|
if ($LastExitCode -ne 0) {
|
||||||
|
Write-Host "Error: failed to build $env:GOOS/$env:GOARCH" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Build complete." -ForegroundColor Green
|
Write-Host "Build complete." -ForegroundColor Green
|
||||||
|
29
build.sh
29
build.sh
@ -1,16 +1,29 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Hysteria local build script for Linux
|
# Hysteria build script for Linux
|
||||||
|
# Environment variable options:
|
||||||
# Change these to whatever you want
|
# - HY_APP_VERSION: App version
|
||||||
platforms=("windows/amd64" "linux/amd64" "darwin/amd64")
|
# - HY_APP_COMMIT: App commit hash
|
||||||
ldflags="-s -w"
|
# - HY_APP_PLATFORMS: Platforms to build for (e.g. "windows/amd64,linux/amd64,darwin/amd64")
|
||||||
|
|
||||||
if ! [ -x "$(command -v go)" ]; then
|
if ! [ -x "$(command -v go)" ]; then
|
||||||
echo 'Error: go is not installed.' >&2
|
echo 'Error: go is not installed.' >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ldflags="-s -w -X 'main.appDate=$(date -u '+%F %T')'"
|
||||||
|
if [ -n "$HY_APP_VERSION" ]; then
|
||||||
|
ldflags="$ldflags -X 'main.appVersion=$HY_APP_VERSION'"
|
||||||
|
fi
|
||||||
|
if [ -n "$HY_APP_COMMIT" ]; then
|
||||||
|
ldflags="$ldflags -X 'main.appCommit=$HY_APP_COMMIT'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$HY_APP_PLATFORMS" ]; then
|
||||||
|
HY_APP_PLATFORMS="$(go env GOOS)/$(go env GOARCH)"
|
||||||
|
fi
|
||||||
|
platforms=(${HY_APP_PLATFORMS//,/ })
|
||||||
|
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
rm -rf build/*
|
rm -rf build/*
|
||||||
|
|
||||||
@ -24,7 +37,11 @@ for platform in "${platforms[@]}"; do
|
|||||||
if [ $GOOS = "windows" ]; then
|
if [ $GOOS = "windows" ]; then
|
||||||
output="$output.exe"
|
output="$output.exe"
|
||||||
fi
|
fi
|
||||||
env GOOS=$GOOS GOARCH=$GOARCH go build -o $output -ldflags "$ldflags" ./cmd/
|
env GOOS=$GOOS GOARCH=$GOARCH go build -o $output -tags=gpl -ldflags "$ldflags" -trimpath ./cmd/
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: failed to build $GOOS/$GOARCH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Build complete."
|
echo "Build complete."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user