Skip to content

Commit 61b9958

Browse files
authored
Merge pull request #2 from AndrewKraevskii/update_to_0.15.2
Update to zig 0.15 and master.
2 parents 0580d36 + 3ab2e1e commit 61b9958

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![CI](https://github.com/jcalabro/stockfish/actions/workflows/zig-build.yml/badge.svg)](https://github.com/jcalabro/stockfish/actions/workflows/zig-build.yml)
44

5-
Zig build for [Stockfish 17.1](https://github.com/official-stockfish/Stockfish/tree/sf_17.1). Requires zig 0.14.0.
5+
Zig build for [Stockfish 17.1](https://github.com/official-stockfish/Stockfish/tree/sf_17.1). Requires zig 0.15.1, 0.15.2 or 0.16.*. Was tested with 0.16.0-dev.2261+d6b3dd25a.
66

77
Usage
88

build.zig

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const heap = std.heap;
99
const http = std.http;
1010
const math = std.math;
1111
const mem = std.mem;
12+
const Io = std.Io;
1213

1314
pub fn build(b: *Build) !void {
1415
const target = b.standardTargetOptions(.{});
@@ -31,10 +32,15 @@ pub fn build(b: *Build) !void {
3132
const stockfish_dep = b.dependency("Stockfish", .{});
3233
const stockfish_src_path = stockfish_dep.path("src/");
3334

34-
const exe = b.addExecutable(.{
35-
.name = "stockfish",
35+
const module = b.createModule(.{
3636
.target = target,
3737
.optimize = optimize,
38+
.link_libc = true,
39+
.link_libcpp = true,
40+
});
41+
const exe = b.addExecutable(.{
42+
.name = "stockfish",
43+
.root_module = module,
3844
});
3945
b.installArtifact(exe);
4046

@@ -45,21 +51,18 @@ pub fn build(b: *Build) !void {
4551
const run_step = b.step("run", "Build and run stockfish");
4652
run_step.dependOn(&run_cmd.step);
4753

48-
exe.linkLibC();
49-
exe.linkLibCpp();
50-
5154
if (optimize != .Debug) {
5255
exe.root_module.pic = true;
5356
exe.pie = true;
5457
exe.root_module.omit_frame_pointer = true;
5558
exe.root_module.strip = true;
56-
exe.want_lto = switch (builtin.os.tag) {
57-
.macos => false,
58-
else => true,
59+
exe.lto = switch (builtin.os.tag) {
60+
.macos => .none,
61+
else => .full,
5962
};
6063
}
6164

62-
exe.addCSourceFiles(.{
65+
module.addCSourceFiles(.{
6366
.root = stockfish_src_path,
6467
.files = &.{
6568
"benchmark.cpp",
@@ -94,17 +97,27 @@ pub fn build(b: *Build) !void {
9497

9598
/// The first time we run "zig build", we need to download the necessary nnue files
9699
fn downloadNNUE(b: *Build, nnue_file: []const u8) !void {
97-
_ = fs.cwd().statFile(nnue_file) catch |err| {
98-
switch (err) {
99-
error.FileNotFound => {
100-
const url = try fmt.allocPrint(b.allocator, "https://data.stockfishchess.org/nn/{s}", .{nnue_file});
101-
std.debug.print("No nnue file found, downloading {s}\n\n", .{url});
100+
const result = if (@hasDecl(fs, "Dir") and @hasDecl(fs.Dir, "statFile"))
101+
fs.cwd().statFile(nnue_file)
102+
else
103+
Io.Dir.cwd().statFile(b.graph.io, nnue_file, .{});
102104

105+
_ = result catch |err| switch (err) {
106+
error.FileNotFound => {
107+
const url = try fmt.allocPrint(b.allocator, "https://data.stockfishchess.org/nn/{s}", .{nnue_file});
108+
std.debug.print("No nnue file found, downloading {s}\n\n", .{url});
109+
110+
if (@hasDecl(std.process, "spawn")) {
111+
var child = try std.process.spawn(b.graph.io, .{
112+
.argv = &.{ "curl", "-o", nnue_file, url },
113+
});
114+
std.debug.assert((try child.wait(b.graph.io)).exited == 0);
115+
} else {
103116
var child = std.process.Child.init(&.{ "curl", "-o", nnue_file, url }, b.allocator);
104117
try child.spawn();
105118
_ = try child.wait();
106-
},
107-
else => return err,
108-
}
119+
}
120+
},
121+
else => return err,
109122
};
110123
}

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .stockfish,
33
.fingerprint = 0x471e85fceadc709,
44
.version = "17.0.0",
5-
.minimum_zig_version = "0.14.0",
5+
.minimum_zig_version = "0.15.1",
66
.dependencies = .{
77
.Stockfish = .{
88
.url = "https://github.com/official-stockfish/Stockfish/archive/sf_17.1.tar.gz",

0 commit comments

Comments
 (0)