Skip to content

Commit c39e802

Browse files
authored
Update Zig bindings to Zig 0.12.0 (#1951)
* update zig bindings to Zig 0.12.0 * support zig package manager * Fix zig macos ci build * Make the macos build use 1 process instead of hitting the macos process limit immediately, utilize the build.zig `-Dparallel false` option for macos ci * Split the macos ci into a new build stage (out of the ubuntu, macos build maxtrix), to allow for multiple architecture builds in the future after the zig bindings improve
1 parent 751a4d0 commit c39e802

File tree

5 files changed

+201
-132
lines changed

5 files changed

+201
-132
lines changed

.github/workflows/zigbuild.yml

+30-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ on:
1515
pull_request:
1616

1717
jobs:
18-
build:
18+
build-ubuntu:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
runs-on: [ubuntu-latest, macos-latest]
22+
runs-on: [ubuntu-latest]
2323
runs-on: ${{ matrix.runs-on }}
2424
steps:
2525
- uses: actions/checkout@v3
@@ -28,7 +28,7 @@ jobs:
2828
fetch-depth: 0
2929
- uses: goto-bus-stop/setup-zig@v2
3030
with:
31-
version: 0.11.0
31+
version: 0.12.0
3232
- uses: lukka/get-cmake@latest
3333
with:
3434
cmakeVersion: latest
@@ -39,7 +39,33 @@ jobs:
3939

4040
- name: Build Summary
4141
run: zig build --summary all -freference-trace
42+
build-macos:
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
runs-on: [macos-latest]
47+
runs-on: ${{ matrix.runs-on }}
48+
steps:
49+
- uses: actions/checkout@v3
50+
with:
51+
submodules: recursive
52+
fetch-depth: 0
53+
- uses: goto-bus-stop/setup-zig@v2
54+
with:
55+
version: 0.12.0
56+
- uses: lukka/get-cmake@latest
57+
with:
58+
cmakeVersion: latest
59+
ninjaVersion: latest
4260

61+
# MacOS has a hard process limit that we will hit if we do a
62+
# parallel build, so disable parallel cmake build (manual
63+
# option set in `build.zig`)
64+
- name: CMake Build
65+
run: zig build -Dparallel=false cmake
66+
67+
- name: Build Summary
68+
run: zig build --summary all -freference-trace
4369
# ===================================================================
4470
# zig-mingw:
4571
# runs-on: windows-latest
@@ -78,4 +104,4 @@ jobs:
78104
# else
79105
# zig build --summary all -freference-trace -Dtarget=${{ matrix.arch }}-windows
80106
# fi
81-
107+

bindings/zig/README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,18 @@ based on [QEMU](http://www.qemu.org/).
77

88
## How to use
99

10-
Add to your project the file `unicorn/unicorn.zig` that will manage all the available architectures.
10+
Using the [Zig Build System](https://ziglang.org/learn/build-system/), you can include
11+
the following into your local `build.zig.zon`
12+
13+
``` zig
14+
.{
15+
.dependencies = .{
16+
.unicorn = .{
17+
.url = "https://github.com/unicorn-engine/unicorn/archive/<ref SHA>.tar.gz",
18+
.hash = "<hash>",
19+
}
20+
},
21+
}
22+
```
23+
24+
Note that currently the only module exported publicly is `unicorn-sys`

bindings/zig/sample/sample_riscv_zig.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ fn hook_code3(uc: ?*unicornC.uc_engine, address: u64, size: u32, user_data: ?*an
3838
fn hook_memalloc(uc: ?*unicornC.uc_engine, @"type": unicornC.uc_mem_type, address: u64, size: u32, user_data: ?*anyopaque) callconv(.C) bool {
3939
_ = user_data;
4040
_ = @"type";
41-
var algined_address = address & 0xFFFFFFFFFFFFF000;
42-
var aligned_size = (@as(u32, @intCast(size / 0x1000)) + 1) * 0x1000;
41+
const algined_address = address & 0xFFFFFFFFFFFFF000;
42+
const aligned_size = (@as(u32, @intCast(size / 0x1000)) + 1) * 0x1000;
4343

4444
log.info(">>> Allocating block at 0x{} (0x{}), block size = 0x{} (0x{})", .{ address, algined_address, size, aligned_size });
4545

0 commit comments

Comments
 (0)