thought-machine / please

High-performance extensible build system for reproducible multi-language builds.
https://please.build
Apache License 2.0
2.48k stars 207 forks source link

Please can not find the yaml target. However it does exist. #3284

Closed PeterBocan closed 3 weeks ago

PeterBocan commented 3 weeks ago

Hello peeps, I am struggling to reason why the go_repo is not being correctly registered in the build graph. (Please version: 17.12.1)


go_library(
    name = "project",
    srcs = ["project.go"],
    visibility = ["PUBLIC"],
    deps = [
        "//third_party/go:yaml.v3",
    ],
)
❯ plz build //...
Build stopped after 230ms. 1 target failed:
    //pkg/project:project
Error building target //pkg/project:project: exit status 1
pkg/project/project.go, line 8, column 7: could not import gopkg.in/yaml.v3 (open : no such file or directory)

my third_party/go/BUILD is as follows:

package(default_visibility = ["PUBLIC"])

go_toolchain(
    name = "toolchain",
    version = "1.23.2",
)

go_stdlib(name = "std")

go_repo(
    name = "yaml.v3",
    module = "gopkg.in/yaml.v3",
    version = "v3.0.1",
    visibility = ["PUBLIC"],
)

go_repo(module="gopkg.in/check.v1", version="v0.0.0-20161208181325-20d25e280405")

and query alltargets says:

//plugins:go
//third_party/go:gopkg.in_check.v1
//third_party/go:std
//third_party/go:toolchain
//third_party/go:toolchain_compile
//third_party/go:toolchain_cover
//third_party/go:toolchain_link
//third_party/go:yaml.v3

It is very similar to #3084

toastwaffle commented 3 weeks ago

When using go_repo, a subrepo is generated for the third party library. Your dependency should be something like "///third_party/go/gopkg.in_yaml.v3//:yaml.v3".

I recommend making use of Puku, as it will configure your dependencies for you

Tatskaari commented 3 weeks ago

To add to what @toastwaffle said, if you prefer a UX closer to how go_module() works, you can add the packages you want to the install list and then depend on //third_party/go:yaml.v3:

go_repo(
    name = "yaml.v3",
    module = "gopkg.in/yaml.v3",
    install = ["."],
    version = "v3.0.1",
    visibility = ["PUBLIC"],
)

but puku fmt -w will update your build files automatically for you :D