From 54c495d867ae610f9f0788eb9f97ead5d6cf624d Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Wed, 23 Nov 2022 09:10:39 +1100 Subject: [PATCH] Remove netgo build tag from Windows builds (#3170) --- Makefile | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 0594f15f4..fe7628a56 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,6 @@ else SET := export endif -IS_WIN_OS = -ifeq ($(OS),Windows_NT) - IS_WIN_OS = true -endif - # set LDFLAGS environment variable to any extra ldflags required # set OUTPUT to generate a specific binary name @@ -29,6 +24,11 @@ endif export CGO_ENABLED = 1 +# including netgo causes name resolution to go through the Go resolver +# and isn't necessary for static builds on Windows +GO_BUILD_TAGS_WINDOWS := sqlite_omit_load_extension sqlite_stat4 osusergo +GO_BUILD_TAGS_DEFAULT = $(GO_BUILD_TAGS_WINDOWS) netgo + .PHONY: release pre-build release: pre-ui generate ui build-release @@ -47,14 +47,21 @@ ifndef STASH_VERSION endif ifndef OFFICIAL_BUILD - $(eval OFFICIAL_BUILD := false) + $(eval OFFICIAL_BUILD := false) endif +ifndef GO_BUILD_TAGS + $(eval GO_BUILD_TAGS := $(GO_BUILD_TAGS_DEFAULT)) +endif + + +# NOTE: the build target still includes netgo because we cannot detect +# Windows easily from the Makefile. build: pre-build build: $(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/internal/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/internal/api.buildstamp=$(BUILD_DATE)' -X 'github.com/stashapp/stash/internal/api.githash=$(GITHASH)') $(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/internal/manager/config.officialBuild=$(OFFICIAL_BUILD)') - go build $(OUTPUT) -mod=vendor -v -tags "sqlite_omit_load_extension sqlite_stat4 osusergo netgo" $(GO_BUILD_FLAGS) -ldflags "$(LDFLAGS) $(EXTRA_LDFLAGS) $(PLATFORM_SPECIFIC_LDFLAGS)" ./cmd/stash + go build $(OUTPUT) -mod=vendor -v -tags "$(GO_BUILD_TAGS)" $(GO_BUILD_FLAGS) -ldflags "$(LDFLAGS) $(EXTRA_LDFLAGS) $(PLATFORM_SPECIFIC_LDFLAGS)" ./cmd/stash # strips debug symbols from the release build build-release: EXTRA_LDFLAGS := -s -w @@ -71,6 +78,7 @@ cross-compile-windows: export GOARCH := amd64 cross-compile-windows: export CC := x86_64-w64-mingw32-gcc cross-compile-windows: export CXX := x86_64-w64-mingw32-g++ cross-compile-windows: OUTPUT := -o dist/stash-win.exe +cross-compile-windows: GO_BUILD_TAGS := $(GO_BUILD_TAGS_WINDOWS) cross-compile-windows: build-release-static cross-compile-macos-intel: export GOOS := darwin @@ -78,6 +86,7 @@ cross-compile-macos-intel: export GOARCH := amd64 cross-compile-macos-intel: export CC := o64-clang cross-compile-macos-intel: export CXX := o64-clang++ cross-compile-macos-intel: OUTPUT := -o dist/stash-macos-intel +cross-compile-macos-intel: GO_BUILD_TAGS := $(GO_BUILD_TAGS_DEFAULT) # can't use static build for OSX cross-compile-macos-intel: build-release @@ -86,6 +95,7 @@ cross-compile-macos-applesilicon: export GOARCH := arm64 cross-compile-macos-applesilicon: export CC := oa64e-clang cross-compile-macos-applesilicon: export CXX := oa64e-clang++ cross-compile-macos-applesilicon: OUTPUT := -o dist/stash-macos-applesilicon +cross-compile-macos-applesilicon: GO_BUILD_TAGS := $(GO_BUILD_TAGS_DEFAULT) # can't use static build for OSX cross-compile-macos-applesilicon: build-release @@ -106,17 +116,20 @@ cross-compile-macos: cross-compile-freebsd: export GOOS := freebsd cross-compile-freebsd: export GOARCH := amd64 cross-compile-freebsd: OUTPUT := -o dist/stash-freebsd +cross-compile-freebsd: GO_BUILD_TAGS += netgo cross-compile-freebsd: build-release-static cross-compile-linux: export GOOS := linux cross-compile-linux: export GOARCH := amd64 cross-compile-linux: OUTPUT := -o dist/stash-linux +cross-compile-linux: GO_BUILD_TAGS := $(GO_BUILD_TAGS_DEFAULT) cross-compile-linux: build-release-static cross-compile-linux-arm64v8: export GOOS := linux cross-compile-linux-arm64v8: export GOARCH := arm64 cross-compile-linux-arm64v8: export CC := aarch64-linux-gnu-gcc cross-compile-linux-arm64v8: OUTPUT := -o dist/stash-linux-arm64v8 +cross-compile-linux-arm64v8: GO_BUILD_TAGS := $(GO_BUILD_TAGS_DEFAULT) cross-compile-linux-arm64v8: build-release-static cross-compile-linux-arm32v7: export GOOS := linux @@ -124,6 +137,7 @@ cross-compile-linux-arm32v7: export GOARCH := arm cross-compile-linux-arm32v7: export GOARM := 7 cross-compile-linux-arm32v7: export CC := arm-linux-gnueabihf-gcc cross-compile-linux-arm32v7: OUTPUT := -o dist/stash-linux-arm32v7 +cross-compile-linux-arm32v7: GO_BUILD_TAGS := $(GO_BUILD_TAGS_DEFAULT) cross-compile-linux-arm32v7: build-release-static cross-compile-linux-arm32v6: export GOOS := linux @@ -131,6 +145,7 @@ cross-compile-linux-arm32v6: export GOARCH := arm cross-compile-linux-arm32v6: export GOARM := 6 cross-compile-linux-arm32v6: export CC := arm-linux-gnueabi-gcc cross-compile-linux-arm32v6: OUTPUT := -o dist/stash-linux-arm32v6 +cross-compile-linux-arm32v6: GO_BUILD_TAGS := $(GO_BUILD_TAGS_DEFAULT) cross-compile-linux-arm32v6: build-release-static cross-compile-all: