-
Notifications
You must be signed in to change notification settings - Fork 65
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
Use the known-folders package to find install dir #139
Conversation
The declarations `std.zig.CrossTarget`, `std.fs.MAX_PATH_BYTES`, and `std.mem.tokenize` were made into compile errors in zig version 0.13.0-dev.33+76fb2b685. Individually, these were deprecated (but not made compile errors) in: - std.mem.tokenize: 0.10.0-dev.3139+9da3a9733 - std.zig.CrossTarget: 0.11.0-dev.1886+3179f58c4 - std.fs.MAX_PATH_BYTES: 0.11.0-dev.3382+cd62005f1 so this change makes zigup unbuildable with versions of zig prior to 0.11.0-dev.3382+cd62005f1 (if it was previously was), but allows building zigup with with zig versions after 0.13.0-dev.33+76fb2b685.
A new build option `default-dir` is provided to achieve the original behaviour prior to this commit by building with zig build -Ddefault-dir=zig
Here's how I'd like to see thing split up:
One thing I note is that you've provided good documentation on what directory zigup will choose in // NOTE: update README.md if any of these ever change
const default_install_path = if (build_options.install_dir) |d| d else switch (builtin.os.tag) {
.windows => "%localappdata%\\zigup",
.linux => "$XDG_DATA_HOME/zigup",
.macos => "$HOME/Library/Application Support/zigup",
else => @compileError("OS " ++ @tagName(builtin.os.tag) ++ " does not have a default install path"),
} A few notes about windows, I think As for all other systems, I find typing One more note, I think I'd be more amenable to adding a more convenient platform-agnostic mechanism to configuring the install path. Maybe a |
Will do.
Whether the default (i.e. when just running
Fair point. I think there is basically 0% chance
Most people don't expect a cli tool to create non-hidden folders in their home directory by default. Personally I'd go further and say I don't really think there is much of a reason to even make hidden ones these days over using the XDG spec, but I know not everyone agrees with me there. If cli tools make the assumption that a non-standardised and not hidden directory under
I agree a config file is the most user-friendly way to go compared with build options (I'm not familiar with Windows resources), though I wouldn't personally care for my usage as long as there are build options. I'm not aware of a mechanism to update a binary like that on Linux/macOS, which would leave the question of where to put the config file. I would strongly recommend and prefer
I'll rework this PR - or close and open another - to just add XDG support for macOS and Linux, and leave Windows for someone more familiar with the conventions and any possible use of resources if we go for runtime config options. |
This change makes zigup use known-folders for determining the install directory by default. A new build option
default-dir
has been added to control whether the default behaviour is to use theknown-options
package or the old behaviour. Whendefault-dir
is provided everything is the same as before, except that instead of the use of"zig"
as the name of the install directory, the value of thedefault-dir
build option is used (i.e. for the old behaviour usezig build -Ddefault-dir=zig
).When the
default-dir
build option is not provided the changes to behaviour are that when the--install-dir
option is not provided:XDG_DATA_HOME
, which defaults to~/.local/share
if the$XDG_DATA_HOME
env var is not set~/Library/Application Support
%APPDATA%
env varzigup
, e.g. the default location on linux becomes~/.local/share/zigup
.Note that I am not very familiar with Windows and macOS conventions here, but I assume
known-folders
is making a sensible choice; it is possible to haveknown-folders
use the XDG spec on macOS rather than using~/Library/Application Support
.In addition, the first commit in the PR updates use of some deprecated aliases in
std
that were made compile errors in the 0.13 release cycle. They were deprecated before Zig 0.12, so 0.12 still works, but with these Zig master can also build zigup. I can split this commit into a separate PR if that is preferable.Compared to #66 (I had not noticed the apparent inactivity in that PR when I commented) I believe using
known-folders
is the right approach, and provides a build option as was suggested in comments on that PR to allow using original default behaviour.