-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
68 lines (58 loc) · 2.04 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
const std = @import("std");
const Builder = std.build.Builder;
const FutharkBackend = enum {
c,
opencl,
multicore,
};
fn addFutharkSrc(b: *Builder, exe: *std.build.LibExeObjStep, backend: FutharkBackend) void {
const cache_root = std.fs.path.join(b.allocator, &[_][]const u8{
b.build_root,
b.cache_root
}) catch unreachable;
const futhark_output = std.fs.path.join(b.allocator, &[_][]const u8{
cache_root,
"futhark"
}) catch unreachable;
const futhark_gen = b.addSystemCommand(&[_][]const u8{
"futhark",
switch (backend) {
.c => "c",
.opencl => "opencl",
.multicore => "multicore"
},
"--library",
"src/main.fut",
"-o",
futhark_output
});
exe.step.dependOn(&futhark_gen.step);
const futhark_c_output = std.mem.concat(b.allocator, u8, &[_][]const u8{futhark_output, ".c"}) catch unreachable;
exe.addCSourceFile(futhark_c_output, &[_][]const u8{ "-march=native" });
exe.addIncludeDir(cache_root);
}
pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const backend = b.option(FutharkBackend, "futhark-backend", "Set futhark backend") orelse .c;
const ocl_inc = b.option([]const u8, "opencl-include", "opencl include path") orelse "/usr/include";
const ocl_lib = b.option([]const u8, "opencl-lib", "opencl library path") orelse "/usr/lib";
const exe = b.addExecutable("sna-asg2", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
exe.linkLibC();
if (backend == .opencl) {
exe.addSystemIncludeDir(ocl_inc);
exe.addLibPath(ocl_lib);
exe.linkSystemLibraryName("OpenCL");
}
addFutharkSrc(b, exe, backend);
const run_cmd = exe.run();
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);
}