aboutsummaryrefslogtreecommitdiff
path: root/go/build.zig
blob: 7cce4758ec89c2a5ecd1551afc3f46b97656dd9c (plain)
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
const std = @import("std");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const typdown = b.dependency("typdown", .{
        .optimize = optimize,
        .target = target,
    }).module("typdown");
    const lib = b.addLibrary(.{
        .name = "typdown",
        .root_module = typdown,
        .linkage = .static,
    });
    //lib.bundle_compiler_rt = true;
    //lib.pie = true;
    const install = b.addInstallArtifact(lib, .{});
    // when emitting headers will be fixed
    // currently, we have to use a symlink/copy to get it
    //installed.emitted_h = lib.getEmittedH();
    b.getInstallStep().dependOn(&install.step);

    var flags = try std.ArrayList(u8).initCapacity(b.allocator, 2);
    try flags.appendSlice(b.allocator, "-linkmode external -extldflags -static");
    if (optimize != .Debug) try flags.appendSlice(b.allocator, " -s");
    const go_build = b.addSystemCommand(&[_][]const u8{
        "go", "build",
        "-ldflags", flags.items,
        ".",
    });
    b.getInstallStep().dependOn(&go_build.step);

    const test_step = b.step("test", "Run tests");
    test_step.dependOn(b.getInstallStep());
    const race = b.option(bool, "race", "Run tests with -race") orelse false;
    const go_test = b.addSystemCommand(&[_][]const u8{
        "go", "test",
        "-ldflags", flags.items,
        "-v",
    });
    if (race) go_test.addArg("-race");
    go_test.addArg("./...");

    test_step.dependOn(&go_test.step);
}