🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
build(netgo): make sure the project is always compiled with `netgo` build tag (#3428)
Deluan Quintão69e2a6d62094
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.ymlindex af936dac0..0684986e7 100644--- a/.github/workflows/pipeline.yml+++ b/.github/workflows/pipeline.yml@@ -102,7 +102,7 @@ jobs:- name: Testrun: |pkg-config --define-prefix --cflags --libs taglib # for debugging- go test -shuffle=on -race -cover ./... -v+ go test -shuffle=on -tags netgo -race -cover ./... -vjs:name: Test JS codediff --git a/.golangci.yml b/.golangci.ymlindex ecd3f79cf..8bb134098 100644--- a/.golangci.yml+++ b/.golangci.yml@@ -1,3 +1,7 @@+run:+ build-tags:+ - netgo+linters:enable:- asasalintdiff --git a/Makefile b/Makefileindex 233113d6f..234309cdb 100644--- a/Makefile+++ b/Makefile@@ -33,11 +33,11 @@ server: check_go_env buildjs ##@Development Start the backend in development mod.PHONY: serverwatch: ##@Development Start Go tests in watch mode (re-run when code changes)- go run github.com/onsi/ginkgo/v2/ginkgo@latest watch -notify ./...+ go run github.com/onsi/ginkgo/v2/ginkgo@latest watch -tags netgo -notify ./....PHONY: watchtest: ##@Development Run Go tests- go test -race -shuffle=on ./...+ go test -tags netgo -race -shuffle=on ./....PHONY: testtestall: test ##@Development Run Go and JS testsdiff --git a/conf/buildtags/buildtags.go b/conf/buildtags/buildtags.gonew file mode 100644index 000000000..5fc125087--- /dev/null+++ b/conf/buildtags/buildtags.go@@ -0,0 +1,4 @@+package buildtags++// This file is left intentionally empty. It is used to make sure the package is not empty, in the case all+// required build tags are disabled.diff --git a/conf/buildtags/netgo.go b/conf/buildtags/netgo.gonew file mode 100644index 000000000..0062ad2bc--- /dev/null+++ b/conf/buildtags/netgo.go@@ -0,0 +1,11 @@+//go:build netgo++package buildtags++// NOTICE: This file was created to force the inclusion of the `netgo` tag when compiling the project.+// If the tag is not included, the compilation will fail because this variable won't be defined, and the `main.go`+// file requires it.++// Why this tag is required? See https://github.com/navidrome/navidrome/issues/700++var NETGO = truediff --git a/main.go b/main.goindex 084cf8f2b..65db162ac 100644--- a/main.go+++ b/main.go@@ -4,8 +4,16 @@ import (_ "net/http/pprof" //nolint:gosec"github.com/navidrome/navidrome/cmd"+ "github.com/navidrome/navidrome/conf/buildtags")+//goland:noinspection GoBoolExpressionsfunc main() {+ // This import is used to force the inclusion of the `netgo` tag when compiling the project.+ // If you get compilation errors like "undefined: buildtags.NETGO", this means you forgot to specify+ // the `netgo` build tag when compiling the project.+ // To avoid these kind of errors, you should use `make build` to compile the project.+ _ = buildtags.NETGO+cmd.Execute()}