google / gvisor

Application Kernel for Containers
https://gvisor.dev
Apache License 2.0
15.63k stars 1.29k forks source link

bazel :gopath not working properly #3854

Closed nanikjava closed 4 years ago

nanikjava commented 4 years ago

The following doc https://gvisor.dev/contributing/ outlined the way to generate GOPATH directories allowing developers to use IDE to do gvisor development.

The command bazel build :gopath generate the directory structure but when compiling using the following command it produces error

GOPATH=/home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/bazel-bin/gopath go build -o exe gvisor.dev/gvisor/runsc

error produced

go: finding module for package gvisor.dev/gvisor/pkg/sentry/arch/registers_go_proto
go: finding module for package gvisor.dev/gvisor/pkg/sentry/strace/strace_go_proto
go: finding module for package gvisor.dev/gvisor/pkg/eventchannel/eventchannel_go_proto
go: finding module for package gvisor.dev/gvisor/pkg/sentry/unimpl/unimplemented_syscall_go_proto
go: finding module for package gvisor.dev/gvisor/pkg/sentry/kernel/uncaught_signal_go_proto
go: finding module for package gvisor.dev/gvisor/pkg/metric/metric_go_proto
pkg/eventchannel/event.go:29:2: no matching versions for query "latest"
pkg/metric/metric.go:25:2: no matching versions for query "latest"
pkg/sentry/kernel/abstract_socket_namespace.go:22:2: found packages refs_vfs2 (refs.go) and refs_template (refs_template.go) in /home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/pkg/refs_vfs2
pkg/sentry/platform/platform.go:26:2: found packages seccomp (seccomp.go) and main (seccomp_test_victim.go) in /home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/pkg/seccomp
pkg/sentry/arch/arch_x86.go:27:2: no matching versions for query "latest"
pkg/sentry/kernel/kernel.go:55:2: found packages benchmark (benchmark_test.go) and tmpfs (device_file.go) in /home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/pkg/sentry/fsimpl/tmpfs
pkg/sentry/kernel/task_signals.go:28:2: no matching versions for query "latest"
pkg/sentry/strace/socket.go:25:2: found packages netlink (message.go) and message (message_test.go) in /home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/pkg/sentry/socket/netlink
pkg/sentry/strace/strace.go:34:2: no matching versions for query "latest"
pkg/sentry/kernel/kernel.go:71:2: no matching versions for query "latest"
pkg/linewriter/linewriter.go:21:2: found packages sync (aliases.go) and template (atomicptr_unsafe.go) in /home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/pkg/sync
pkg/sentry/socket/netstack/netstack.go:61:2: found packages tcp (accept.go) and rcv (rcv_test.go) in /home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/pkg/tcpip/transport/tcp
nanikjava commented 4 years ago

Copied main.go and version.go to src/gvisor.dev/gvisor/bazel-bin/gopath/src/gvisor.dev/gvisor/runsc/ and compile it with the following command

GOPATH=/home/nanik/Downloads/temp/packages/src/gvisor.dev/gvisor/bazel-bin/gopath GO111MODULE=off go build -o exe gvisor.dev/gvisor/runsc/

it works.

Looks like the problem is bazel for some reasons are not symlinking the main.go and version.go inside runsc/

nanikjava commented 4 years ago

More info about local bazel installation:

Build label: 3.5.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Sep 2 20:11:46 2020 (1599077506)
Build timestamp: 1599077506
Build timestamp as int: 1599077506
ianlewis commented 4 years ago

I think this is because the :gopath wasn't necessarily intended to be a way to build runsc (or other binaries). But rather a way to export gvisor's library packages so they could be used by an editor like vim-go or VSCode. We don't provide instructions to build from there for that reason.

From https://gvisor.dev/contributing/

If you use this mechanism, keep in mind that the generated tree is not the canonical source. You will still need to build and test with bazel.

I think you'll still want to edit the original files (not via the links in GOPATH) and build using bazel build ... and set your editor up to do that rather than using the Go compiler directly.

nanikjava commented 4 years ago

Thanks @ianlewis

Since there is go branch wouldn't it be easier for contributor to work using that branch as you mentioned that it is based on the master branch ?

Maybe this should be mentioned inside the contributing page ?. Happy to take this on if that make sense ?