Skip to content

change the default installation directory from ./zig-cache to ./ #7296

Description

@andrewrk

Accepted Proposal


If you run zig init-exe and then zig build --help you see this:

Steps:
install (default) Copy build artifacts to prefix path
uninstall Remove build artifacts from prefix path
run Run the app
General Options:
-h, --help Print this help and exit
--verbose Print commands before executing them
--prefix [path] Override default install prefix
--search-prefix [path] Add a path to look for binaries, libraries, headers
--color [auto|off|on] Enable or disable colored error messages
Project-Specific Options:
-Dtarget=[string] The CPU architecture, OS, and ABI to build for
-Drelease-safe=[bool] Optimizations on and safety on
-Drelease-fast=[bool] Optimizations on and safety off
-Drelease-small=[bool] Size optimizations on and safety off
Advanced Options:
...

As you can see, the default step is install. If you pass explicit steps on the command line, those steps are executed instead of the default. Currently, the install step has a default prefix path of zig-cache:

zig/lib/std/build.zig

Lines 194 to 210 in fd18252

/// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
pubfnresolveInstallPrefix(self: *Builder) void {
if (self.dest_dir) |dest_dir| {
constinstall_prefix=self.install_prefixorelse"/usr";
self.install_path=fs.path.join(self.allocator, &[_][]constu8{ dest_dir, install_prefix }) catchunreachable;
} else {
constinstall_prefix=self.install_prefixorelseblk: {
constp=self.cache_root;
self.install_prefix=p;
break :blkp;
};
self.install_path=install_prefix;
}
self.lib_dir=fs.path.join(self.allocator, &[_][]constu8{ self.install_path, "lib" }) catchunreachable;
self.exe_dir=fs.path.join(self.allocator, &[_][]constu8{ self.install_path, "bin" }) catchunreachable;
self.h_dir=fs.path.join(self.allocator, &[_][]constu8{ self.install_path, "include" }) catchunreachable;
}

This proposal is to make the default installation directory named after the output mode:

zig/lib/std/builtin.zig

Lines 144 to 149 in fd18252

pubconstMode=enum {
Debug,
ReleaseSafe,
ReleaseFast,
ReleaseSmall,
};

So, if you were to run zig build with the defaults for init-exe, you would get:

Debug/bin/foo.exe

With zig build -Drelease-safe you would get:

ReleaseSafe/bin/foo.exe

However, I further propose that this changes when one takes advantage of setPreferredReleaseMode, in which case

Project-Specific Options:
-Dtarget=[string] The CPU architecture, OS, and ABI to build for
-Drelease-safe=[bool] Optimizations on and safety on
-Drelease-fast=[bool] Optimizations on and safety off
-Drelease-small=[bool] Size optimizations on and safety off

turns into

Project-Specific Options:
-Dtarget=[string] The CPU architecture, OS, and ABI to build for
-Drelease=[bool] Create a release build (ReleaseSafe)

where "ReleaseSafe" is whatever the preferred release mode is. In this case, zig build -Drelease would give you a default installation directory of "Release":

Release/bin/foo.exe

As a reminder, it is always possible to override the install prefix with the --prefix CLI parameter.


Comments / suggestions / counter proposals welcome! Nobody will be accused of doing the B-word in this thread!

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions