Skip to content

Commit 23172c2

Browse files
committed
Initial commit
0 parents  commit 23172c2

File tree

8 files changed

+134
-0
lines changed

8 files changed

+134
-0
lines changed

.github/workflows/ci.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
name: Tests on Linux
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: goto-bus-stop/setup-zig@v2
17+
- uses: Hanaasagi/[email protected]
18+
with:
19+
cache-on-failure: true
20+
- run: zig version
21+
- run: zig env
22+
- name: Build
23+
run: zig build --verbose
24+
- name: Run Tests
25+
run: zig build test

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/zig-out/
2+
**/zig-cache/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# zig-project-template

build.zig

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const std = @import("std");
2+
3+
// Although this function looks imperative, note that its job is to
4+
// declaratively construct a build graph that will be executed by an external
5+
// runner.
6+
pub fn build(b: *std.Build) void {
7+
// Standard target options allows the person running `zig build` to choose
8+
// what target to build for. Here we do not override the defaults, which
9+
// means any target is allowed, and the default is native. Other options
10+
// for restricting supported target set are available.
11+
const target = b.standardTargetOptions(.{});
12+
13+
// Standard optimization options allow the person running `zig build` to select
14+
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
15+
// set a preferred release mode, allowing the user to decide how to optimize.
16+
const optimize = b.standardOptimizeOption(.{});
17+
18+
const lib = b.addStaticLibrary(.{
19+
.name = "zig-project-template",
20+
// In this case the main source file is merely a path, however, in more
21+
// complicated build scripts, this could be a generated file.
22+
.root_source_file = .{ .path = "src/lib.zig" },
23+
.target = target,
24+
.optimize = optimize,
25+
});
26+
27+
// This declares intent for the library to be installed into the standard
28+
// location when the user invokes the "install" step (the default step when
29+
// running `zig build`).
30+
b.installArtifact(lib);
31+
32+
// Creates a step for unit testing. This only builds the test executable
33+
// but does not run it.
34+
const main_tests = b.addTest(.{
35+
.root_source_file = .{ .path = "src/lib.zig" },
36+
.target = target,
37+
.optimize = optimize,
38+
});
39+
40+
const run_main_tests = b.addRunArtifact(main_tests);
41+
42+
// This creates a build step. It will be visible in the `zig build --help` menu,
43+
// and can be selected like this: `zig build test`
44+
// This will evaluate the `test` step rather than the default, which is "install".
45+
const test_step = b.step("test", "Run library tests");
46+
test_step.dependOn(&run_main_tests.step);
47+
}

build.zig.zon

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.{
2+
.name = "zig-project-template",
3+
.version = "0.1.0",
4+
.dependencies = .{},
5+
}

examples/build.zig

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const std = @import("std");
2+
3+
const pkg_name = "zig-project-template";
4+
const pkg_path = "../src/lib.zig";
5+
6+
const examples = .{
7+
"default",
8+
};
9+
10+
pub fn build(b: *std.build.Builder) void {
11+
const target = b.standardTargetOptions(.{});
12+
const optimize = b.standardOptimizeOption(.{});
13+
14+
inline for (examples) |e| {
15+
const example_path = e ++ "/main.zig";
16+
const exe_name = "example-" ++ e;
17+
const run_name = "run-" ++ e;
18+
const run_desc = "Run the " ++ e ++ " example";
19+
20+
const exe = b.addExecutable(.{
21+
.name = exe_name,
22+
.root_source_file = .{ .path = example_path },
23+
.target = target,
24+
.optimize = optimize,
25+
});
26+
const mod = b.addModule("zig-project-template", .{
27+
.source_file = .{ .path = "../src/lib.zig" },
28+
});
29+
exe.addModule("zig-project-template", mod);
30+
31+
b.installArtifact(exe);
32+
33+
const run_cmd = b.addRunArtifact(exe);
34+
35+
run_cmd.step.dependOn(b.getInstallStep());
36+
const run_step = b.step(run_name, run_desc);
37+
run_step.dependOn(&run_cmd.step);
38+
}
39+
}

examples/default/main.zig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const std = @import("std");
2+
3+
pub fn main() !void {
4+
std.debug.print("Hello World!\n", .{});
5+
}

src/lib.zig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const std = @import("std");
2+
const testing = std.testing;
3+
4+
export fn add(a: i32, b: i32) i32 {
5+
return a + b;
6+
}
7+
8+
test "basic add functionality" {
9+
try testing.expect(add(3, 7) == 10);
10+
}

0 commit comments

Comments
 (0)