ziglang / sublime-zig-language

Zig language support for Sublime Text
MIT License
85 stars 25 forks source link

Zig build cwd #57

Closed cammm closed 1 year ago

cammm commented 3 years ago

Update the build step so that the cwd is always the project folder when using zig build / zig build run / zig build test. I was running into path problems running the build command otherwise.

When running commands against a file ie zig test then it keeps the path assigned to that specific file.

emekoi commented 3 years ago

could you elaborate on what kinds of path errors you were getting? i don't there should be any real issues with zig build unless you are using some sort of unusual structure. because of https://github.com/ziglang/zig/issues/2587 zig build should search up for the build.zig file.

cammm commented 3 years ago

There were 2 problems I ran into:

  1. I often like to add multiple folders to my sublime project, things like some reference code, maybe external libraries and the std library which exist outside of my project. If you happen to have a file outside of your project folder focused and run the build project it will fail. By using the sublime "folder" (the first folder referenced in the sublime workspace) then this use case works.

  2. I was getting some linker errors, but after setting up a minimal example I've realized it fails on the command line too just using "zig build" with the CWD inside of src instead of at the root of the project. So either my understanding of how to setup the build file is wrong, or there is a bug in the zig build itself since from the issue you linked it sounds like doing that should be possible.

If you disagree with 1. as a viable reason for this change I'm happy to close the PR and I'll continue investigating 2 regardless.

EDIT: The tldr on the linker error is I had exe.addLibPath("external/SDL2/lib/x64") when I actually needed to do exe.addLibPath(b.pathFromRoot("external/SDL2/lib/x64")) to ensure we have resolved absolute paths for everything.

emekoi commented 3 years ago

i see no issue with 1 as often do the exact same thing, but i neglected is to test that while i was writing the extension.