mirror of
https://github.com/ziglang/zig.git
synced 2026-02-10 19:41:16 +00:00
This commit introduces a new flag to generate a new Zig project using `zig init` without comments for users who are already familiar with the Zig build system. Additionally, the generated files are now different. Previously we would generate a set of files that defined a static library and an executable, which real-life experience has shown to cause confusion to newcomers. The new template generates one Zig module and one executable both in order to accommodate the two most common use cases, but also to suggest that a library could use a CLI tool (e.g. a parser library could use a CLI tool that provides syntax checking) and vice-versa a CLI tool might want to expose its core functionality as a Zig module. All references to C interoperability are removed from the template under the assumption that if you're tall enough to do C interop, you're also tall enough to find your way around the build system. Experienced users will still be able to use the current template and adapt it with minimal changes in order to perform more advanced operations. As an example, one only needs to change `b.addExecutable` to `b.addLibrary` to switch from generating an executable to a dynamic (or static) library.
24 lines
726 B
Zig
24 lines
726 B
Zig
//! By convention, root.zig is the root source file when making a library.
|
|
const std = @import("std");
|
|
|
|
pub fn advancedPrint() !void {
|
|
// Stdout is for the actual output of your application, for example if you
|
|
// are implementing gzip, then only the compressed bytes should be sent to
|
|
// stdout, not any debugging messages.
|
|
const stdout_file = std.io.getStdOut().writer();
|
|
var bw = std.io.bufferedWriter(stdout_file);
|
|
const stdout = bw.writer();
|
|
|
|
try stdout.print("Run `zig build test` to run the tests.\n", .{});
|
|
|
|
try bw.flush(); // Don't forget to flush!
|
|
}
|
|
|
|
pub fn add(a: i32, b: i32) i32 {
|
|
return a + b;
|
|
}
|
|
|
|
test "basic add functionality" {
|
|
try std.testing.expect(add(3, 7) == 10);
|
|
}
|