Skip to content

Commit

Permalink
Merge pull request #51 from jinzhongjia/build_zig
Browse files Browse the repository at this point in the history
update `build.zig`
  • Loading branch information
hendriknielaender authored Jul 25, 2024
2 parents 14541d9 + 35f1dbe commit 4c2d878
Showing 1 changed file with 26 additions and 44 deletions.
70 changes: 26 additions & 44 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
const std = @import("std");
const builtin = @import("builtin");

const Build = std.Build;

const min_zig_string = "0.13.0";
// Semantic version of your application
const version = std.SemanticVersion{ .major = 0, .minor = 4, .patch = 4 };

const CrossTargetInfo = struct {
crossTarget: std.zig.CrossTarget,
name: []const u8,
};
// Semantic version of your application
const version = std.SemanticVersion{ .major = 0, .minor = 4, .patch = 4 };

const min_zig_string = "0.13.0";

const Build = blk: {
// comptime detect the zig version
comptime {
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse(min_zig_string) catch unreachable;
if (current_zig.order(min_zig) == .lt) {
@compileError(std.fmt.comptimePrint("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
const error_msg = std.fmt.comptimePrint(
"Your Zig version v{} does not meet the minimum build requirement of v{}",
.{ current_zig, min_zig },
);
@compileError(error_msg);
}
break :blk std.Build;
};
}

pub fn build(b: *std.Build) void {
pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Add a global option for versioning
Expand All @@ -29,7 +35,7 @@ pub fn build(b: *std.Build) void {

const exe = b.addExecutable(.{
.name = "zvm",
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/main.zig" } },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.version = version,
Expand All @@ -42,46 +48,22 @@ pub fn build(b: *std.Build) void {

const release = b.step("release", "make an upstream binary release");
const release_targets = [_]std.Target.Query{
.{
.cpu_arch = .aarch64,
.os_tag = .linux,
},
.{
.cpu_arch = .x86_64,
.os_tag = .linux,
},
.{
.cpu_arch = .x86,
.os_tag = .linux,
},
.{
.cpu_arch = .riscv64,
.os_tag = .linux,
},
.{
.cpu_arch = .x86_64,
.os_tag = .macos,
},
.{
.cpu_arch = .aarch64,
.os_tag = .macos,
},
.{
.cpu_arch = .x86_64,
.os_tag = .windows,
},
.{
.cpu_arch = .x86,
.os_tag = .windows,
},
.{ .cpu_arch = .x86_64, .os_tag = .linux },
.{ .cpu_arch = .x86_64, .os_tag = .windows },
.{ .cpu_arch = .x86_64, .os_tag = .macos },
.{ .cpu_arch = .x86, .os_tag = .linux },
.{ .cpu_arch = .x86, .os_tag = .windows },
.{ .cpu_arch = .aarch64, .os_tag = .linux },
.{ .cpu_arch = .aarch64, .os_tag = .macos },
.{ .cpu_arch = .riscv64, .os_tag = .linux },
};

for (release_targets) |target_query| {
const resolved_target = b.resolveTargetQuery(target_query);
const t = resolved_target.result;
const rel_exe = b.addExecutable(.{
.name = "zvm",
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/main.zig" } },
.root_source_file = b.path("src/main.zig"),
.target = resolved_target,
.optimize = .ReleaseSafe,
.strip = true,
Expand All @@ -102,7 +84,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/main.zig" } },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
Expand Down

0 comments on commit 4c2d878

Please sign in to comment.