-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
executable file
·93 lines (82 loc) · 3.8 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const std = @import("std");
pub fn build(b: *std.build.Builder) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "sapt",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
.main_pkg_path = .{.path="."}
});
// This seems quite hacky, but makes it currently possible to cross-build provided we have prebuilt libcurl.dll/.so/.dylib (and zlib1?)
// Cross-builds with windows host: always libcurl
// Cross-builds with WSL host:
if(target.isNative()) {
exe.linkSystemLibrary("libcurl");
} else {
std.debug.print("Crossbuilding\n", .{});
// exe.addIncludeDir("/usr/include/");
// exe.addLibPath("/usr/include/"); // TODO: Only for linux as host?
// TODO: Check arch as well to ensure x86_64
switch(target.getOsTag()) {
.linux => {
exe.linkSystemLibrary("libcurl");
// try exe.lib_paths.resize(0); // Workaround, as linkSystemLibrary adds system link-path, and we want to override this with a custom one
try exe.lib_paths.insert(0, std.Build.FileSource.relative("xbuild/libs/x86_64-linux"));
},
.macos => {
exe.linkSystemLibrary("libcurl");
// try exe.lib_paths.resize(0); // Workaround, as linkSystemLibrary adds system link-path, and we want to override this with a custom one
try exe.lib_paths.insert(0, std.Build.FileSource.relative("xbuild/libs/x86_64-macos"));
},
.windows => {
exe.linkSystemLibrary("libcurl");
// try exe.lib_paths.resize(0); // Workaround, as linkSystemLibrary adds system link-path, and we want to override this with a custom one
try exe.lib_paths.insert(0, std.Build.FileSource.relative("xbuild/libs/x86_64-windows"));
// TODO: Copy in zlib1.dll and libcurl.dll to prefix
},
else => {
// Not supported?
return error.UnsupportedCrossTarget;
}
}
}
// try exe.lib_paths.resize(0);
// exe.addLibPath("xbuild/libs/x86_64-linux");
// exe.addLibPath("xbuild/libs/x86_64-mac");
// exe.addLibPath("xbuild/libs/x86_64-windows/lib");
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const all_tests = b.addTest(.{
.root_source_file = .{ .path = "src/test.zig" },
.target = target,
.optimize = optimize,
.main_pkg_path = .{.path="."}
});
all_tests.linkSystemLibrary("libcurl");
const run_unit_tests = b.addRunArtifact(all_tests);
const test_step = b.step("test", "Run default test suite");
test_step.dependOn(&run_unit_tests.step);
if(target.isNative()) {
const all_itests = b.addTest(.{
.root_source_file = .{ .path = "src/integration_test.zig" },
.target = target,
.optimize = optimize,
.main_pkg_path = .{.path="."},
.filter = "integration:"
});
all_itests.linkSystemLibrary("libcurl");
const run_itests = b.addRunArtifact(all_itests);
const itest_step = b.step("itest", "Run default integration test suite");
itest_step.dependOn(&run_itests.step);
}
}