This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
70 lines (51 loc) · 2.01 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "ZigCEF",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.addIncludePath(.{ .path = "cef" });
exe.addObjectFile(.{ .path = "cef/binaries/libcef.so" });
exe.linkLibC();
b.installArtifact(exe);
const copy_bin_step = b.step("copy-bin", "Copies the CEF binaries into the output directory");
copy_bin_step.makeFn = copyBin;
copy_bin_step.dependOn(b.getInstallStep());
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(copy_bin_step);
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}
fn copyBin(self: *std.Build.Step, progress: *std.Progress.Node) !void {
_ = self;
_ = progress;
std.debug.print("Copying CEF binaries...\n", .{});
try copyDirectory("cef/binaries", "zig-out/bin");
try copyDirectory("cef/binaries/locales", "zig-out/bin/locales");
}
fn copyDirectory(src: []const u8, dest: []const u8) !void {
var dest_dir = try std.fs.cwd().makeOpenPath(dest, .{});
defer dest_dir.close();
var src_iter_dir = try std.fs.cwd().openIterableDir(src, .{});
defer src_iter_dir.close();
var src_dir = try std.fs.cwd().openDir(src, .{});
defer src_dir.close();
var iterator = src_iter_dir.iterate();
while (try iterator.next()) |entry| {
if (entry.kind != .file) continue;
try src_dir.copyFile(entry.name, dest_dir, entry.name, .{});
}
}