Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vymao opened this issue Jul 5, 2022 · 3 comments

Comments

@vymao
Copy link

vymao commented Jul 5, 2022

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?

@vymao vymao changed the title Proper way to import go_proto_library gRPC generated service Go file in VSCode? Proper way to import go_proto_library gRPC generated service Go file? Jul 5, 2022
@vymao vymao changed the title Proper way to import go_proto_library gRPC generated service Go file? Proper way to import go_proto_library gRPC generated service Go file in VSCode? Jul 5, 2022
@achew22
Copy link
Member

achew22 commented Jul 6, 2022

Have you set up VSCode to use the LSP plugin?

https://github.com/bazelbuild/rules_go/wiki/Editor-setup#visual-studio-code

@vymao
Copy link
Author

vymao commented Jul 7, 2022

Thanks for this. I think I may be running into a similar issue as this. Right now, my settings.json file looks like this:

{
    "files.associations": {
        "iosfwd": "cpp",
        "stdexcept": "cpp",
        "__bit_reference": "cpp",
        "__bits": "cpp",
        "__config": "cpp",
        "__debug": "cpp",
        "__errc": "cpp",
        "__functional_base": "cpp",
        "__hash_table": "cpp",
        "__locale": "cpp",
        "__mutex_base": "cpp",
        "__node_handle": "cpp",
        "__nullptr": "cpp",
        "__split_buffer": "cpp",
        "__string": "cpp",
        "__threading_support": "cpp",
        "__tree": "cpp",
        "__tuple": "cpp",
        "algorithm": "cpp",
        "any": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "bit": "cpp",
        "bitset": "cpp",
        "cctype": "cpp",
        "cfenv": "cpp",
        "chrono": "cpp",
        "cinttypes": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "codecvt": "cpp",
        "complex": "cpp",
        "condition_variable": "cpp",
        "csignal": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cstring": "cpp",
        "ctime": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "exception": "cpp",
        "forward_list": "cpp",
        "fstream": "cpp",
        "functional": "cpp",
        "future": "cpp",
        "initializer_list": "cpp",
        "iomanip": "cpp",
        "ios": "cpp",
        "iostream": "cpp",
        "istream": "cpp",
        "iterator": "cpp",
        "limits": "cpp",
        "list": "cpp",
        "locale": "cpp",
        "map": "cpp",
        "memory": "cpp",
        "mutex": "cpp",
        "new": "cpp",
        "numeric": "cpp",
        "optional": "cpp",
        "ostream": "cpp",
        "queue": "cpp",
        "random": "cpp",
        "ratio": "cpp",
        "regex": "cpp",
        "scoped_allocator": "cpp",
        "set": "cpp",
        "sstream": "cpp",
        "stack": "cpp",
        "streambuf": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "thread": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "typeindex": "cpp",
        "typeinfo": "cpp",
        "unordered_map": "cpp",
        "unordered_set": "cpp",
        "utility": "cpp",
        "valarray": "cpp",
        "variant": "cpp",
        "vector": "cpp",
        "*.inc": "cpp"
    },
    "go.goroot": "${workspaceFolder}/bazel-main/external/go_sdk",
    "go.toolsEnvVars": {
      "GOPACKAGESDRIVER": "${workspaceFolder}/tools/gopackagesdriver.sh"
    },
    "go.enableCodeLens": {
      "references": false,
      "runtest": false
    },
    "gopls": {
      "build.directoryFilters": [
        "-bazel-bin",
        "-bazel-out",
        "-bazel-testlogs",
        "-bazel-main",
      ],
      "formatting.gofumpt": true,
      "formatting.local": "github.com/vymao/Anthem/back-end/main",
      "ui.completion.usePlaceholders": true,
      "ui.semanticTokens": true,
      "ui.codelenses": {
        "gc_details": false,
        "regenerate_cgo": false,
        "generate": false,
        "test": false,
        "tidy": false,
        "upgrade_dependency": false,
        "vendor": false
      },
    },
    "go.useLanguageServer": true,
    "go.buildOnSave": "off",
    "go.lintOnSave": "off",
    "go.vetOnSave": "off",
}

Yet I get a notification like

Error loading workspace: no packages returned: packages.Load error

even after adding GOPACKAGESDRIVER_BAZEL_BUILD_FLAGS=--strategy=GoStdlibList=local to the tools/gopackagesdriver.sh file.

@lromor
Copy link

lromor commented Mar 13, 2023

Have the same issue. I'm using emacs, this is my dir-locals.el:

((go-mode . ((lsp-go-directory-filters . ["-bazel-bin" "-bazel-foo" "-bazel-out" "-bazel-testlogs" "-external"])
             (lsp-go-codelenses . nil)
             (lsp-go-env . ((GOPACKAGESDRIVER . "./tools/gopackagesdriver.sh"))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants