Skip to content

Commit 13f5426

Browse files
author
lcp5y3
committed
minimal packaging of cpputest with zig build system
0 parents  commit 13f5426

File tree

6 files changed

+190
-0
lines changed

6 files changed

+190
-0
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
pull_request:
8+
branches: [main]
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check out repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up LLVM and Clang
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y lld llvm llvm-dev clang
24+
25+
- name: Set up Zig
26+
uses: mlugg/setup-zig@v1
27+
28+
- name: Check Formatting
29+
run: zig fmt --ast-check --check .
30+
31+
- name: Run `build`
32+
run: zig build

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.zig-cache
2+
zig-out

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (Expat)
2+
3+
Copyright (c) contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

build.zig

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const cpputest_dep = b.dependency("cpputest", .{});
5+
const target = b.standardTargetOptions(.{});
6+
const optimize = b.standardOptimizeOption(.{});
7+
8+
const cpputest = b.addStaticLibrary(.{
9+
.name = "CppUTest",
10+
.target = target,
11+
.optimize = optimize,
12+
.link_libc = true,
13+
});
14+
15+
cpputest.addCSourceFiles(.{
16+
.root = cpputest_dep.path("src/CppUTest"),
17+
.files = &CPPUTEST_SRC,
18+
.flags = &FLAGS,
19+
});
20+
cpputest.installHeadersDirectory(cpputest_dep.path("include/CppUTest"), "CppUTest", .{});
21+
cpputest.addIncludePath(cpputest_dep.path("include"));
22+
cpputest.linkLibCpp();
23+
24+
const cpputest_ext = b.addStaticLibrary(.{
25+
.name = "CppUTestExt",
26+
.target = target,
27+
.optimize = optimize,
28+
.link_libc = true,
29+
});
30+
31+
cpputest_ext.addCSourceFiles(.{
32+
.root = cpputest_dep.path("src/CppUTestExt"),
33+
.files = &CPPUTEST_EXT_SRC,
34+
.flags = &FLAGS,
35+
});
36+
cpputest_ext.installHeadersDirectory(cpputest_dep.path("include/CppUTestExt"), "CppUTestExt", .{});
37+
cpputest_ext.addIncludePath(cpputest_dep.path("include"));
38+
cpputest_ext.linkLibCpp();
39+
40+
b.installArtifact(cpputest);
41+
b.installArtifact(cpputest_ext);
42+
}
43+
44+
const CPPUTEST_SRC = [_][]const u8{
45+
"CommandLineArguments.cpp",
46+
"CommandLineTestRunner.cpp",
47+
"JUnitTestOutput.cpp",
48+
"MemoryLeakDetector.cpp",
49+
"MemoryLeakWarningPlugin.cpp",
50+
"SimpleMutex.cpp",
51+
"SimpleString.cpp",
52+
"SimpleStringInternalCache.cpp",
53+
"TeamCityTestOutput.cpp",
54+
"TestFailure.cpp",
55+
"TestFilter.cpp",
56+
"TestHarness_c.cpp",
57+
"TestMemoryAllocator.cpp",
58+
"TestOutput.cpp",
59+
"TestPlugin.cpp",
60+
"TestRegistry.cpp",
61+
"TestResult.cpp",
62+
"TestTestingFixture.cpp",
63+
"Utest.cpp",
64+
};
65+
66+
const CPPUTEST_EXT_SRC = [_][]const u8{
67+
"CodeMemoryReportFormatter.cpp",
68+
"GTest.cpp",
69+
"IEEE754ExceptionsPlugin.cpp",
70+
"MemoryReportAllocator.cpp",
71+
"MemoryReporterPlugin.cpp",
72+
"MemoryReportFormatter.cpp",
73+
"MockActualCall.cpp",
74+
"MockExpectedCall.cpp",
75+
"MockExpectedCallsList.cpp",
76+
"MockFailure.cpp",
77+
"MockNamedValue.cpp",
78+
"MockSupport_c.cpp",
79+
"MockSupport.cpp",
80+
"MockSupportPlugin.cpp",
81+
"OrderedTest.cpp",
82+
};
83+
84+
const FLAGS = [_][]const u8{
85+
"-std=c++20",
86+
};

build.zig.zon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.{
2+
.name = "cpputest",
3+
.version = "4.0.0",
4+
.dependencies = .{
5+
.cpputest = .{
6+
.url = "https://github.com/cpputest/cpputest/archive/refs/tags/v4.0.tar.gz",
7+
.hash = "122085ba8e137a7ad8dfafa90ea97aa6cb87a3f1b016b387501a7961b291d40838a7",
8+
},
9+
},
10+
11+
.paths = .{
12+
"build.zig",
13+
"build.zig.zon",
14+
"LICENSE",
15+
"README.md",
16+
},
17+
}

readme.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# CppUTest Zig
2+
3+
Using zig build system to build [CppUTest](https://github.com/cpputest/cpputest) unit test library.
4+
5+
## Adding It to your project
6+
7+
First update your *build.zig.zon* with:
8+
9+
```bash
10+
zig fetch --save git+https://github.com/lcp5y3/cpputest-zig.git#v4.0.0
11+
```
12+
13+
After that you can link `CppUTest` with your project by adding the following
14+
lines to your `build.zig`
15+
16+
```zig
17+
const cpputest_dep = b.dependency("cpputest_zig", .{
18+
.target = target,
19+
.optimize = optimize,
20+
});
21+
22+
exe.linkLibrary(cpputest_dep.artifact("CppUTest"));
23+
exe.linkLibrary(cpputest_dep.artifact("CppUTestExt"));
24+
```
25+
26+
## Building the lib
27+
28+
If you only want to build CppUTest to get .a and header, run:
29+
30+
```bash
31+
zig build
32+
```

0 commit comments

Comments
 (0)