Skip to content

Commit

Permalink
Update to support news
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Apr 22, 2024
1 parent f387897 commit f269809
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 61 deletions.
34 changes: 9 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,18 @@ on:
workflow_dispatch:

jobs:
build_12:
runs-on: ubuntu-latest

build:
strategy:
matrix:
os: [ubuntu-latest]
version: [0.11.0, 0.12.0, ""]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Zig
- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2

- name: Build and test with Zig
run: zig build test

build_11:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0

- name: Build and test with Zig
run: zig build test
18 changes: 13 additions & 5 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ jobs:
cache: false
- name: Generate Docs
run: zig build docs
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: docs
publish_dir: ./zig-out/docs
path: ./zig-out/docs
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: generate_docs
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ const msgpack = b.dependency("zig-msgpack", .{
exe.addModule("msgpack", msgpack.module("msgpack"));
```

### `nightly`
### `0.12` \ `nightly`

1. Add to `build.zig.zon`

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

2. Config `build.zig`

```zig
// To standardize development, maybe you should use `lazyDependency()` instead of `dependency()`
const msgpack = b.dependency("zig-msgpack", .{
.target = target,
.optimize = optimize,
Expand Down
16 changes: 11 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const std = @import("std");
const builtin = @import("builtin");
const build_11 = @import("build_11.zig").build;
const build_12 = @import("build_12.zig").build;
const build_13 = @import("build_13.zig").build;

const min_zig_string = "0.11.0";

Expand All @@ -16,8 +19,11 @@ comptime {
}
}

pub const build =
if (current_zig.minor == 11)
@import("build_11.zig").build
else
@import("build_12.zig").build;
pub fn build(b: *std.Build) void {
switch (current_zig.minor) {
11 => build_11(b),
12 => build_12(b),
13 => build_13(b),
else => @compileError("unknown version!"),
}
}
23 changes: 0 additions & 23 deletions build_12.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ pub fn build(b: *std.Build) void {
},
});

generateDocs(b, optimize, target);

const test_step = b.step("test", "Run unit tests");

const msgpack_unit_tests = b.addTest(.{
Expand All @@ -26,24 +24,3 @@ pub fn build(b: *std.Build) void {
const run_msgpack_tests = b.addRunArtifact(msgpack_unit_tests);
test_step.dependOn(&run_msgpack_tests.step);
}

fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget) void {
const lib = b.addObject(.{
.name = "zig-msgpack",
.root_source_file = .{
.path = "src/msgpack.zig",
},
.target = target,
.optimize = optimize,
});

const docs_step = b.step("docs", "Emit docs");

const docs_install = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});

docs_step.dependOn(&docs_install.step);
}
49 changes: 49 additions & 0 deletions build_13.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const std = @import("std");
const Build = std.Build;
const Module = Build.Module;
const OptimizeMode = std.builtin.OptimizeMode;

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const msgpack = b.addModule("msgpack", .{
.root_source_file = .{
.path = "src/msgpack.zig",
},
});

generateDocs(b, optimize, target);

const test_step = b.step("test", "Run unit tests");

const msgpack_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/msgpack_unit_test.zig" },
.target = target,
.optimize = optimize,
});
msgpack_unit_tests.root_module.addImport("msgpack", msgpack);
const run_msgpack_tests = b.addRunArtifact(msgpack_unit_tests);
test_step.dependOn(&run_msgpack_tests.step);
}

fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget) void {
const lib = b.addObject(.{
.name = "zig-msgpack",
.root_source_file = .{
.path = "src/msgpack.zig",
},
.target = target,
.optimize = optimize,
});

const docs_step = b.step("docs", "Emit docs");

const docs_install = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});

docs_step.dependOn(&docs_install.step);
}
4 changes: 2 additions & 2 deletions src/msgpack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const native_endian = builtin.cpu.arch.endian();

const big_endian = switch (current_zig.minor) {
11 => std.builtin.Endian.Big,
12 => std.builtin.Endian.big,
12, 13 => std.builtin.Endian.big,
else => @compileError("not support current version zig"),
};
const little_endian = switch (current_zig.minor) {
11 => std.builtin.Endian.Little,
12 => std.builtin.Endian.little,
12, 13 => std.builtin.Endian.little,
else => @compileError("not support current version zig"),
};

Expand Down

0 comments on commit f269809

Please sign in to comment.