FalsePattern / ZigBrains

The zig language plugin for intellij
https://plugins.jetbrains.com/plugin/22456-zigbrains
Other
105 stars 7 forks source link

Debugging once using Zig Build with dependencies defined in build.zig.zon #41

Closed timsavage closed 5 months ago

timsavage commented 6 months ago

This may be a limitation of the zig tooling rather than this plugin.

Using a Zig-Run does not use the build.zig and build.zig.zon dependencies causing builds to fail where dependencies are required.

Using a Zig-Build will successfully build, and adding the run argument will allow a build to subsequently be run. However, the debugger gets stuck at Connecting. Have tested with both GDB and LLDB.

Plugin version: 13.1.1-233 CLion version: 2023.3.4 Zig: 0.12....nightly ZLS: 0.12...nightly OS: Ubuntu 22.04

timsavage commented 6 months ago

After investigating more, I've found this is more of an issue with the Zig toolchain.

For anybody encountering this problem, here is how to work around the issue and get things working.

  1. Once you start using zig build with dependencies - ZigTest and ZigRun will no longer work (will cause build failures)
  2. Replace all of your run configs with the build versions:
    • Create a ZigBuild configuration with the Extra command line arguments test for tests
  3. For Debugging, add a Native Application run config
    • You may need to add a target
    • Select the executable generated by your build in ./zig-out/bin
    • In the Before Launch section, replace any actions with your ZigBuild Build run-config so any re-compilation is done on run.

It would be nice if the plugin could handle some of this work, but this is a suitable workaround. Before-lanch does have an annoying side effect where if there are build errors, the binary is still run rather than stopping at the failure.

Will leave this issue open so the plugin author can determine if they want to take any action.

FalsePattern commented 5 months ago

The plugin already supports this, in the ZigBuild task type, you need to directly specify the executable generated by your zig build inside the task itself, this is effectively what you're doing with the Native Application solution, but integrated with the toolchain system.

image

Unfortunately i have not yet figured out a way to fully automate this without requiring the user to add extra code to build.zig.

timsavage commented 5 months ago

Would it be possible to add command line arguments for the executable?

FalsePattern commented 5 months ago

Yep, i will add that in the next update

FalsePattern commented 5 months ago

Fixed in 13.2.0, debugging Zig build type intellij tasks should now work, even if you set the build step to run. If the exe path is not specified, it will try finding it automatically on a best effort basis, assuming that there is a single executable file inside ./zig-out/bin after running the build, otherwise it will just require you to set the exe path in the intellij task like before.

timsavage commented 5 months ago

Thanks very much, that works good.

Cheers