golang/go

cmd/go: doc: inconsistent handling of build tags, cgo, goexperiment

オープン

#76,829 opened on 2025/12/14

 (8 件のコメント) (2 件のリアクション) (0 人の担当者)Go (19,008 件のフォーク)batch import
GoCommandNeedsInvestigationToolProposalhelp wanted

Repository metrics

Stars
 (133,883 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

Go version

go version go1.26-devel_f2d96272cb 2025-12-08 10:58:21 -0800 linux/amd64

Output of go env in your module/workspace:

-g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT='jsonv2'
GOFIPS140='off'
GOFLAGS='-trimpath "-ldflags=-s -w" -vet=all'
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1893534021=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/user/tmp/testrepo1348/go.mod'
GOMODCACHE='/home/user/.data/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/.data/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='path'
GOTOOLDIR='/home/user/sdk/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26-devel_f2d96272cb 2025-12-08 10:58:21 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Run go doc:

-- c.go --
//go:build cgo

package xxx

// C is cgo
func C() {}
-- exp.go --
//go:build goexperiment.jsonv2

package xxx

// E is goexperiment
func E() {}
-- notc.go --
//go:build !cgo

package xxx

// C is !cgo
func C() {}
-- notexp.go --
//go:build !goexperiment.jsonv2

package xxx

// E is !goexperiment
func E() {}
-- nott.go --
//go:build !mytag

package xxx

// T is !mytag
func T() {}
-- t.go --
//go:build mytag

package xxx

// T is mytag
func T() {}

What did you see happen?

$ go doc -all
package xxx // import "go.seankhliao.com/testrepo1348"


FUNCTIONS

func C()
    C is cgo

func E()
    E is !goexperiment

func T()
    T is !mytag

go doc by default uses cgo, no goexperiment, no extra tags. It ignores CGO_ENABLED and GOEXPERIMENT set in the GOENV config file, but it does use those settings if they are set as environment variables.

Custom build tags are always ignored (including if set via GOFLAGS=-tags=...).

go doc -http ignores all optional tags.

What did you expect to see?

A -tags flag for go doc.

Handling of environment / tags consistent with other go commands like go build.

cc @golang/command-line

コントリビューターガイド