@@ -9,6 +9,7 @@ const heap = std.heap;
99const http = std .http ;
1010const math = std .math ;
1111const mem = std .mem ;
12+ const Io = std .Io ;
1213
1314pub 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
9699fn 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}
0 commit comments