diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ccfefba --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8c8979 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache +zig-out diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..06ce9e0 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..434a882 --- /dev/null +++ b/build.zig @@ -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", +}; diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..dad5799 --- /dev/null +++ b/build.zig.zon @@ -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", + }, +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..568935f --- /dev/null +++ b/readme.md @@ -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 +```