Skip to content

Commit

Permalink
zig-build: refactor & updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Apr 18, 2024
1 parent cd09218 commit 179c543
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
38 changes: 23 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const abs = @import("anotherBuildStep");
const abs = @import("abs");

pub fn build(b: *std.Build) !void {
// ldc2 not support mingw
Expand All @@ -9,30 +9,38 @@ pub fn build(b: *std.Build) !void {
.{} });
const optimize = b.standardOptimizeOption(.{});

try buildExe(b, "example1", .{ target, optimize });
try buildExe(b, "example2", .{ target, optimize });
}
fn buildExe(b: *std.Build, comptime name: []const u8, options: anytype) !void {
const bdwgc = b.dependency("bdwgc", .{
.target = options[0],
.optimize = options[1],
.target = target,
.optimize = optimize,
.BUILD_SHARED_LIBS = false,
});

const exe = try abs.ldcBuildStep(b, .{
.name = name,
.target = options[0],
.optimize = options[1],
try buildExe(b, .{
.name = "example1",
.target = target,
.optimize = optimize,
.betterC = true, // disable D runtimeGC
.artifact = bdwgc.artifact("gc"),
.sources = &.{"examples/" ++ name ++ ".d"},
.sources = &.{"examples/example1.d"},
.dflags = &.{
"-w",
"-vgc", // see Druntime GC if enabled
"-vtls", // thread-local storage
"-Isrc",
b.fmt("-P-I{s}", .{bdwgc.path("include").getPath(b)}),
},
});
try buildExe(b, .{
.name = "example2",
.target = target,
.optimize = optimize,
.betterC = true, // disable D runtimeGC
.artifact = bdwgc.artifact("gc"),
.sources = &.{"examples/example2.d"},
.dflags = &.{
"-w",
"-Isrc",
},
});
}
fn buildExe(b: *std.Build, options: abs.DCompileStep) !void {
const exe = try abs.ldcBuildStep(b, options);
b.default_step.dependOn(&exe.step);
}
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
.name = "bdwgc",
.version = "0.1.0",
.dependencies = .{
.anotherBuildStep = .{
.abs = .{
.url = "git+https://github.com/kassane/anotherBuildStep#main",
.hash = "1220d609e447a36dfe876c76a4a60f7e9a54e4fd7c4c21fb8a4452a6dbab57d95d6a",
.hash = "12201a8ca860ea3f27538562f1862891242699679edde2a6159b73177b3c495ff6de",
},
.bdwgc = .{
.url = "git+https://github.com/ivmai/bdwgc#df1a787929aa550ec5343442fd2212a2717ac0cd",
Expand Down

0 comments on commit 179c543

Please sign in to comment.