Skip to content

Commit

Permalink
build: requireZig cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jan 8, 2025
1 parent e14bc5b commit eb40cce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
16 changes: 1 addition & 15 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,7 @@ const builtin = @import("builtin");
const buildpkg = @import("src/build/main.zig");

comptime {
// This is the required Zig version for building this project. We allow
// any patch version but the major and minor must match exactly.
const required_zig = "0.13.0";

// Fail compilation if the current Zig version doesn't meet requirements.
const current_vsn = builtin.zig_version;
const required_vsn = std.SemanticVersion.parse(required_zig) catch unreachable;
if (current_vsn.major != required_vsn.major or
current_vsn.minor != required_vsn.minor)
{
@compileError(std.fmt.comptimePrint(
"Your Zig version v{} does not meet the required build version of v{}",
.{ current_vsn, required_vsn },
));
}
buildpkg.requireZig("0.13.0");
}

pub fn build(b: *std.Build) !void {
Expand Down
3 changes: 3 additions & 0 deletions src/build/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ pub const XCFrameworkStep = @import("XCFrameworkStep.zig");
pub const fish_completions = @import("fish_completions.zig").completions;
pub const zsh_completions = @import("zsh_completions.zig").completions;
pub const bash_completions = @import("bash_completions.zig").completions;

// Helpers
pub const requireZig = @import("zig.zig").requireZig;
17 changes: 17 additions & 0 deletions src/build/zig.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const std = @import("std");
const builtin = @import("builtin");

/// Require a specific version of Zig to build this project.
pub fn requireZig(comptime required_zig: []const u8) void {
// Fail compilation if the current Zig version doesn't meet requirements.
const current_vsn = builtin.zig_version;
const required_vsn = std.SemanticVersion.parse(required_zig) catch unreachable;
if (current_vsn.major != required_vsn.major or
current_vsn.minor != required_vsn.minor)
{
@compileError(std.fmt.comptimePrint(
"Your Zig version v{} does not meet the required build version of v{}",
.{ current_vsn, required_vsn },
));
}
}

0 comments on commit eb40cce

Please sign in to comment.