Skip to content

Commit

Permalink
minimal packaging of cpputest with zig build system
Browse files Browse the repository at this point in the history
  • Loading branch information
lcp5y3 committed Dec 27, 2024
0 parents commit 13f5426
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Continuous Integration

on:
push:
branches: [main]

pull_request:
branches: [main]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up LLVM and Clang
run: |
sudo apt-get update
sudo apt-get install -y lld llvm llvm-dev clang
- name: Set up Zig
uses: mlugg/setup-zig@v1

- name: Check Formatting
run: zig fmt --ast-check --check .

- name: Run `build`
run: zig build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.zig-cache
zig-out
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (Expat)

Copyright (c) contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
86 changes: 86 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const cpputest_dep = b.dependency("cpputest", .{});
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const cpputest = b.addStaticLibrary(.{
.name = "CppUTest",
.target = target,
.optimize = optimize,
.link_libc = true,
});

cpputest.addCSourceFiles(.{
.root = cpputest_dep.path("src/CppUTest"),
.files = &CPPUTEST_SRC,
.flags = &FLAGS,
});
cpputest.installHeadersDirectory(cpputest_dep.path("include/CppUTest"), "CppUTest", .{});
cpputest.addIncludePath(cpputest_dep.path("include"));
cpputest.linkLibCpp();

const cpputest_ext = b.addStaticLibrary(.{
.name = "CppUTestExt",
.target = target,
.optimize = optimize,
.link_libc = true,
});

cpputest_ext.addCSourceFiles(.{
.root = cpputest_dep.path("src/CppUTestExt"),
.files = &CPPUTEST_EXT_SRC,
.flags = &FLAGS,
});
cpputest_ext.installHeadersDirectory(cpputest_dep.path("include/CppUTestExt"), "CppUTestExt", .{});
cpputest_ext.addIncludePath(cpputest_dep.path("include"));
cpputest_ext.linkLibCpp();

b.installArtifact(cpputest);
b.installArtifact(cpputest_ext);
}

const CPPUTEST_SRC = [_][]const u8{
"CommandLineArguments.cpp",
"CommandLineTestRunner.cpp",
"JUnitTestOutput.cpp",
"MemoryLeakDetector.cpp",
"MemoryLeakWarningPlugin.cpp",
"SimpleMutex.cpp",
"SimpleString.cpp",
"SimpleStringInternalCache.cpp",
"TeamCityTestOutput.cpp",
"TestFailure.cpp",
"TestFilter.cpp",
"TestHarness_c.cpp",
"TestMemoryAllocator.cpp",
"TestOutput.cpp",
"TestPlugin.cpp",
"TestRegistry.cpp",
"TestResult.cpp",
"TestTestingFixture.cpp",
"Utest.cpp",
};

const CPPUTEST_EXT_SRC = [_][]const u8{
"CodeMemoryReportFormatter.cpp",
"GTest.cpp",
"IEEE754ExceptionsPlugin.cpp",
"MemoryReportAllocator.cpp",
"MemoryReporterPlugin.cpp",
"MemoryReportFormatter.cpp",
"MockActualCall.cpp",
"MockExpectedCall.cpp",
"MockExpectedCallsList.cpp",
"MockFailure.cpp",
"MockNamedValue.cpp",
"MockSupport_c.cpp",
"MockSupport.cpp",
"MockSupportPlugin.cpp",
"OrderedTest.cpp",
};

const FLAGS = [_][]const u8{
"-std=c++20",
};
17 changes: 17 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.{
.name = "cpputest",
.version = "4.0.0",
.dependencies = .{
.cpputest = .{
.url = "https://github.com/cpputest/cpputest/archive/refs/tags/v4.0.tar.gz",
.hash = "122085ba8e137a7ad8dfafa90ea97aa6cb87a3f1b016b387501a7961b291d40838a7",
},
},

.paths = .{
"build.zig",
"build.zig.zon",
"LICENSE",
"README.md",
},
}
32 changes: 32 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CppUTest Zig

Using zig build system to build [CppUTest](https://github.com/cpputest/cpputest) unit test library.

## Adding It to your project

First update your *build.zig.zon* with:

```bash
zig fetch --save git+https://github.com/lcp5y3/cpputest-zig.git#v4.0.0
```

After that you can link `CppUTest` with your project by adding the following
lines to your `build.zig`

```zig
const cpputest_dep = b.dependency("cpputest_zig", .{
.target = target,
.optimize = optimize,
});
exe.linkLibrary(cpputest_dep.artifact("CppUTest"));
exe.linkLibrary(cpputest_dep.artifact("CppUTestExt"));
```

## Building the lib

If you only want to build CppUTest to get .a and header, run:

```bash
zig build
```

0 comments on commit 13f5426

Please sign in to comment.