Skip to content

Commit

Permalink
zig build: support DESTDIR environment variable
Browse files Browse the repository at this point in the history
closes #2929
  • Loading branch information
andrewrk committed Jul 21, 2019
1 parent f429f4d commit 77c2ac3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions std/build.zig
Expand Up @@ -41,9 +41,10 @@ pub const Builder = struct {
env_map: *BufMap,
top_level_steps: ArrayList(*TopLevelStep),
install_prefix: ?[]const u8,
search_prefixes: ArrayList([]const u8),
dest_dir: ?[]const u8,
lib_dir: ?[]const u8,
exe_dir: ?[]const u8,
search_prefixes: ArrayList([]const u8),
installed_files: ArrayList(InstalledFile),
build_root: []const u8,
cache_root: []const u8,
Expand Down Expand Up @@ -125,10 +126,11 @@ pub const Builder = struct {
.top_level_steps = ArrayList(*TopLevelStep).init(allocator),
.default_step = undefined,
.env_map = env_map,
.install_prefix = null,
.search_prefixes = ArrayList([]const u8).init(allocator),
.install_prefix = null,
.lib_dir = null,
.exe_dir = null,
.dest_dir = env_map.get("DESTDIR"),
.installed_files = ArrayList(InstalledFile).init(allocator),
.install_tls = TopLevelStep{
.step = Step.initNoOp("install", allocator),
Expand Down Expand Up @@ -164,14 +166,14 @@ pub const Builder = struct {
}

fn resolveInstallPrefix(self: *Builder) void {
const prefix = if (self.install_prefix) |prefix| prefix else blk: {
const prefix = self.cache_root;
self.install_prefix = prefix;
break :blk prefix;
const dest_dir = self.dest_dir orelse blk: {
const dest_dir = self.install_prefix orelse self.cache_root;
self.dest_dir = dest_dir;
break :blk dest_dir;
};

self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "bin" }) catch unreachable;
self.dest_dir = dest_dir;
self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "bin" }) catch unreachable;
}

pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
Expand Down Expand Up @@ -884,7 +886,7 @@ pub const Builder = struct {

fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
const base_dir = switch (dir) {
.Prefix => self.install_prefix.?,
.Prefix => self.dest_dir.?,
.Bin => self.exe_dir.?,
.Lib => self.lib_dir.?,
};
Expand Down

2 comments on commit 77c2ac3

@JL2210
Copy link

@JL2210 JL2210 commented on 77c2ac3 Jul 22, 2019

Choose a reason for hiding this comment

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

This is wrong. DESTDIR needs to be prepended to the path of installed files.

@andrewrk
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. d6d0bb0

Please sign in to comment.