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

Update zig build to work with latest std changes #84

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions GitRepoStep.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn create(b: *std.build.Builder, opt: struct {
.branch = opt.branch,
.sha = opt.sha,
.path = if (opt.path) |p| (b.allocator.dupe(u8, p) catch @panic("memory")) else (std.fs.path.resolve(b.allocator, &[_][]const u8{
b.build_root,
b.build_root.join(b.allocator, &.{"."}) catch unreachable,
"dep",
name,
})) catch @panic("memory"),
Expand Down Expand Up @@ -140,7 +140,7 @@ fn checkSha(self: GitRepoStep) !void {
"rev-parse",
"HEAD",
},
.cwd = self.builder.build_root,
.cwd = self.builder.build_root.join(self.builder.allocator, &.{"."}) catch unreachable,
.env_map = self.builder.env_map,
}) catch |e| break :blk .{ .failed = e };
try std.io.getStdErr().writer().writeAll(result.stderr);
Expand Down Expand Up @@ -183,7 +183,7 @@ fn run(builder: *std.build.Builder, argv: []const []const u8) !void {
child.stdin_behavior = .Ignore;
child.stdout_behavior = .Inherit;
child.stderr_behavior = .Inherit;
child.cwd = builder.build_root;
child.cwd = builder.build_root.join(builder.allocator, &.{"."}) catch unreachable;
child.env_map = builder.env_map;

try child.spawn();
Expand Down
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ pub fn addBuild(self: *Builder, build_file: std.build.FileSource, _: struct { })
run_step.addArg("--build-file");
run_step.addFileSourceArg(build_file);
run_step.addArg("--cache-dir");
run_step.addArg(self.pathFromRoot(self.cache_root));
run_step.addArg(self.cache_root.join(self.allocator, &.{"."}) catch unreachable);
return run_step;
}
44 changes: 26 additions & 18 deletions build2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ pub fn build(b: *Builder) !void {
else
b.standardTargetOptions(.{});

const mode = b.standardReleaseOptions();
const mode = b.standardOptimizeOption(.{});

const zigup_build_options = b.addOptions();
const win32exelink: ?*std.build.LibExeObjStep = blk: {
if (target.getOs().tag == .windows) {
const exe = b.addExecutable("win32exelink", "win32exelink.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
const exe = b.addExecutable(.{
.name = "win32exelink",
.root_source_file = std.Build.FileSource.relative("win32exelink.zig"),
.target = target,
.optimize = mode,
});
// workaround @embedFile not working with absolute paths, see https://github.com/ziglang/zig/issues/14551
//zigup_build_options.addOptionFileSource("win32exelink_filename", .{ .generated = &exe.output_path_source });
const update_step = RelativeOutputPathSourceStep.create(exe);
Expand All @@ -59,7 +62,7 @@ pub fn build(b: *Builder) !void {
};

// TODO: Maybe add more executables with different ssl backends
const exe = try addZigupExe(b, ziget_repo, target, mode, zigup_build_options, win32exelink, zigetbuild.SslBackend.iguana);
const exe = try addZigupExe(b, ziget_repo, target, mode, zigup_build_options, win32exelink, zigetbuild.SslBackend.std);
exe.install();

const run_cmd = exe.run();
Expand Down Expand Up @@ -93,17 +96,21 @@ const RelativeOutputPathSourceStep = struct {
fn make(step: *std.build.Step) !void {
const self = @fieldParentPtr(RelativeOutputPathSourceStep, "step", step);
const b = self.exe.builder;
const build_root_str = b.build_root.join(b.allocator, &.{"."}) catch unreachable;
//std.log.info("output path is '{s}'", .{self.exe.output_path_source.path.?});
const abs_path = self.exe.output_path_source.path.?;
std.debug.assert(std.mem.startsWith(u8, abs_path, b.build_root));
self.output_path_source.path = std.mem.trimLeft(u8, abs_path[b.build_root.len..], "\\/");
std.debug.assert(std.mem.startsWith(u8, abs_path, build_root_str));
self.output_path_source.path = std.mem.trimLeft(u8, abs_path[build_root_str.len..], "\\/");
}
};

fn addTest(b: *Builder, exe: *std.build.LibExeObjStep, target: std.zig.CrossTarget, mode: std.builtin.Mode) void {
const test_exe = b.addExecutable("test", "test.zig");
test_exe.setTarget(target);
test_exe.setBuildMode(mode);
const test_exe = b.addExecutable(.{
.name = "test",
.root_source_file = std.Build.FileSource.relative("test.zig"),
.target = target,
.optimize = mode,
});
const run_cmd = test_exe.run();

// TODO: make this work, add exe install path as argument to test
Expand All @@ -127,17 +134,19 @@ fn addZigupExe(
const require_ssl_backend = b.allocator.create(RequireSslBackendStep) catch unreachable;
require_ssl_backend.* = RequireSslBackendStep.init(b, "the zigup exe", ssl_backend);

const exe = b.addExecutable("zigup", "zigup.zig");
exe.setTarget(target);
exe.setBuildMode(mode);

const exe = b.addExecutable(.{
.name = "zigup",
.root_source_file = std.Build.FileSource.relative("zigup.zig"),
.target = target,
.optimize = mode,
});
if (optional_win32exelink) |win32exelink| {
exe.step.dependOn(&win32exelink.step);
}
exe.addOptions("build_options", zigup_build_options);

exe.step.dependOn(&ziget_repo.step);
zigetbuild.addZigetPkg(exe, ssl_backend, ziget_repo.getPath(&exe.step));
zigetbuild.addZigetModule(exe, ssl_backend, ziget_repo.getPath(&exe.step));

if (targetIsWindows(target)) {
const zarc_repo = GitRepoStep.create(b, .{
Expand All @@ -147,9 +156,8 @@ fn addZigupExe(
});
exe.step.dependOn(&zarc_repo.step);
const zarc_repo_path = zarc_repo.getPath(&exe.step);
exe.addPackage(Pkg {
.name = "zarc",
.source = .{ .path = try join(b, &[_][]const u8 { zarc_repo_path, "src", "main.zig" }) },
exe.addAnonymousModule("zarc", .{
.source_file = .{ .path = try join(b, &[_][]const u8 { zarc_repo_path, "src", "main.zig" }) },
});
}

Expand Down
2 changes: 1 addition & 1 deletion zigetsha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fcf104cd3a59e8f9465512e735f3b820137105ef
c790806514720daf6960ab5671f2466674acf44a