Skip to content

Commit f269809

Browse files
committed
Update to support news
1 parent f387897 commit f269809

File tree

7 files changed

+87
-61
lines changed

7 files changed

+87
-61
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,18 @@ on:
99
workflow_dispatch:
1010

1111
jobs:
12-
build_12:
13-
runs-on: ubuntu-latest
14-
12+
build:
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest]
16+
version: [0.11.0, 0.12.0, ""]
17+
fail-fast: false
18+
runs-on: ${{ matrix.os }}
1519
steps:
16-
- name: Checkout repository
17-
uses: actions/checkout@v3
18-
with:
19-
fetch-depth: 0
20-
21-
- name: Set up Zig
20+
- name: Setup Zig
2221
uses: goto-bus-stop/setup-zig@v2
23-
24-
- name: Build and test with Zig
25-
run: zig build test
26-
27-
build_11:
28-
runs-on: ubuntu-latest
29-
30-
steps:
31-
- name: Checkout repository
32-
uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
3323
with:
3424
fetch-depth: 0
35-
36-
- name: Set up Zig
37-
uses: goto-bus-stop/setup-zig@v2
38-
with:
39-
version: 0.11.0
40-
4125
- name: Build and test with Zig
4226
run: zig build test

.github/workflows/deploy_docs.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@ jobs:
4040
cache: false
4141
- name: Generate Docs
4242
run: zig build docs
43-
- name: Deploy
44-
uses: peaceiris/actions-gh-pages@v3
43+
- name: Upload artifact
44+
uses: actions/upload-pages-artifact@v3
4545
with:
46-
github_token: ${{ secrets.GITHUB_TOKEN }}
47-
publish_branch: docs
48-
publish_dir: ./zig-out/docs
46+
path: ./zig-out/docs
47+
deploy:
48+
environment:
49+
name: github-pages
50+
url: ${{ steps.deployment.outputs.page_url }}
51+
runs-on: ubuntu-latest
52+
needs: generate_docs
53+
steps:
54+
- name: Deploy to GitHub Pages
55+
id: deployment
56+
uses: actions/deploy-pages@v4

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,19 @@ const msgpack = b.dependency("zig-msgpack", .{
4141
exe.addModule("msgpack", msgpack.module("msgpack"));
4242
```
4343

44-
### `nightly`
44+
### `0.12` \ `nightly`
4545

4646
1. Add to `build.zig.zon`
4747

4848
```sh
4949
zig fetch --save https://github.com/zigcc/zig-msgpack/archive/{commit or branch}.tar.gz
50+
# Of course, you can also use git+https to fetch this package!
5051
```
5152

5253
2. Config `build.zig`
5354

5455
```zig
56+
// To standardize development, maybe you should use `lazyDependency()` instead of `dependency()`
5557
const msgpack = b.dependency("zig-msgpack", .{
5658
.target = target,
5759
.optimize = optimize,

build.zig

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3+
const build_11 = @import("build_11.zig").build;
4+
const build_12 = @import("build_12.zig").build;
5+
const build_13 = @import("build_13.zig").build;
36

47
const min_zig_string = "0.11.0";
58

@@ -16,8 +19,11 @@ comptime {
1619
}
1720
}
1821

19-
pub const build =
20-
if (current_zig.minor == 11)
21-
@import("build_11.zig").build
22-
else
23-
@import("build_12.zig").build;
22+
pub fn build(b: *std.Build) void {
23+
switch (current_zig.minor) {
24+
11 => build_11(b),
25+
12 => build_12(b),
26+
13 => build_13(b),
27+
else => @compileError("unknown version!"),
28+
}
29+
}

build_12.zig

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ pub fn build(b: *std.Build) void {
1313
},
1414
});
1515

16-
generateDocs(b, optimize, target);
17-
1816
const test_step = b.step("test", "Run unit tests");
1917

2018
const msgpack_unit_tests = b.addTest(.{
@@ -26,24 +24,3 @@ pub fn build(b: *std.Build) void {
2624
const run_msgpack_tests = b.addRunArtifact(msgpack_unit_tests);
2725
test_step.dependOn(&run_msgpack_tests.step);
2826
}
29-
30-
fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget) void {
31-
const lib = b.addObject(.{
32-
.name = "zig-msgpack",
33-
.root_source_file = .{
34-
.path = "src/msgpack.zig",
35-
},
36-
.target = target,
37-
.optimize = optimize,
38-
});
39-
40-
const docs_step = b.step("docs", "Emit docs");
41-
42-
const docs_install = b.addInstallDirectory(.{
43-
.source_dir = lib.getEmittedDocs(),
44-
.install_dir = .prefix,
45-
.install_subdir = "docs",
46-
});
47-
48-
docs_step.dependOn(&docs_install.step);
49-
}

build_13.zig

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const std = @import("std");
2+
const Build = std.Build;
3+
const Module = Build.Module;
4+
const OptimizeMode = std.builtin.OptimizeMode;
5+
6+
pub fn build(b: *std.Build) void {
7+
const target = b.standardTargetOptions(.{});
8+
const optimize = b.standardOptimizeOption(.{});
9+
10+
const msgpack = b.addModule("msgpack", .{
11+
.root_source_file = .{
12+
.path = "src/msgpack.zig",
13+
},
14+
});
15+
16+
generateDocs(b, optimize, target);
17+
18+
const test_step = b.step("test", "Run unit tests");
19+
20+
const msgpack_unit_tests = b.addTest(.{
21+
.root_source_file = .{ .path = "src/msgpack_unit_test.zig" },
22+
.target = target,
23+
.optimize = optimize,
24+
});
25+
msgpack_unit_tests.root_module.addImport("msgpack", msgpack);
26+
const run_msgpack_tests = b.addRunArtifact(msgpack_unit_tests);
27+
test_step.dependOn(&run_msgpack_tests.step);
28+
}
29+
30+
fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget) void {
31+
const lib = b.addObject(.{
32+
.name = "zig-msgpack",
33+
.root_source_file = .{
34+
.path = "src/msgpack.zig",
35+
},
36+
.target = target,
37+
.optimize = optimize,
38+
});
39+
40+
const docs_step = b.step("docs", "Emit docs");
41+
42+
const docs_install = b.addInstallDirectory(.{
43+
.source_dir = lib.getEmittedDocs(),
44+
.install_dir = .prefix,
45+
.install_subdir = "docs",
46+
});
47+
48+
docs_step.dependOn(&docs_install.step);
49+
}

src/msgpack.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const native_endian = builtin.cpu.arch.endian();
1111

1212
const big_endian = switch (current_zig.minor) {
1313
11 => std.builtin.Endian.Big,
14-
12 => std.builtin.Endian.big,
14+
12, 13 => std.builtin.Endian.big,
1515
else => @compileError("not support current version zig"),
1616
};
1717
const little_endian = switch (current_zig.minor) {
1818
11 => std.builtin.Endian.Little,
19-
12 => std.builtin.Endian.little,
19+
12, 13 => std.builtin.Endian.little,
2020
else => @compileError("not support current version zig"),
2121
};
2222

0 commit comments

Comments
 (0)