Skip to content

Commit a64b032

Browse files
committed
zig build
1 parent 5c9d60c commit a64b032

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed

.github/workflows/zig.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "CI: zig build"
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
targets:
11+
- x86_64-linux-gnu
12+
- x86_64-linux-musl
13+
- x86-linux-gnu
14+
- x86-linux-musl
15+
- aarch64-linux-gnu
16+
- aarch64-linux-musl
17+
- riscv64-linux-musl
18+
- mipsel-linux-musl
19+
- mips-linux-musl
20+
- powerpc64-linux-musl
21+
- x86_64-macos
22+
- aarch64-macos
23+
- x86_64-windows
24+
- x86-windows
25+
- aarch64-windows
26+
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
with:
31+
submodules: recursive
32+
fetch-depth: 0
33+
- uses: goto-bus-stop/setup-zig@v2
34+
with:
35+
version: master
36+
37+
- name: Build Summary ${{ matrix.targets }}
38+
run: zig build -DTests --summary all -freference-trace -Dtarget=${{ matrix.targets }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Makefile.in
2424
/sigc++config.h
2525
/sigc++-*.pc
2626
/stamp-h?
27+
zig-cache/
28+
zig-out/
2729
untracked/build_scripts/
2830
untracked/docs/
2931
*.pro.user

build.zig

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
const std = @import("std");
2+
const FileSource = std.Build.FileSource;
3+
4+
pub fn build(b: *std.Build) void {
5+
const target = b.standardTargetOptions(.{});
6+
const optimize = b.standardOptimizeOption(.{});
7+
const tests = b.option(bool, "Tests", "Build tests [default: false]") orelse false;
8+
9+
const config = b.addConfigHeader(.{
10+
.style = .{
11+
.cmake = .{ .path = "sigc++config.h.cmake" },
12+
},
13+
.include_path = "sigc++config.h",
14+
}, .{
15+
.SIGCXX_DISABLE_DEPRECATED = null,
16+
.SIGC_DLL = if (target.isWindows()) {} else null,
17+
._ALLOW_KEYWORD_MACROS = if (target.getAbi() == .msvc) "1" else null,
18+
});
19+
const lib = b.addStaticLibrary(.{
20+
.name = "sigc++",
21+
.target = target,
22+
.optimize = optimize,
23+
});
24+
lib.addConfigHeader(config);
25+
lib.addIncludePath(".");
26+
lib.addCSourceFiles(&.{
27+
"sigc++/connection.cc",
28+
"sigc++/functors/slot_base.cc",
29+
"sigc++/signal_base.cc",
30+
"sigc++/trackable.cc",
31+
}, cxxFlags);
32+
lib.linkLibCpp();
33+
lib.installHeadersDirectoryOptions(.{
34+
.source_dir = FileSource.relative("sigc++"),
35+
.install_dir = .header,
36+
.install_subdir = "sigc++",
37+
.exclude_extensions = &.{
38+
"am",
39+
"gitignore",
40+
"build",
41+
"cc",
42+
"txt",
43+
},
44+
});
45+
46+
b.installArtifact(lib);
47+
48+
if (tests) {
49+
buildTest(b, .{
50+
.path = "examples/hello_world.cc",
51+
.lib = lib,
52+
});
53+
buildTest(b, .{
54+
.path = "examples/member_method.cc",
55+
.lib = lib,
56+
});
57+
buildTest(b, .{
58+
.path = "tests/test_accum_iter.cc",
59+
.lib = lib,
60+
});
61+
buildTest(b, .{
62+
.path = "tests/test_bind.cc",
63+
.lib = lib,
64+
});
65+
buildTest(b, .{
66+
.path = "tests/test_compose.cc",
67+
.lib = lib,
68+
});
69+
buildTest(b, .{
70+
.path = "tests/test_accumulated.cc",
71+
.lib = lib,
72+
});
73+
buildTest(b, .{
74+
.path = "tests/test_hide.cc",
75+
.lib = lib,
76+
});
77+
buildTest(b, .{
78+
.path = "tests/test_slot.cc",
79+
.lib = lib,
80+
});
81+
buildTest(b, .{
82+
.path = "tests/test_tuple_start.cc",
83+
.lib = lib,
84+
});
85+
buildTest(b, .{
86+
.path = "tests/test_tuple_transform_each.cc",
87+
.lib = lib,
88+
});
89+
buildTest(b, .{
90+
.path = "tests/test_visit_each.cc",
91+
.lib = lib,
92+
});
93+
buildTest(b, .{
94+
.path = "tests/test_weak_raw_ptr.cc",
95+
.lib = lib,
96+
});
97+
}
98+
}
99+
const cxxFlags: []const []const u8 = &.{
100+
"-Wall",
101+
"-Wextra",
102+
"-Werror",
103+
};
104+
fn buildTest(b: *std.Build, info: BuildInfo) void {
105+
const test_exe = b.addExecutable(.{
106+
.name = info.filename(),
107+
.optimize = info.lib.optimize,
108+
.target = info.lib.target,
109+
});
110+
for (info.lib.include_dirs.items) |include| {
111+
test_exe.include_dirs.append(include) catch {};
112+
}
113+
test_exe.addCSourceFile(info.path, cxxFlags);
114+
test_exe.addCSourceFile("tests/testutilities.cc", cxxFlags);
115+
test_exe.linkLibrary(info.lib);
116+
test_exe.linkLibCpp();
117+
b.installArtifact(test_exe);
118+
119+
const run_cmd = b.addRunArtifact(test_exe);
120+
run_cmd.step.dependOn(b.getInstallStep());
121+
if (b.args) |args| {
122+
run_cmd.addArgs(args);
123+
}
124+
125+
const run_step = b.step(
126+
b.fmt("{s}", .{info.filename()}),
127+
b.fmt("Run the {s} test", .{info.filename()}),
128+
);
129+
run_step.dependOn(&run_cmd.step);
130+
}
131+
132+
const BuildInfo = struct {
133+
lib: *std.Build.CompileStep,
134+
path: []const u8,
135+
136+
fn filename(self: BuildInfo) []const u8 {
137+
var split = std.mem.split(u8, std.fs.path.basename(self.path), ".");
138+
return split.first();
139+
}
140+
};

build.zig.zon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.{
2+
.name = "sigc++",
3+
.version = "2.3.1",
4+
.license = "LGPLv3",
5+
}

0 commit comments

Comments
 (0)