cue-lang/cue

cmd/cue: get go generates packages conflicting with the standard library

Opened this issue ยท 8 comments

Originally opened by @myitcv in cuelang/cue#648

What version of CUE are you using (cue version)?

$ cue version
cue version +f0c025c1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

cat <<'EOD' | testscript -v
exec go mod init blah
exec cue mod init blah.com
exec go get mvdan.cc/sh/v3@v3.2.1
exec cue get go mvdan.cc/sh/v3/...
exec cue def mvdan.cc/sh/v3/syntax
EOD

What did you expect to see?

Success.

What did you see instead?

> exec go mod init blah
[stderr]
go: creating new go.mod: module blah
> exec cue mod init blah.com
> exec go get mvdan.cc/sh/v3
[stderr]
go: mvdan.cc/sh/v3 upgrade => v3.2.1
> exec cue get go mvdan.cc/sh/v3/...
> exec cue def mvdan.cc/sh/v3/syntax
[stderr]
package "io" not found:
    ./cue.mod/gen/mvdan.cc/sh/v3/syntax/parser_go_gen.cue:7:8
[exit status 1]

Per offline discussion with @mpvl, Go standard library packages need to mapped to a domain-qualified module path. Perhaps something like golang.org/pkg/io etc.

Original reply by @myitcv in cuelang/cue#648 (comment)

Another good test case here is goreleaser/goreleaser#2065

sjwl commented

still a problem with v0.5.0-beta.2

cue get go github.com/helmfile/helmfile/pkg/helmexec
cue def github.com/helmfile/helmfile/pkg/helmexec 
builtin package "io" undefined:
    ./cue.mod/gen/github.com/helmfile/helmfile/pkg/helmexec/context_go_gen.cue:7:8

My Workaround:

  1. move cue.mod/gen/io/ to cue.mod/pkg/golang.org/pkg/io/
  2. move cue.mod/gen/github.com/helmfile/helmfile/pkg/helmexec/ to cue.mod/pkg/github.com/helmfile/helmfile/pkg/helmexec/
  3. modify cue.mod/pkg/github.com/helmfile/helmfile/pkg/helmexec/context_go_gen.cue

from

import "io"

to

import "golang.org/pkg/io"
mvdan commented

Multiple duplicates of this issue have been filed, so in the hopes of making this issue more discoverable, I've given it a slightly more specific title.

myitcv commented

Dropping the now-defunct v0.4.x milestone from this issue, but leaving the zGarden label such that we come round to considering what milestone this should sit in.

yujunz commented

Per offline discussion with @mpvl, Go standard library packages need to mapped to a domain-qualified module path. Perhaps something like golang.org/pkg/io etc.

Or pkg.go.dev/io?

Are we getting any closer to resolving this issue?

I've run into a similar issue relative to sigstore.

$ cue eval    
builtin package "reflect" undefined:
    ./cue.mod/gen/github.com/sigstore/k8s-manifest-sigstore/pkg/util/mapnode/node_go_gen.cue:7:8

See: https://github.com/bradbeck/k8s-cue

I've just ran into the same issue importing the cilium api with cue get go github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2

builtin package "reflect" undefined:
    ./cue.mod/gen/github.com/go-openapi/strfmt/format_go_gen.cue:7:8

I've run into this tying to get the Kyverno schema. Fails with same sigstore error as @bradbeck but adding it here for searchability.

go get github.com/kyverno/kyverno/api/kyverno/v1
cue get go github.com/kyverno/kyverno/api/kyverno/v1
builtin package "reflect" undefined:
    ./cue.mod/gen/github.com/sigstore/k8s-manifest-sigstore/pkg/util/mapnode/node_go_gen.cue:7:8

# but also:
builtin package "internal/abi" undefined:
    ./cue.mod/gen/pkg.go.dev/pkg/reflect/type_go_gen.cue:18:8

I was able to use @sjwl 's workaround. But I feel like that's going to blow up in my face one day :)