Skip to content

Commit

Permalink
refactor examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Nov 25, 2023
1 parent bb2dd21 commit 38c068a
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 56 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ jobs:
make lint
git diff --exit-code
test:
examples:
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: goto-bus-stop/setup-zig@v2
with:
version: master
- name: Run Test
run: ./run-all.sh
- name: Run examples(Unix)
if: matrix.os != 'windows-latest'
working-directory: examples
run: zig build run-all

- name: Run examples(Windows)
if: matrix.os == 'windows-latest'
working-directory: examples
run: zig.exe build run-all
13 changes: 0 additions & 13 deletions 01-zig-files-are-struct/build.zig

This file was deleted.

13 changes: 0 additions & 13 deletions 02-name-convention/build.zig

This file was deleted.

13 changes: 0 additions & 13 deletions 03-dot-literals/build.zig

This file was deleted.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

lint:
npx [email protected] --write .

run-all:
zig build run-all
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

[![](https://github.com/zigcc/zig-idioms/actions/workflows/ci.yml/badge.svg)](https://github.com/zigcc/zig-idioms/actions/workflows/ci.yml)

This repository collects idioms/quirks for Zig.
> Zig, despite its simplicity, harbors unique features rarely found in other programming languages. This project aims to collect these techniques, serving as a valuable complement to the [Zig Language Reference](https://ziglang.org/documentation/master).
Each idiom is given an example named after it, which could be run with `zig build run`.

> This could be used as a quick guide for learner with other programming languages background.
Each idiom is accompanied by an illustrative example named after its corresponding sequence number. These examples can be executed using the command `zig build run-{number}`, or `zig build run-all` to execute all.

## 01. Zig files are structs

Expand Down
19 changes: 19 additions & 0 deletions examples/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const std = @import("std");

pub fn build(b: *std.Build) !void {
var run_all_step = b.step("run-all", "Run all examples");
inline for (1..4) |num| {
// This will padding number like 01, 02, .. 99
const seq = std.fmt.comptimePrint("{d:0>2}", .{num});
const exe = b.addExecutable(.{
.name = "examples-" ++ seq,
.root_source_file = .{ .path = "src/" ++ seq ++ ".zig" },
.target = .{},
.optimize = .Debug,
});

const run_step = &b.addRunArtifact(exe).step;
b.step("run-" ++ seq, "Run example " ++ seq).dependOn(run_step);
run_all_step.dependOn(run_step);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions run-all.sh

This file was deleted.

0 comments on commit 38c068a

Please sign in to comment.