Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor build.zig improvements #677

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ cmake_install.cmake

# These ones are generated by Zig:
/zig-cache/
/.zig-cache/
/zig-out/

# Rarely generated files (mostly by some Win/DOS compilers):
Expand Down
102 changes: 51 additions & 51 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ pub fn build(b: *std.Build) void {
"Install header and pkg-config metadata files") orelse true;
// TODO: support with_libatomic_ops, without_libatomic_ops

var gc = b.addStaticLibrary(.{
.name = "gc",
.target = target,
.optimize = optimize,
});
if (build_shared_libs) {
const gc = if (build_shared_libs) blk: {
// TODO: convert VER_INFO values to [SO]VERSION ones
gc = b.addSharedLibrary(.{
break :blk b.addSharedLibrary(.{
.name = "gc",
.target = target,
.optimize = optimize,
});
}
} else blk: {
break :blk b.addStaticLibrary(.{
.name = "gc",
.target = target,
.optimize = optimize,
});
};

var source_files = std.ArrayList([]const u8).init(b.allocator);
defer source_files.deinit();
Expand Down Expand Up @@ -493,51 +494,51 @@ pub fn build(b: *std.Build) void {
gc.addIncludePath(b.path("include"));
gc.linkLibC();

var gccpp = b.addStaticLibrary(.{
.name = "gccpp",
.target = target,
.optimize = optimize,
});
var gctba = b.addStaticLibrary(.{
.name = "gctba",
.target = target,
.optimize = optimize,
});
var gccpp: *std.Build.Step.Compile = undefined;
var gctba: *std.Build.Step.Compile = undefined;
if (enable_cplusplus) {
if (build_shared_libs) {
gccpp = b.addSharedLibrary(.{
gccpp = if (build_shared_libs) blk: {
break :blk b.addSharedLibrary(.{
.name = "gccpp",
.target = target,
.optimize = optimize,
});
}
var gccpp_src_files = std.ArrayList([]const u8).init(b.allocator);
defer gccpp_src_files.deinit();
gccpp_src_files.appendSlice(&.{
"gc_badalc.cc",
"gc_cpp.cc",
}) catch unreachable;
} else blk: {
break :blk b.addStaticLibrary(.{
.name = "gccpp",
.target = target,
.optimize = optimize,
});
};
gccpp.addCSourceFiles(.{
.files = gccpp_src_files.items,
.files = &.{
"gc_badalc.cc",
"gc_cpp.cc",
},
.flags = flags.items,
});
gccpp.addIncludePath(b.path("include"));
gccpp.linkLibrary(gc);
linkLibCpp(gccpp);
if (enable_throw_bad_alloc_library) {
// The same as gccpp but contains only gc_badalc.
if (build_shared_libs) {
gctba = b.addSharedLibrary(.{
gctba = if (build_shared_libs) blk: {
break :blk b.addSharedLibrary(.{
.name = "gctba",
.target = target,
.optimize = optimize,
});
}
var gctba_src_files = std.ArrayList([]const u8).init(b.allocator);
defer gctba_src_files.deinit();
gctba_src_files.append("gc_badalc.cc") catch unreachable;
} else blk: {
break :blk b.addStaticLibrary(.{
.name = "gctba",
.target = target,
.optimize = optimize,
});
};
gctba.addCSourceFiles(.{
.files = gctba_src_files.items,
.files = &.{
"gc_badalc.cc",
},
.flags = flags.items,
});
gctba.addIncludePath(b.path("include"));
Expand All @@ -546,28 +547,27 @@ pub fn build(b: *std.Build) void {
}
}

var cord = b.addStaticLibrary(.{
.name = "cord",
.target = target,
.optimize = optimize,
});
var cord: *std.Build.Step.Compile = undefined;
if (build_cord) {
if (build_shared_libs) {
cord = b.addSharedLibrary(.{
cord = if (build_shared_libs) blk: {
break :blk b.addSharedLibrary(.{
.name = "cord",
.target = target,
.optimize = optimize,
});
}
var cord_src_files = std.ArrayList([]const u8).init(b.allocator);
defer cord_src_files.deinit();
cord_src_files.appendSlice(&.{
"cord/cordbscs.c",
"cord/cordprnt.c",
"cord/cordxtra.c",
}) catch unreachable;
} else blk: {
break :blk b.addStaticLibrary(.{
.name = "cord",
.target = target,
.optimize = optimize,
});
};
cord.addCSourceFiles(.{
.files = cord_src_files.items,
.files = &.{
"cord/cordbscs.c",
"cord/cordprnt.c",
"cord/cordxtra.c",
},
.flags = flags.items,
});
cord.addIncludePath(b.path("include"));
Expand Down
Loading