Skip to content

Commit

Permalink
test: c++ build
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Apr 18, 2024
1 parent fcbbfe1 commit 9944b65
Show file tree
Hide file tree
Showing 4 changed files with 490 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ jobs:
run: |
zig build run-example1
zig build run-example2
zig build run-example3
zig build run-example3
zig build run-cpp
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ docs/
# Code coverage
*.lst

test/
# Zig
zig-*/
58 changes: 53 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
.BUILD_SHARED_LIBS = false,
});
const bdwgc_artifact = bdwgc.artifact("gc");
const bdwgc_path = bdwgc.path("");

// generate di file (like, zig-translate-c from D-importC)
// note: ImportC just gives no-mangling C code,
// but does not suppress D features exception and DruntimeGC.

// try buildExe(b, .{
// .name = "bdwgcd",
// .target = target,
// .optimize = optimize,
// .betterC = true, // disable D runtimeGC
// .kind = .obj,
// .artifact = bdwgc.artifact("gc"),
// .artifact = bdwgc_artifact,
// .sources = &.{"src/gc.c"},
// .dflags = &.{
// "-w",
Expand All @@ -40,7 +41,7 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
.betterC = true, // disable D runtimeGC
.artifact = bdwgc.artifact("gc"),
.artifact = bdwgc_artifact,
.sources = &.{"examples/example1.d"},
.dflags = &.{
"-w",
Expand All @@ -52,7 +53,7 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
.betterC = true, // disable D runtimeGC
.artifact = bdwgc.artifact("gc"),
.artifact = bdwgc_artifact,
.sources = &.{"examples/example2.d"},
.dflags = &.{
"-w",
Expand All @@ -64,13 +65,60 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
.betterC = false, // need D runtimeGC
.artifact = bdwgc.artifact("gc"),
.artifact = bdwgc_artifact,
.sources = &.{"examples/example3.d"},
.dflags = &.{
"-w",
"-Isrc",
},
});

// C++ build test

const exe = b.addExecutable(.{
.name = "cpp_tests",
.target = target,
.optimize = optimize,
});
exe.addCSourceFiles(.{
.root = bdwgc_path,
.files = if (exe.rootModuleTarget().abi != .msvc)
&.{
"gc_cpp.cc",
"gc_badalc.cc",
}
else
&.{
"gc_cpp.cpp",
"gc_badalc.cpp",
},
.flags = &.{
"-Wall",
"-Wpedantic",
"-Wextra",
},
});
exe.addCSourceFile(.{
.file = b.path("tests/cpp.cc"),
.flags = &.{
"-Wall",
"-Wpedantic",
"-Wextra",
},
});
for (bdwgc_artifact.root_module.include_dirs.items) |dir| {
exe.addIncludePath(dir.path);
}
exe.linkLibrary(bdwgc_artifact);
if (exe.rootModuleTarget().abi != .msvc) {
exe.linkLibCpp();
} else {
exe.linkLibC();
}
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run-cpp", "Run the C++ app");
run_step.dependOn(&run_cmd.step);
}
fn buildExe(b: *std.Build, options: abs.DCompileStep) !void {
const exe = try abs.ldcBuildStep(b, options);
Expand Down
Loading

0 comments on commit 9944b65

Please sign in to comment.