Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Included the option to call zig build run from the project root. #74

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alexjgriffith
Copy link

For interactive projects its nice to do a quick build run from any file your working on.

The new zig-project-build-run interactive function identifies the root of the project and calls the appropriate executable with the arguments build run.

By default it is bound to C-c C-p.

This PR adds two additional customs

zig-project-build-file is the name of the file you wish to use as your build file. It defaults to build.zig

zig-project-root-search-up is the number of directories you wish to search up for the zig-project-build-file. This is used to ensure the function terminates.

If the project root cannot be found, zig-project-build-run indicates so in Messages.

@joachimschmidt557
Copy link
Member

zig build automatically searches for a build.zig file in the current directory or in all parent directories.

joachim@pier ~ % ~/src/zig/build/stage3/bin/zig build       
info: Initialize a 'build.zig' template file with `zig init-lib` or `zig init-exe`,
or see `zig --help` for more options.
error: No 'build.zig' file found, in the current directory or any parent directories.
joachim@pier ~ % 

In my opinion, we shouldn't support other build file names than build.zig as this is also the default enforced by the zig compiler.

@jiacai2050
Copy link
Contributor

I agree with @joachimschmidt557, this addition seems unnecessary.

@den-mentiei den-mentiei mentioned this pull request Feb 22, 2024
root-dir
(dir (directory-file-name
(replace-regexp-in-string "^Directory " "" default-directory))))
(while (and (< count zig-project-root-search-up)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's locate-dominating-file for all of this btw, so no need to search directories upwards yourself.

@@ -123,6 +135,31 @@ If given a SOURCE, execute the CMD on it."
(interactive)
(zig--run-cmd "run" (buffer-file-name) "-O" zig-run-optimization-mode))

(defun zig--find-project-root ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Really what I'd suggest instead of these changes is to add a (likely trivial) snippet that allows project.el to find the project root of Zig project. Then you can use project-* functions as needed in zig-project-build-run below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants