File tree Expand file tree Collapse file tree 15 files changed +79
-96
lines changed
package_management_importer Expand file tree Collapse file tree 15 files changed +79
-96
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ pub fn build(b: *Build) void {
5252 });
5353 exe .linkLibC ();
5454
55+ if (exe .root_module .resolved_target .? .result .os .tag == .windows and std .mem .eql (u8 , "echo_tcp_server.zig" , entry .name )) {
56+ std .log .info ("link ws2_32 for {s}" , .{entry .name });
57+ exe .linkSystemLibrary ("ws2_32" );
58+ }
5559 // add to default install
5660 b .installArtifact (exe );
5761
Original file line number Diff line number Diff line change 11const std = @import ("std" );
22
33pub fn build (b : * std.Build ) void {
4- // 标准构建目标
54 const target = b .standardTargetOptions (.{});
6-
7- // 标准构建模式
85 const optimize = b .standardOptimizeOption (.{});
96
10- // 添加一个二进制可执行程序构建
117 const exe = b .addExecutable (.{
128 .name = "zig" ,
13- .root_module = b .addModule ( "zig" , .{
9+ .root_module = b .createModule ( .{
1410 .root_source_file = b .path ("src/main.zig" ),
1511 .target = target ,
1612 .optimize = optimize ,
1713 }),
1814 });
1915
20- // 添加到顶级 install step 中作为依赖
2116 b .installArtifact (exe );
2217}
Original file line number Diff line number Diff line change @@ -7,12 +7,13 @@ pub fn main() !void {
77 // stdout is for the actual output of your application, for example if you
88 // are implementing gzip, then only the compressed bytes should be sent to
99 // stdout, not any debugging messages.
10- const stdout_file = std .io .getStdOut ().writer ();
11- var bw = std .io .bufferedWriter (stdout_file );
12- const stdout = bw .writer ();
10+ var stdout_buffer : [1024 ]u8 = undefined ;
11+ var stdout_writer = std .fs .File .stdout ().writer (& stdout_buffer );
12+ const stdout = & stdout_writer .interface ;
13+
1314 try stdout .print ("Run `zig build test` to run the tests.\n " , .{});
1415
15- try bw .flush (); // don't forget to flush!
16+ try stdout .flush ();
1617}
1718
1819test "simple test" {
Original file line number Diff line number Diff line change 11const std = @import ("std" );
22
33pub fn build (b : * std.Build ) void {
4- // 标准构建目标
54 const target = b .standardTargetOptions (.{});
6-
7- // 标准构建模式
85 const optimize = b .standardOptimizeOption (.{});
9-
10- // 使用 option 来获取命令参数决定是否剥离调试信息
116 const is_strip =
127 b .option (bool , "is_strip" , "whether strip executable" ) orelse
138 false ;
149
15- // 添加一个二进制可执行程序构建
1610 const exe = b .addExecutable (.{
1711 .name = "zig" ,
18- .root_module = b .addModule ( "zig" , .{
12+ .root_module = b .createModule ( .{
1913 .root_source_file = b .path ("src/main.zig" ),
2014 .target = target ,
2115 .optimize = optimize ,
22- // 设置 exe 的 strip
2316 .strip = is_strip ,
2417 }),
2518 });
2619
27- // 添加到顶级 install step 中作为依赖
2820 b .installArtifact (exe );
2921}
Original file line number Diff line number Diff line change @@ -7,13 +7,13 @@ pub fn main() !void {
77 // stdout is for the actual output of your application, for example if you
88 // are implementing gzip, then only the compressed bytes should be sent to
99 // stdout, not any debugging messages.
10- const stdout_file = std . io . getStdOut (). writer () ;
11- var bw = std .io . bufferedWriter ( stdout_file );
12- const stdout = bw . writer () ;
10+ var stdout_buffer : [ 1024 ] u8 = undefined ;
11+ var stdout_writer = std .fs . File . stdout (). writer ( & stdout_buffer );
12+ const stdout = & stdout_writer . interface ;
1313
1414 try stdout .print ("Run `zig build test` to run the tests.\n " , .{});
1515
16- try bw .flush (); // don't forget to flush!
16+ try stdout .flush (); // don't forget to flush!
1717}
1818
1919test "simple test" {
Original file line number Diff line number Diff line change @@ -8,35 +8,24 @@ pub fn build(b: *std.Build) void {
88 const optimize = b .standardOptimizeOption (.{});
99
1010 // 尝试添加一个静态库
11- const lib = b .addStaticLibrary (.{
12- // 库的名字
13- .name = "example" ,
14- // 源文件地址
15- .root_module = b .addModule ("example" , .{
16- .root_source_file = b .path ("src/root.zig" ),
17- // 构建目标
18- .target = target ,
19- // 构建模式
20- .optimize = optimize ,
21- }),
22- });
11+ const lib = b .addLibrary (.{ .name = "example" , .root_module = b .createModule (.{
12+ .root_source_file = b .path ("src/root.zig" ),
13+ .target = target ,
14+ .optimize = optimize ,
15+ }) });
2316
24- // 这代替原本的 lib.install,在构建时自动构建 lib
25- // 但其实这是不必要的,因为如果有可执行二进制程序构建使用了 lib,那么它会自动被构建
2617 b .installArtifact (lib );
2718
28- // 添加一个二进制可执行程序构建
2919 const exe = b .addExecutable (.{
3020 .name = "zig" ,
31- .root_module = b .addModule ( "zig" , .{
21+ .root_module = b .createModule ( .{
3222 .root_source_file = b .path ("src/main.zig" ),
3323 .target = target ,
3424 .optimize = optimize ,
3525 }),
3626 });
37- // 链接 lib
27+
3828 exe .linkLibrary (lib );
3929
40- // 添加到顶级 install step 中作为依赖,构建 exe
4130 b .installArtifact (exe );
4231}
Original file line number Diff line number Diff line change @@ -7,18 +7,11 @@ pub fn main() !void {
77 // stdout is for the actual output of your application, for example if you
88 // are implementing gzip, then only the compressed bytes should be sent to
99 // stdout, not any debugging messages.
10- const stdout_file = std . io . getStdOut (). writer () ;
11- var bw = std .io . bufferedWriter ( stdout_file );
12- const stdout = bw . writer () ;
10+ var stdout_buffer : [ 1024 ] u8 = undefined ;
11+ var stdout_writer = std .fs . File . stdout (). writer ( & stdout_buffer );
12+ const stdout = & stdout_writer . interface ;
1313
1414 try stdout .print ("Run `zig build test` to run the tests.\n " , .{});
1515
16- try bw .flush (); // don't forget to flush!
17- }
18-
19- test "simple test" {
20- var list = std .ArrayList (i32 ).init (std .testing .allocator );
21- defer list .deinit (); // try commenting this out and see if zig detects the memory leak!
22- try list .append (42 );
23- try std .testing .expectEqual (@as (i32 , 42 ), list .pop ());
16+ try stdout .flush ();
2417}
Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ pub fn build(b: *std.Build) void {
1010 // 添加一个二进制可执行程序构建
1111 const exe = b .addExecutable (.{
1212 .name = "zig" ,
13- .root_source_file = b .path ("src/main.zig" ),
14- .target = target ,
15- .optimize = optimize ,
13+ .root_module = b .createModule (.{
14+ .root_source_file = b .path ("src/main.zig" ),
15+ .target = target ,
16+ .optimize = optimize ,
17+ }),
1618 });
1719
1820 // 通过标准库获取时间戳
Original file line number Diff line number Diff line change @@ -7,18 +7,11 @@ pub fn main() !void {
77 // stdout is for the actual output of your application, for example if you
88 // are implementing gzip, then only the compressed bytes should be sent to
99 // stdout, not any debugging messages.
10- const stdout_file = std . io . getStdOut (). writer () ;
11- var bw = std .io . bufferedWriter ( stdout_file );
12- const stdout = bw . writer () ;
10+ var stdout_buffer : [ 1024 ] u8 = undefined ;
11+ var stdout_writer = std .fs . File . stdout (). writer ( & stdout_buffer );
12+ const stdout = & stdout_writer . interface ;
1313
1414 try stdout .print ("Run `zig build test` to run the tests.\n " , .{});
1515
16- try bw .flush (); // don't forget to flush!
17- }
18-
19- test "simple test" {
20- var list = std .ArrayList (i32 ).init (std .testing .allocator );
21- defer list .deinit (); // try commenting this out and see if zig detects the memory leak!
22- try list .append (42 );
23- try std .testing .expectEqual (@as (i32 , 42 ), list .pop ());
16+ try stdout .flush ();
2417}
Original file line number Diff line number Diff line change @@ -7,13 +7,13 @@ pub fn main() !void {
77 // stdout is for the actual output of your application, for example if you
88 // are implementing gzip, then only the compressed bytes should be sent to
99 // stdout, not any debugging messages.
10- const stdout_file = std . io . getStdOut (). writer () ;
11- var bw = std .io . bufferedWriter ( stdout_file );
12- const stdout = bw . writer () ;
10+ var stdout_buffer : [ 1024 ] u8 = undefined ;
11+ var stdout_writer = std .fs . File . stdout (). writer ( & stdout_buffer );
12+ const stdout = & stdout_writer . interface ;
1313
1414 try stdout .print ("Run `zig build test` to run the tests.\n " , .{});
1515
16- try bw .flush (); // don't forget to flush!
16+ try stdout .flush ();
1717}
1818
1919test "simple test" {
You can’t perform that action at this time.
0 commit comments