wire icon indicating copy to clipboard operation
wire copied to clipboard

Go workspaces broken in 1.24rc2

Open nstandif opened this issue 11 months ago • 3 comments

What version of Go are you using (go version)?

$ go version
go version go1.24rc2 darwin/arm64

Does this issue reproduce with the latest release?

I am running the 1.24rc2 toolchain.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/nathan/go/bin'
GOCACHE='/Users/nathan/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/nathan/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/rw/w0xs2vj159b0np2r601b709w0000gn/T/go-build503003425=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/nathan/git/tule/connector/go.mod'
GOMODCACHE='/Users/nathan/go/pkg/mod'
GONOPROXY='buf.build/gen/go,github.com/stratus-ai'
GONOSUMDB='buf.build/gen/go,github.com/stratus-ai'
GOOS='darwin'
GOPATH='/Users/nathan/go'
GOPRIVATE='buf.build/gen/go,github.com/stratus-ai'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/nathan/go/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/nathan/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/nathan/go/pkg/mod/golang.org/[email protected]/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24rc2'
GOWORK='/Users/nathan/git/tule/go.work'
PKG_CONFIG='pkg-config'
GOROOT/bin/go version: go version go1.24rc2 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.24rc2
uname -v: Darwin Kernel Version 24.2.0: Fri Dec  6 19:03:40 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6041
ProductName:		macOS
ProductVersion:		15.2
BuildVersion:		24C101
lldb --version: lldb-1600.0.39.109
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)

What did you do?

Ran go generate in a main module in a workspace containing wire injectors.

//go:build wireinject
// +build wireinject

package main

import (
	"github.com/google/wire"
          ...
)

var SuperSet = wire.NewSet(...)

func initializeSvcCmd() *cmd.SvcCmd {
	panic(wire.Build(SuperSet))
}

What did you expect to see?

No errors.

What did you see instead?

$ go generate
go: -mod may only be set to readonly or vendor when in workspace mode, but it is set to "mod"
	Remove the -mod flag to use the default readonly value, 
	or set GOWORK=off to disable workspace mode.
wire_gen.go:3: running "go": exit status 1

In wire_gen.go, this is produced:

// Code generated by Wire. DO NOT EDIT.

//go:generate go run -mod=mod github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject

For now, the workaround would be to set GOWORK=off env variable when running go generate. However, this may may be overlooked in a CI/CD pipeline.

nstandif avatar Jan 27 '25 22:01 nstandif

This workaround will also not work if you try to generate while using workspaces

ralf-cestusio avatar Jan 28 '25 19:01 ralf-cestusio

@giautm Workspaces is broken because of -mod=mod in pr#353 merge.

nstandif avatar Feb 14 '25 00:02 nstandif

Every time I remove the -mod=mod and then run go run github.com/google/wire/cmd/wire the output file add the -mod=mod in to the source code.

Next time I have to remove the -mod=mod again.

So I write a script to fix this problem.

	const matchOriginLine = "//go:generate go run -mod=mod github.com/google/wire/cmd/wire"
	const changeToNewLine = "//go:generate go run github.com/google/wire/cmd/wire"
        // then replace code

I think you should add a flag to the wire: Such as //go:generate go run github.com/google/wire/cmd/wire -waliwali=notmod then we can use this every time and it generate the target code also //go:generate go run github.com/google/wire/cmd/wire -waliwali=notmod. Then I can run it every time without change any thing. thank you.

yyle88 avatar Jul 05 '25 10:07 yyle88