bazel-contrib / bazel-contrib/rules_go

Proper way to import go_proto_library gRPC generated service Go file in VSCode?

Open
#3,228 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?
v0.32.0

### What version of gazelle are you using?
v0.25.0

### What version of Bazel are you using?
Build label: 5.2.0

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

### What did you do?
Successfully used rules_go to build a gRPC service:
```
go_proto_library(
name = "processor_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/vymao/Anthem/back-end/main/services/shared/proto/processor",
proto = ":processor_proto",
deps = ["//services/shared/proto/common:common_go_proto"],
)
```
However, I'm not sure how to import the resulting file. The generated file is nested under `bazel_bin` and under the original proto file path. Just importing this generated file based on the path specified in the `option go_package` field in the proto doesn't seem to work. For example, if I specify `option go_package = github.com/test/path/to/proto`, and if I then try to do `import github.com/test/path/to/proto` in my Go file after building the proto, this does not build.

### What did you expect to see?
A successful import.

### What did you see instead?
```
ERROR: /Users/victor/Desktop/Anthem/back-end/main/server/app/router/BUILD.bazel:3:11: GoCompilePkg server/app/router/router.a failed: (Exit 1): builder failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src server/app/router/handlerFunctions.go -src ... (remaining 43 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
server/app/router/handlerFunctions.go:19:16: undefined: processor.Processor
compilepkg: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/compile: exit status 2
Target //server/app/router:router failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.202s, Critical Path: 0.46s
INFO: 3 processes: 2 internal, 1 darwin-sandbox.
FAILED: Build did NOT complete successfully
```

Is there a way around this? Is there a better IDE to use?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with the go_proto_library target in the mentioned BUILD.bazel file and the import or reference in server/app/router/handlerFunctions.go. Check how the processor proto's go_package and generated gRPC service are exposed to the router target, then run the reported Bazel build. Done means the router target builds and processor.Processor resolves successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, vscode
Domain
build-system, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.