Initial Commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.zig-cache/
|
||||||
|
zig-out/
|
||||||
|
.idea/
|
1
.tool-versions
Normal file
1
.tool-versions
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zig 0.14.0-dev.2647+5322459a0
|
18
README.md
Normal file
18
README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
### Configuring CLion for debugging
|
||||||
|
|
||||||
|
Use https://github.com/asdf-vm/asdf with https://github.com/allemangd/asdf-zig for the versioned zig master in `.tool-versions`.
|
||||||
|
|
||||||
|
Build ZLS with that zig and point ZigBrains to it.
|
||||||
|
|
||||||
|
Custom Build Application configurations:
|
||||||
|
|
||||||
|
- `zig-shape` uses custom target `zig build -fincremental` and executes `zig-out/bin/zig-shape`.
|
||||||
|
- `exe-unit-tests` uses custom target `zig build -fincremental build-tests` and executes `zig-out/dev/exe-unit-tests`
|
||||||
|
- `lib-unit-tests` uses custom target `zig build -fincremental build-tests` and executes `zig-out/dev/lib-unit-tests`
|
||||||
|
|
||||||
|
Then native "build", "run", and "debug" buttons will work.
|
||||||
|
|
||||||
|
Optionally create a "clean" target that executes `rm -r .zig-cache zig-out`
|
||||||
|
|
||||||
|
Switching between debug and release build is more difficult. Probably easier to run release builds
|
||||||
|
only via CLI, like `zig build --release=fast` or `zig build --release=fast test`.
|
70
build.zig
Normal file
70
build.zig
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) void {
|
||||||
|
const target = b.standardTargetOptions(.{});
|
||||||
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
const lib_mod = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/root.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
|
||||||
|
const exe_mod = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
|
||||||
|
exe_mod.addImport("zig-shape-lib", lib_mod);
|
||||||
|
|
||||||
|
const lib = b.addStaticLibrary(.{
|
||||||
|
.name = "zig-shape",
|
||||||
|
.root_module = lib_mod,
|
||||||
|
});
|
||||||
|
|
||||||
|
b.installArtifact(lib);
|
||||||
|
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "zig-shape",
|
||||||
|
.root_module = exe_mod,
|
||||||
|
});
|
||||||
|
|
||||||
|
b.installArtifact(exe);
|
||||||
|
|
||||||
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
|
||||||
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
if (b.args) |args| {
|
||||||
|
run_cmd.addArgs(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
const run_step = b.step("run", "Run the app");
|
||||||
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
||||||
|
const lib_unit_tests = b.addTest(.{
|
||||||
|
.root_module = lib_mod,
|
||||||
|
.name = "lib-unit-tests",
|
||||||
|
});
|
||||||
|
|
||||||
|
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
|
||||||
|
|
||||||
|
const exe_unit_tests = b.addTest(.{
|
||||||
|
.root_module = exe_mod,
|
||||||
|
.name = "exe-unit-tests",
|
||||||
|
});
|
||||||
|
|
||||||
|
const build_test_step = b.step("build-test", "Build unit tests");
|
||||||
|
|
||||||
|
const install_lib_test = b.addInstallArtifact(lib_unit_tests, .{ .dest_dir = .{ .override = .{ .custom = "dev" } } });
|
||||||
|
build_test_step.dependOn(&install_lib_test.step);
|
||||||
|
|
||||||
|
const install_exe_test = b.addInstallArtifact(exe_unit_tests, .{ .dest_dir = .{ .override = .{ .custom = "dev" } } });
|
||||||
|
build_test_step.dependOn(&install_exe_test.step);
|
||||||
|
|
||||||
|
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||||
|
|
||||||
|
const test_step = b.step("test", "Run unit tests");
|
||||||
|
test_step.dependOn(&run_lib_unit_tests.step);
|
||||||
|
test_step.dependOn(&run_exe_unit_tests.step);
|
||||||
|
}
|
16
build.zig.zon
Normal file
16
build.zig.zon
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
.{
|
||||||
|
.name = "zig-shape",
|
||||||
|
.version = "0.0.0",
|
||||||
|
|
||||||
|
.minimum_zig_version = "0.14.0",
|
||||||
|
|
||||||
|
.dependencies = .{
|
||||||
|
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
|
||||||
|
},
|
||||||
|
|
||||||
|
.paths = .{
|
||||||
|
"build.zig",
|
||||||
|
"build.zig.zon",
|
||||||
|
"src",
|
||||||
|
},
|
||||||
|
}
|
35
src/main.zig
Normal file
35
src/main.zig
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const lib = @import("zig-shape-lib");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
test "simple test" {
|
||||||
|
var list = std.ArrayList(i32).init(std.testing.allocator);
|
||||||
|
defer list.deinit();
|
||||||
|
try list.append(42);
|
||||||
|
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||||
|
}
|
||||||
|
|
||||||
|
test "use other module" {
|
||||||
|
try std.testing.expectEqual(@as(i32, 150), lib.add(100, 50));
|
||||||
|
}
|
||||||
|
|
||||||
|
test "fuzz example" {
|
||||||
|
const global = struct {
|
||||||
|
fn testOne(input: []const u8) anyerror!void {
|
||||||
|
// Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
|
||||||
|
try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try std.testing.fuzz(global.testOne, .{});
|
||||||
|
}
|
14
src/root.zig
Normal file
14
src/root.zig
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
//! By convention, root.zig is the root source file when making a library. If
|
||||||
|
//! you are making an executable, the convention is to delete this file and
|
||||||
|
//! start with main.zig instead.
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
pub export fn add(a: i32, b: i32) i32 {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
test "basic add functionality" {
|
||||||
|
try testing.expect(add(3, 7) == 10);
|
||||||
|
}
|
Reference in New Issue
Block a user