vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

plugin was built with a different version of package internal

Open JCzz opened this issue 1 year ago • 8 comments

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?

JCzz avatar Jan 05 '24 22:01 JCzz

CC @hyangah @suzmue

Can you please share your settings.json?

findleyr avatar Jan 08 '24 16:01 findleyr

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

in my settings.json file

JCzz avatar Jan 08 '24 19:01 JCzz

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?

hyangah avatar Jan 08 '24 19:01 hyangah

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

JCzz avatar Jan 08 '24 19:01 JCzz

Do GOROOT values & path to the go command match?

hyangah avatar Jan 08 '24 22:01 hyangah

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

JCzz avatar Jan 08 '24 22:01 JCzz

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.

hyangah avatar Jan 09 '24 17:01 hyangah

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

JCzz avatar Jan 14 '24 13:01 JCzz