This repository was archived by the owner on Mar 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
68 lines (54 loc) · 2.18 KB
/
build.zig
File metadata and controls
68 lines (54 loc) · 2.18 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const core_dep = b.dependency("core", .{
.target = target,
.optimize = optimize,
});
try b.modules.put("zigplug", core_dep.module("zigplug"));
const test_step = b.step("test", "Run unit tests");
const core_tests = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "test" });
core_tests.setCwd(b.path("src/core"));
test_step.dependOn(&core_tests.step);
const clap_tests = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "test" });
clap_tests.setCwd(b.path("src/clap"));
test_step.dependOn(&clap_tests.step);
}
pub fn clapModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
const dep = b.dependencyFromBuildZig(@This(), .{
.target = target,
.optimize = optimize,
});
if (dep.builder.lazyDependency("clap", .{
.target = target,
.optimize = optimize,
})) |clap_dep|
return clap_dep.module("clap");
unreachable;
}
pub const Options = struct {
/// Doesn't have to match the display name in your plugin's descriptor
name: []const u8,
/// This module must export a CLAP entry point
root_module: *std.Build.Module,
/// Whether to add the resulting compile step to your project's top level install step
install: bool = true,
};
/// If `options.install` is true, the result will be installed to `lib/clap/{options.name}.clap`
pub fn addClap(b: *std.Build, options: Options) !*std.Build.Step.Compile {
const lib = b.addLibrary(.{
.name = try std.fmt.allocPrint(b.allocator, "{s}_clap", .{options.name}),
.linkage = .dynamic,
// printing to stdout/stderr segfaults without this, possibly a bug in zig's new x86 backend
.use_llvm = true,
.root_module = options.root_module,
});
if (options.install) {
const install = b.addInstallArtifact(lib, .{
.dest_sub_path = b.fmt("clap/{s}.clap", .{options.name}),
});
b.getInstallStep().dependOn(&install.step);
}
return lib;
}