ziglang / zig-mode

Zig mode for Emacs
GNU General Public License v3.0
166 stars 55 forks source link

zig-run for files with external dependencies #96

Closed corpix closed 6 months ago

corpix commented 8 months ago

Let's say I have src/main.zig with following:

const std = @import("std");
const zap = @import("zap");

...

I have zap defined in build.zig & build.zig.zon, zig build succeeds. But when I try to zig-runfrom Emacs it fails with:

main.zig:2:21: error: no package named 'zap' available within package 'root'

I probably know why it happens (sorry I am relatively new to Zig), because zig run does not play well with build.zig. But doesn't this make zig run and zig-run Emacs function useless for larger (and practical) projects?

How do you run your code from within Emacs while making projects with Zig?

joachimschmidt557 commented 6 months ago

zig-run will not use a build.zig even if one is present. For larger projects, you're right, it's very unlikely to be used, but for small single-file "scratchpads" it can be useful.

https://github.com/ziglang/zig-mode/blob/b6f5375efeb97026410190f352f1044214fa0289/zig-mode.el#L107

99 is a proposal to add zig build run as a new function. I'll close this issue in favor of that one. If you think this topic deserves a separate issue, we can reopen this again.