golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.8k stars 730 forks source link

plugin was built with a different version of package internal #3116

Open JCzz opened 6 months ago

JCzz commented 6 months ago

Hi there

I am compiling golang plugin from code, and then read in the plugin again - for reading in code dynamic.

This works great from the terminal, but the problem is that when reading in the plugin using vscode debugger, the build flags are not the same as when I build the plugin.

Example:

  1. I build using: commands := []string{"build", "-buildmode=plugin", "-o", pluginPathSo, pluginPathGo}
  2. Reading in the plugin with plug, err := plugin.Open(path) I get "plugin was built with a different version of package internal"

Problem

I can solve the problem using the same build flags as vscode, when building my plugin, but I dont know what build flags vscode is using?

findleyr commented 6 months ago

CC @hyangah @suzmue

Can you please share your settings.json?

JCzz commented 6 months ago

I only have: "go.toolsManagement.autoUpdate": true,

in my settings.json file

hyangah commented 6 months ago

Can you check if the environment variables and the go command shown in "Go: Locate Configured Go Tools" match the env var and go command used when you were building the plugin?

JCzz commented 6 months ago

Good question @hyangah

VSCode: GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/ws/r3lmtqdj03d3jn5l3v3t_s3w0000gn/T/go-build1156416228=/tmp/go-build -gno-record-gcc-switches -fno-common' Go env: GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/ws/r3lmtqdj03d3jn5l3v3t_s3w0000gn/T/go-build53071494=/tmp/go-build -gno-record-gcc-switches -fno-common'

From the above very long line, there is a difference in: VSCode / go env: -ffile-prefix-map=/var/folders/ws/r3lmtqdj03d3jn5l3v3t_s3w0000gn/T/go-build1156416228=/tmp/go-build -ffile-prefix-map=/var/folders/ws/r3lmtqdj03d3jn5l3v3t_s3w0000gn/T/go-build53071494=/tmp/go-build

hyangah commented 6 months ago

Do GOROOT values & path to the go command match?

JCzz commented 6 months ago

Yes, only "-ffile-prefix-map=/var/folders/.......=/tmp/go-build" described above mismatch

hyangah commented 6 months ago

That is a temporary directory so I doubt that matters. I don't know what makes the difference but you can try to pass build flags to the go command and the delve and compare what's going on.

For go command used for building the plugin, use -x -v to see details. For delve, add that -x -v flags to buildFlags https://github.com/golang/vscode-go/wiki/debugging#configuration in the launch configuration, and add fields to enable logging (https://github.com/golang/vscode-go/wiki/debugging#collect-logs). That will print build details in DEBUG OUTPUT tab.

JCzz commented 6 months ago

Unable to set it up correctly, can you please help - thanks.

Tried the following:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "showLog": true,
            "logOutput": "dap",
            "buildFlags": [

            ]
        },
    ]
}

But I dont know how to "For delve, add that -x -v flags to buildFlags"?

Thanks in advance