bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 661 forks source link

cgocall doesn't work #2396

Open dtbartle opened 4 years ago

dtbartle commented 4 years ago

What version of rules_go are you using?

0.22.1

What version of gazelle are you using?

0.19.0

What version of Bazel are you using?

2.2.0

Does this issue reproduce with the latest releases of all the above?

Yes.

What operating system and processor architecture are you using?

Mac/Darwin

Any other potentially useful information about your toolchain?

What did you do?

Enabled cgocall analyzer via nogo.

What did you expect to see?

No errors.

What did you see instead?

I received an error that the original go file can't be opened. This is possibly because of #2271.

I'm curious if this is something specific to my setup, or if anyone has gotten this to work. If not, it might make sense to remove cgocall from the "tools_nogo" rule until this is fixed?

jayconrod commented 4 years ago

This is a bug, not specific to your setup. I don't think it's related to #2271. The GoCompilePkg action is responsible for running nogo, and it has access to both the raw cgo files and the generated go files (it's also responsible for running cgo). However, it only passes the generated go files to nogo.

I'm not exactly sure how the raw files need to be plumbed in, and unfortunately I don't have bandwidth to look into it right now. I'll remove cgocall from tools_nogo until it can be fixed.

sluongng commented 7 months ago

@emmaxy I wonder if you could take a look at this issue after https://github.com/bazelbuild/rules_go/pull/3770/

My original hope in https://github.com/bazelbuild/rules_go/pull/3770#issuecomment-1831986344 was to turn on cgocall after your PR is merged. But it seems that cgocall could still fail in some cases.

Here is an example failure in buildbuddy code base with cgocall turned on

compilepkg: nogo: errors found by nogo during build-time code analysis:
analyzer "cgocall" failed: can't parse raw cgo file: open /tmp/rules_go_work-128458798/cgo/github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/copy_on_write/cow_cgo_testutil/75e0fdb9-ef74-46fa-ab50-4c0915bdc144/enterprise/server/remote_execution/copy_on_write/cow_cgo_testutil/cow_cgo_testutil.go: no such file or directory

for this file https://github.com/buildbuddy-io/buildbuddy/blob/ed17796cadb4347401f7b3cfbb7223a973fb32bf/enterprise/server/remote_execution/copy_on_write/cow_cgo_testutil/cow_cgo_testutil.go#L1