diff --git a/common/build-style/go.sh b/common/build-style/go.sh index c16baa12380..50524b07f76 100644 --- a/common/build-style/go.sh +++ b/common/build-style/go.sh @@ -32,8 +32,13 @@ do_build() { go_package=${go_package:-$go_import_path} # Build using Go modules if there's a go.mod file if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then + + if [[ -n "${_go_mod_path}" ]]; then + pushd $(dirname ${_go_mod_path}) + fi + # Check if go_import_path matches module - if [ "module $go_import_path" != "$(head -n1 go.mod)" ]; then + if [ "module $go_import_path" != "$(grep '^module' go.mod | head -n1)" ]; then msg_error "\"\$go_import_path\" doesn't match the one defined in go.mod!\n" fi @@ -46,6 +51,9 @@ do_build() { go_mod_mode= fi go install -p "$XBPS_MAKEJOBS" -mod="${go_mod_mode}" -modcacherw -v -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} + if [[ -n "${_go_mod_path}" ]]; then + popd + fi else # Otherwise, build using GOPATH go get -p "$XBPS_MAKEJOBS" -v -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} diff --git a/common/environment/build-style/go.sh b/common/environment/build-style/go.sh index 68f88c6dbee..30945552207 100644 --- a/common/environment/build-style/go.sh +++ b/common/environment/build-style/go.sh @@ -39,6 +39,10 @@ export CGO_CXXFLAGS="$CXXFLAGS" export CGO_LDFLAGS="$LDFLAGS" export CGO_ENABLED="${CGO_ENABLED:-1}" export GO111MODULE=auto +export GOTOOLCHAIN=local +export GOPROXY="https://proxy.golang.org,direct" +export GOSUMDB="sum.golang.org" + case "$XBPS_TARGET_MACHINE" in *-musl) export GOCACHE="${XBPS_HOSTDIR}/gocache-muslc" ;; *) export GOCACHE="${XBPS_HOSTDIR}/gocache-glibc" ;;