Skip to content
New issue

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

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

Already on GitHub? # to your account

Update build flags to make -trimpath go flag configurable #82

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Dec 20, 2023

Context and Problem

While working on integrating the Streams API into k6 using xk6 extensions, I encountered a significant challenge in debugging with VSCode. Specifically, the debugger could not associate breakpoints with the correct file paths. This issue stems from the -trimpath argument in our build process, which removes file system paths from the executable, thus hindering the debugger's ability to function correctly.

Solution

This PR modifies the build process for xk6 extensions. By adjusting where and how the -trimpath flag is applied, we allow extension developers to override this setting using the XK6_BUILD_FLAGS environment variable. This change offers more flexibility in preserving debug symbols and optimizing the debugging experience in VSCode.

For the history books: Debugging in VSCode using this fix

For those looking to debug xk6 extensions in VSCode, here's a guide based on my setup:

Build Task Configuration

Create a VSCode task to build the xk6 binary with the necessary flags for debugging. This task utilizes the changes introduced in this PR. Here's the configuration in tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "command": "xk6",
            "args": [
                "build",
                "--with",
                "github.com/grafana/xk6-streams=.",  // Replace with your extension
                "--output",
                "${workspaceFolder}/k6"
            ],
            "group": "build",
            "label": "xk6: build",
            "options": {
                "env": {
                    "XK6_BUILD_FLAGS": "-gcflags 'all=-N -l'"
                }
            }
        }
    ]
}

Define a launch.json file in VSCode to run the above build task before starting the debugger. Here's the configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "xk6",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            "preLaunchTask": "xk6: build",
            "cwd": "${workspaceFolder}",
            "program": "${workspaceFolder}/k6",
            "args": ["run", "${workspaceFolder}/examples/readablestream-numbers.js"]
        }
    ]
}

References

ref #51
ref #43

@oleiade oleiade requested a review from a team as a code owner December 20, 2023 15:47
@oleiade oleiade added the enhancement New feature or request label Dec 20, 2023
@oleiade oleiade self-assigned this Dec 20, 2023
@oleiade oleiade marked this pull request as draft December 20, 2023 15:54
@oleiade oleiade marked this pull request as ready for review December 20, 2023 15:57
Copy link
Collaborator

@pablochacin pablochacin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@oleiade oleiade merged commit ff146f7 into master Jan 30, 2024
8 checks passed
@oleiade oleiade deleted the feature/goflags branch January 30, 2024 14:32
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants