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

Enforce Zig version for build.zig #605

Closed
wants to merge 2 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
2 changes: 1 addition & 1 deletion .github/workflows/zig-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
- name: "Install zig"
run: |
mkdir zig && curl https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.1849+bb0f7d55e.tar.xz | tar Jx --directory=zig --strip-components=1
mkdir zig && curl https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.2015+60958d135.tar.xz | tar Jx --directory=zig --strip-components=1
- name: Build
run: >
zig/zig build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zig-cross-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
- uses: actions/checkout@v4
- name: "Install zig"
run: |
mkdir zig && curl https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.1849+bb0f7d55e.tar.xz | tar Jx --directory=zig --strip-components=1
mkdir zig && curl https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.2015+60958d135.tar.xz | tar Jx --directory=zig --strip-components=1
- name: Build
run: >
zig/zig build -Dtarget=${{ matrix.ttriple }}
Expand Down
44 changes: 28 additions & 16 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@
// A script to build and test the collector using Zig build system.
// The script matches CMakeLists.txt as much as possible.

// TODO: this script assumes zig 0.12.0-dev.1814.

const std = @import("std");
const builtin = @import("builtin");
const Path = std.Build.LazyPath;

comptime {
const min_zig_version = "0.12.0-dev.2015+60958d135";

const min_zig = std.SemanticVersion.parse(min_zig_version)
catch unreachable;
if (builtin.zig_version.order(min_zig) == .lt) {
@compileError(std.fmt.comptimePrint(
"Zig version {} does not meet the build requirement of {}",
.{ builtin.zig_version, min_zig },
));
}
}

// TODO: specify PACKAGE_VERSION and LIB*_VER_INFO.

// Compared to the CMake script, a lot more definitions and compiler options
Expand All @@ -27,10 +39,10 @@ const Path = std.Build.LazyPath;
// the knowledge of the platform, determine what capabilities should be
// enabled or not.

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const t = target.toTarget();
const t = target.result;

const default_enable_threads = !t.isWasm(); // both emscripten and wasi

Expand Down Expand Up @@ -172,11 +184,11 @@ pub fn build(b: *std.build.Builder) void {
"pthread_start.c",
"pthread_support.c",
}) catch unreachable;
if (target.isWindows()) {
if (t.os.tag == .windows) {
source_files.appendSlice(&.{
"win32_threads.c",
}) catch unreachable;
} else if (target.isDarwin()) {
} else if (t.isDarwin()) {
source_files.appendSlice(&.{
"darwin_stop_world.c",
}) catch unreachable;
Expand All @@ -200,7 +212,7 @@ pub fn build(b: *std.build.Builder) void {
}) catch unreachable;
}
// Message for clients: Explicit GC_INIT() calls may be required.
if (target.isWindows()) {
if (t.os.tag == .windows) {
// Does not provide process fork functionality.
} else if (enable_handle_fork and !disable_handle_fork) {
flags.append("-D HANDLE_FORK") catch unreachable;
Expand Down Expand Up @@ -248,7 +260,7 @@ pub fn build(b: *std.build.Builder) void {
if (enable_gc_debug) {
flags.append("-D DBG_HDRS_ALL") catch unreachable;
flags.append("-D KEEP_BACK_PTRS") catch unreachable;
if (target.isLinux()) {
if (t.os.tag == .linux) {
flags.append("-D MAKE_BACK_GRAPH") catch unreachable;
// TODO: do not define SAVE_CALL_COUNT for e2k
flags.append("-D SAVE_CALL_COUNT=8") catch unreachable;
Expand Down Expand Up @@ -276,7 +288,7 @@ pub fn build(b: *std.build.Builder) void {
} else {
flags.append("-D REDIRECT_MALLOC=GC_malloc") catch unreachable;
}
if (target.isWindows()) {
if (t.os.tag == .windows) {
flags.append("-D REDIRECT_MALLOC_IN_HEADER") catch unreachable;
} else {
flags.append("-D GC_USE_DLOPEN_WRAP") catch unreachable;
Expand Down Expand Up @@ -337,7 +349,7 @@ pub fn build(b: *std.build.Builder) void {
source_files.appendSlice(&.{
"extra/gc.c",
}) catch unreachable;
if (enable_threads and !(target.isDarwin() or target.isWindows())) {
if (enable_threads and !(t.isDarwin() or t.os.tag == .windows)) {
flags.append("-D GC_PTHREAD_START_STANDALONE") catch unreachable;
source_files.appendSlice(&.{
"pthread_start.c",
Expand All @@ -364,7 +376,7 @@ pub fn build(b: *std.build.Builder) void {
}) catch unreachable;
} else {
flags.append("-D GC_NOT_DLL") catch unreachable;
if (target.isWindows()) {
if (t.os.tag == .windows) {
// Do not require the clients to link with "user32" system library.
flags.append("-D DONT_USE_USER32_DLL") catch unreachable;
}
Expand All @@ -388,7 +400,7 @@ pub fn build(b: *std.build.Builder) void {
// dl_iterate_phdr exists (as a strong symbol).
flags.append("-D HAVE_DL_ITERATE_PHDR") catch unreachable;

if (enable_threads and !(target.isDarwin() or target.isWindows())) {
if (enable_threads and !(t.isDarwin() or t.os.tag == .windows)) {
// pthread_sigmask() and sigset_t are available and needed.
flags.append("-D HAVE_PTHREAD_SIGMASK") catch unreachable;
}
Expand All @@ -397,10 +409,10 @@ pub fn build(b: *std.build.Builder) void {
flags.append("-D GC_REQUIRE_WCSDUP") catch unreachable;

// pthread_setname_np, if available, may have 1, 2 or 3 arguments.
if (target.isDarwin()) {
if (t.isDarwin()) {
flags.append("-D HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID")
catch unreachable;
} else if (target.isLinux()) {
} else if (t.os.tag == .linux) {
flags.append("-D HAVE_PTHREAD_SETNAME_NP_WITH_TID") catch unreachable;
} else {
// TODO: support HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG
Expand Down Expand Up @@ -478,8 +490,8 @@ fn addTest(b: *std.Build, lib: *std.Build.Step.Compile,
catch @panic("Error joining paths");
const test_exe = b.addExecutable(.{
.name = testname,
.optimize = lib.optimize,
.target = lib.target
.optimize = lib.root_module.optimize.?,
.target = lib.root_module.resolved_target.?
});
test_exe.addCSourceFile(.{
.file = Path.relative(filename),
Expand Down