-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.zig
76 lines (63 loc) · 2.13 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
const Build = @import("std").Build;
pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const wcwidth = b.dependency("wcwidth", .{
.target = target,
.optimize = optimize,
}).module("wcwidth");
const linenoise = b.addModule("linenoise", .{
.root_source_file = b.path("src/main.zig"),
.imports = &.{
.{
.name = "wcwidth",
.module = wcwidth,
},
},
});
// Static library
const lib = b.addStaticLibrary(.{
.name = "linenoise",
.root_source_file = b.path("src/c.zig"),
.target = target,
.optimize = optimize,
});
lib.root_module.addImport("wcwidth", wcwidth);
lib.linkLibC();
b.installArtifact(lib);
// Tests
const main_tests = b.addTest(.{
.name = "main-tests",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_main_tests = b.addRunArtifact(main_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
// Zig example
var example = b.addExecutable(.{
.name = "example",
.root_source_file = b.path("examples/example.zig"),
.target = target,
.optimize = optimize,
});
example.root_module.addImport("linenoise", linenoise);
var example_run = b.addRunArtifact(example);
const example_step = b.step("example", "Run example");
example_step.dependOn(&example_run.step);
// C example
var c_example = b.addExecutable(.{
.name = "example",
.target = target,
.optimize = optimize,
});
c_example.root_module.addCSourceFile(.{ .file = b.path("examples/example.c") });
c_example.addIncludePath(b.path("include"));
c_example.linkLibC();
c_example.linkLibrary(lib);
var c_example_run = b.addRunArtifact(c_example);
const c_example_step = b.step("c-example", "Run C example");
c_example_step.dependOn(&c_example_run.step);
c_example_step.dependOn(&lib.step);
}