-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
122 lines (108 loc) · 5.99 KB
/
Copy pathbuild.zig
File metadata and controls
122 lines (108 loc) · 5.99 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const latex_renderer = b.option(bool, "latex_renderer", "Build the TikZ emitter and cktimg-tex") orelse false;
const options = b.addOptions();
options.addOption(bool, "latex_renderer", latex_renderer);
const mod = b.addModule("NetlistParser", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
mod.addOptions("build_options", options);
// libcktimg.a and its header: the C ABI (src/abi.zig).
const static = b.addLibrary(.{ .name = "cktimg", .linkage = .static, .root_module = mod });
b.installArtifact(static);
b.installFile("include/cktimg.h", "include/cktimg.h");
// The standard symbol set, for the tools (the library itself has none).
const sym_files = b.addWriteFiles();
_ = sym_files.addCopyFile(b.path("tests/symbols.zon"), "symbols.zon");
const symbols = b.createModule(.{ .root_source_file = sym_files.add("symbols.zig", "pub const text = @embedFile(\"symbols.zon\");\n") });
// Unit tests inside the library (netlist, csr, library, config, …).
const lib_tests = b.addTest(.{ .root_module = mod });
// The algorithm and API suites, as a consumer sees the module.
const tool_imports: []const std.Build.Module.Import = &.{.{ .name = "NetlistParser", .module = mod }};
const cases = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("tests/cases.zig"),
.target = target,
.optimize = optimize,
.imports = tool_imports,
}) });
// The example decks, for the API suite's connectivity check.
const ex_files = b.addWriteFiles();
_ = ex_files.addCopyFile(b.path("examples/blocks.spice"), "blocks.spice");
_ = ex_files.addCopyFile(b.path("examples/latex/cs.cir"), "cs.cir");
const examples = b.createModule(.{ .root_source_file = ex_files.add("examples.zig", "pub const all = [_][]const u8{ @embedFile(\"blocks.spice\"), @embedFile(\"cs.cir\") };\n") });
const api = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("tests/api.zig"),
.target = target,
.optimize = optimize,
.imports = &.{ .{ .name = "NetlistParser", .module = mod }, .{ .name = "examples", .module = examples } },
}) });
// The C ABI as a C program uses it.
const abi_test = b.addExecutable(.{ .name = "abi_test", .root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}) });
abi_test.root_module.addCSourceFile(.{ .file = b.path("tests/abi_test.c"), .flags = &.{ "-std=c99", "-Wall", "-Wextra", "-Werror" } });
abi_test.root_module.addIncludePath(b.path("include"));
abi_test.root_module.linkLibrary(static);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&b.addRunArtifact(lib_tests).step);
test_step.dependOn(&b.addRunArtifact(cases).step);
test_step.dependOn(&b.addRunArtifact(api).step);
test_step.dependOn(&b.addRunArtifact(abi_test).step);
const fuzz = b.addExecutable(.{ .name = "fuzz", .root_module = b.createModule(.{
.root_source_file = b.path("tests/fuzz.zig"),
.target = target,
.optimize = .ReleaseSafe,
.imports = tool_imports,
}) });
const fuzz_run = b.addRunArtifact(fuzz);
if (b.args) |args| fuzz_run.addArgs(args);
b.step("fuzz", "Random netlists through the pipeline; smallest example per rare case").dependOn(&fuzz_run.step);
const gallery = b.addExecutable(.{ .name = "gallery", .root_module = b.createModule(.{
.root_source_file = b.path("tests/gallery.zig"),
.target = target,
.optimize = optimize,
.imports = tool_imports,
}) });
b.installArtifact(gallery);
const gallery_run = b.addRunArtifact(gallery);
if (b.args) |args| gallery_run.addArgs(args);
b.step("gallery", "Draw the textbook circuits (--svgs dir | --gallery out.html | in.cir out.svg)").dependOn(&gallery_run.step);
// cktimg-json: the placed schematic as JSON (and SVG) for scripts.
const svg_mod = b.createModule(.{ .root_source_file = b.path("tests/svg.zig"), .imports = tool_imports });
const json_mod = b.createModule(.{
.root_source_file = b.path("tools/json.zig"),
.target = target,
.optimize = optimize,
.imports = &.{ .{ .name = "NetlistParser", .module = mod }, .{ .name = "symbols", .module = symbols }, .{ .name = "svg", .module = svg_mod } },
});
b.installArtifact(b.addExecutable(.{ .name = "cktimg-json", .root_module = json_mod }));
test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = json_mod })).step);
// cktimg-xschem: the xschem target (tools/xschem).
const xs_files = b.addWriteFiles();
_ = xs_files.addCopyFile(b.path("tools/xschem/symbols.zon"), "symbols.zon");
_ = xs_files.addCopyFile(b.path("tools/xschem/xschem.zon"), "xschem.zon");
const xs_mod = b.createModule(.{ .root_source_file = xs_files.add("files.zig", "pub const symbols = @embedFile(\"symbols.zon\");\npub const map = @embedFile(\"xschem.zon\");\n") });
const xschem = b.addExecutable(.{ .name = "cktimg-xschem", .root_module = b.createModule(.{
.root_source_file = b.path("tools/xschem/export.zig"),
.target = target,
.optimize = optimize,
.imports = &.{ .{ .name = "NetlistParser", .module = mod }, .{ .name = "xschem_files", .module = xs_mod } },
}) });
b.installArtifact(xschem);
if (latex_renderer) {
const tex = b.addExecutable(.{ .name = "cktimg-tex", .root_module = b.createModule(.{
.root_source_file = b.path("tools/tex.zig"),
.target = target,
.optimize = optimize,
.imports = &.{ .{ .name = "NetlistParser", .module = mod }, .{ .name = "symbols", .module = symbols } },
}) });
b.installArtifact(tex);
b.installFile("latex/cktimg.sty", "share/latex/cktimg.sty");
}
}