~jamii/focus

ref: 9129a602ae181370105ef749b628f2b69546ee28 focus/build.zig -rw-r--r-- 1.5 KiB View raw
9129a602Jamie Brandon Nit 3 months ago
                                                                                
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
const builtin = @import("builtin");
const std = @import("std");
const Builder = std.build.Builder;
const allocator = std.testing.allocator;

pub fn build(b: *Builder) !void {
    const mode = b.standardReleaseOptions();

    const local = b.addExecutable("focus-local", "./src/root.zig");
    try includeCommon(local);
    local.setBuildMode(mode);
    local.install();

    const cross = b.addExecutable("focus-cross", "./src/root.zig");
    try includeCommon(cross);
    cross.setBuildMode(mode);
    cross.setTarget(
        std.zig.CrossTarget{
            .cpu_arch = .aarch64,
            .os_tag = .linux,
            .abi = .gnu,
        }
    );
    cross.install();

    const local_step = b.step("local", "Build for local");
    local_step.dependOn(&local.step);

    const cross_step = b.step("cross", "Build for focus");
    cross_step.dependOn(&cross.step);

    const run = local.run();
    const run_step = b.step("run", "Run locally");
    run_step.dependOn(&run.step);
}

fn includeCommon(exe: *std.build.LibExeObjStep) !void {
    exe.linkSystemLibrary("c");
    try includeNix(exe, "NIX_LIBGL_DEV");
    exe.linkSystemLibrary("GL");
    try includeNix(exe, "NIX_SDL2_DEV");
    exe.linkSystemLibrary("SDL2");
    exe.setOutputDir("./zig-cache");
}

fn includeNix(exe: *std.build.LibExeObjStep, env_var: []const u8) !void {
    var buf = std.ArrayList(u8).init(allocator);
    defer buf.deinit();
    try buf.appendSlice(std.os.getenv(env_var).?);
    try buf.appendSlice("/include");
    exe.addIncludeDir(buf.items);
}