Skip to content

Commit 6795b77

Browse files
template: add zig project
1 parent b9bd11f commit 6795b77

File tree

10 files changed

+164
-0
lines changed

10 files changed

+164
-0
lines changed

template/zig/.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; https://editorconfig.org
2+
root = true
3+
4+
; default configuration
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
indent_style = unset
11+
12+
[{*.nix,flake.lock}]
13+
indent_style = space
14+
indent_size = 2
15+
16+
[*.{yml,yaml}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[*.md]
21+
indent_style = space
22+
indent_size = 2
23+
24+
[*.zig]
25+
indent_style = space
26+
indent_size = 4

template/zig/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: main
2+
on:
3+
pull_request:
4+
branches: [main]
5+
push:
6+
branches: [main]
7+
env:
8+
CI_NIX_STORE: ~/nix
9+
CI_NIX_FLAKE: .#default
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup Nix
15+
uses: cachix/install-nix-action@v26
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Cache Nix
19+
uses: actions/cache@v4
20+
with:
21+
path: ${{ env.CI_NIX_STORE }}
22+
key: ${{ runner.os }}-nix-${{ hashFiles('flake.nix', 'flake.lock') }}
23+
- name: Lint
24+
run: |
25+
nix --store ${{ env.CI_NIX_STORE }} \
26+
develop ${{ env.CI_NIX_FLAKE }} --command \
27+
editorconfig-checker && echo "ok"

template/zig/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://github.com/github/gitignore/blob/main/Zig.gitignore
2+
3+
.zig-cache/
4+
zig-out/

template/zig/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test:
2+
@zig build test
3+
run:
4+
@zig build run

template/zig/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Zig Project

template/zig/build.zig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
7+
const exe = b.addExecutable(.{
8+
.name = "zigproject",
9+
.root_source_file = b.path("src/main.zig"),
10+
.target = target,
11+
.optimize = optimize,
12+
});
13+
14+
b.installArtifact(exe);
15+
16+
const run_exe = b.addRunArtifact(exe);
17+
const run_step = b.step("run", "Run the application");
18+
run_step.dependOn(&run_exe.step);
19+
20+
const unit_tests = b.addTest(.{
21+
.root_source_file = b.path("src/main.zig"),
22+
.target = target,
23+
.optimize = optimize,
24+
});
25+
26+
const run_unit_tests = b.addRunArtifact(unit_tests);
27+
const test_step = b.step("test", "Run unit tests");
28+
test_step.dependOn(&run_unit_tests.step);
29+
}

template/zig/flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

template/zig/flake.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
description = "Zig Project";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
6+
outputs =
7+
{ nixpkgs, ... }:
8+
let
9+
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
10+
in
11+
{
12+
devShells = forAllSystems (
13+
system:
14+
let
15+
pkgs = nixpkgs.legacyPackages.${system};
16+
in
17+
{
18+
default = pkgs.mkShell {
19+
name = "zig-project";
20+
shellHook = ''
21+
git config pull.rebase true
22+
${pkgs.neo-cowsay}/bin/cowsay -f sage "Zig Project"
23+
'';
24+
buildInputs = with pkgs; [
25+
editorconfig-checker
26+
zig
27+
];
28+
};
29+
}
30+
);
31+
};
32+
}

template/zig/src/main.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const std = @import("std");
2+
3+
fn greet() []const u8 {
4+
return "Hello, World!";
5+
}
6+
7+
pub fn main() !void {
8+
std.debug.print("{s}\n", .{greet()});
9+
}
10+
11+
test "greet" {
12+
try std.testing.expectEqualStrings("Hello, World!", greet());
13+
}

0 commit comments

Comments
 (0)