-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.zig
More file actions
100 lines (92 loc) · 3.05 KB
/
build.zig
File metadata and controls
100 lines (92 loc) · 3.05 KB
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
94
95
96
97
98
99
100
const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
_ = b.addModule("ini", .{
.root_source_file = b.path("src/ini.zig"),
.optimize = optimize,
.target = target,
});
const ini_c_header = b.addTranslateC(.{
.root_source_file = b.path("src/ini.h"),
.target = target,
.optimize = optimize,
});
const lib = b.addLibrary(.{
.name = "ini",
.root_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{
.name = "c",
.module = ini_c_header.createModule(),
},
},
}),
});
lib.bundle_compiler_rt = true;
lib.root_module.addIncludePath(b.path("src"));
lib.installHeader(b.path("src/ini.h"), "ini.h");
b.installArtifact(lib);
const example_step = b.step("example", "Build examples");
const example_c = b.addExecutable(.{
.name = "example-c",
.root_module = b.createModule(.{
.optimize = optimize,
.target = target,
.link_libc = true,
}),
});
example_c.root_module.addCSourceFile(.{
.file = b.path("example/example.c"),
.flags = &.{
"-Wall",
"-Wextra",
"-pedantic",
},
});
example_c.root_module.addIncludePath(b.path("src"));
example_c.root_module.linkLibrary(lib);
example_step.dependOn(&b.addInstallArtifact(example_c, .{}).step);
const example_zig = b.addExecutable(.{
.name = "example-zig",
.root_module = b.createModule(.{
.root_source_file = b.path("example/example.zig"),
.optimize = optimize,
.target = target,
.imports = &.{
.{ .name = "ini", .module = b.modules.get("ini").? },
},
}),
});
example_step.dependOn(&b.addInstallArtifact(example_zig, .{}).step);
const test_step = b.step("test", "Run library tests");
const main_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/test.zig"),
.optimize = optimize,
.target = target,
}),
});
test_step.dependOn(&b.addRunArtifact(main_tests).step);
const binding_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/lib-test.zig"),
.optimize = optimize,
.target = target,
.link_libc = true,
.imports = &.{
.{
.name = "c",
.module = ini_c_header.createModule(),
},
},
}),
});
binding_tests.root_module.addIncludePath(b.path("src"));
binding_tests.root_module.linkLibrary(lib);
test_step.dependOn(&b.addRunArtifact(binding_tests).step);
}