Skip to content

Commit 5a59f3d

Browse files
authored
Generate standalone files for Regz by default (#353)
* Generate standalone files for Regz by default * Fix unit tests * Update stm32 generator * remove dependency * Fix to_zig() invocation * Add dependencies to CI * Add workflow dispatch * Remove circular dependency * Remove dependencies, full parallelism
1 parent 88b3f5a commit 5a59f3d

File tree

6 files changed

+131
-101
lines changed

6 files changed

+131
-101
lines changed

.github/workflows/ci.yml

Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,15 @@ on:
44
branches: [main, zig-master]
55
pull_request:
66
branches: [main, zig-master]
7+
workflow_dispatch:
78

89
env:
910
ZIG_VERSION: ${{ github.ref == 'refs/heads/zig-master' && 'master' || '0.13.0' }}
1011

1112
jobs:
12-
build:
13-
name: Build
14-
runs-on: ${{ matrix.os }}
15-
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v4
18-
- name: Setup Zig
19-
uses: mlugg/setup-zig@v1
20-
with:
21-
version: ${{ env.ZIG_VERSION }}
22-
- name: Build
23-
run: zig build -Doptimize=ReleaseSmall
24-
25-
unit-test-ports:
26-
name: Unit Test Ports
27-
runs-on: ${{ matrix.os }}
28-
needs: build
29-
strategy:
30-
matrix:
31-
os: [ubuntu-latest, windows-latest, macos-latest]
32-
port_dir: [gigadevice/gd32, raspberrypi/rp2xxx, stmicro/stm32]
33-
steps:
34-
- name: Checkout
35-
uses: actions/checkout@v4
36-
- name: Setup Zig
37-
uses: mlugg/setup-zig@v1
38-
with:
39-
version: ${{ env.ZIG_VERSION }}
40-
- name: Unit Test Ports
41-
run: zig build test
42-
working-directory: port/${{ matrix.port_dir }}
43-
4413
unit-test-regz:
4514
name: Unit Test Regz
15+
continue-on-error: true
4616
strategy:
4717
matrix:
4818
os: [ubuntu-latest, windows-latest, macos-latest]
@@ -60,6 +30,7 @@ jobs:
6030

6131
unit-test-uf2:
6232
name: Unit Test UF2
33+
continue-on-error: true
6334
strategy:
6435
matrix:
6536
os: [ubuntu-latest, windows-latest, macos-latest]
@@ -75,48 +46,71 @@ jobs:
7546
run: zig build test
7647
working-directory: tools/uf2
7748

78-
build-website:
79-
name: Build Website
49+
stm32-gen-check:
50+
name: Check that stm32 generated code is up to date
51+
continue-on-error: true
8052
runs-on: ubuntu-latest
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v3
56+
- name: Setup Zig
57+
uses: mlugg/setup-zig@v1
58+
with:
59+
version: ${{ env.ZIG_VERSION }}
60+
- name: Generate Code
61+
run: zig build -Dgenerate
62+
working-directory: port/stmicro/stm32
63+
- name: Check for code diffs
64+
run: |
65+
if [[ $(git status --porcelain | grep -v '^??') ]]; then
66+
echo "Code differences detected:"
67+
git diff
68+
echo "Please commit or fix these changes to proceed."
69+
exit 1
70+
else
71+
echo "No code differences detected."
72+
fi
73+
74+
build:
75+
name: Build
76+
continue-on-error: true
77+
runs-on: ${{ matrix.os }}
78+
strategy:
79+
matrix:
80+
os: [ubuntu-latest, windows-latest, macos-latest]
8181
steps:
8282
- name: Checkout
8383
uses: actions/checkout@v4
8484
- name: Setup Zig
8585
uses: mlugg/setup-zig@v1
8686
with:
8787
version: ${{ env.ZIG_VERSION }}
88-
- name: Build Website
89-
run: zig build
90-
working-directory: website
88+
- name: Build
89+
run: zig build -Doptimize=ReleaseSmall
9190

92-
dry-run-packaging:
93-
name: Dry Run Packaging
94-
runs-on: macos-latest
91+
unit-test-ports:
92+
name: Unit Test Ports
93+
continue-on-error: true
94+
runs-on: ${{ matrix.os }}
95+
strategy:
96+
matrix:
97+
os: [ubuntu-latest, windows-latest, macos-latest]
98+
port_dir: [gigadevice/gd32, raspberrypi/rp2xxx, stmicro/stm32]
9599
steps:
96100
- name: Checkout
97101
uses: actions/checkout@v4
98102
- name: Setup Zig
99103
uses: mlugg/setup-zig@v1
100104
with:
101105
version: ${{ env.ZIG_VERSION }}
102-
- name: Dry Run Packaging
103-
run: |
104-
MICROZIG_VERSION=$(zig build package -- get-version)
105-
echo microzig version: $MICROZIG_VERSION
106-
zig build package -- http://localhost:8000
107-
python3 -m http.server 8000 --directory boxzer-out &
108-
sleep 1
109-
110-
cd tools/package-test
111-
zig fetch --save=microzig http://localhost:8000/${MICROZIG_VERSION}/microzig.tar.gz
112-
zig build -Doptimize=ReleaseSmall
113-
114-
jobs -p | xargs kill
106+
- name: Unit Test Ports
107+
run: zig build test
108+
working-directory: port/${{ matrix.port_dir }}
115109

116110
build-examples:
117111
name: Build Examples
112+
continue-on-error: true
118113
runs-on: ubuntu-latest
119-
needs: build
120114
strategy:
121115
matrix:
122116
example_dir:
@@ -142,26 +136,44 @@ jobs:
142136
run: zig build -Doptimize=ReleaseSmall --summary all
143137
working-directory: examples/${{ matrix.example_dir }}
144138

145-
stm32-gen-check:
146-
name: Check that stm32 generated code is up to date
139+
140+
141+
build-website:
142+
name: Build Website
143+
continue-on-error: true
147144
runs-on: ubuntu-latest
148145
steps:
149-
- name: Checkout code
150-
uses: actions/checkout@v3
146+
- name: Checkout
147+
uses: actions/checkout@v4
151148
- name: Setup Zig
152149
uses: mlugg/setup-zig@v1
153150
with:
154151
version: ${{ env.ZIG_VERSION }}
155-
- name: Generate Code
156-
run: zig build -Dgenerate
157-
working-directory: port/stmicro/stm32
158-
- name: Check for code diffs
152+
- name: Build Website
153+
run: zig build
154+
working-directory: website
155+
156+
dry-run-packaging:
157+
name: Dry Run Packaging
158+
continue-on-error: true
159+
runs-on: macos-latest
160+
steps:
161+
- name: Checkout
162+
uses: actions/checkout@v4
163+
- name: Setup Zig
164+
uses: mlugg/setup-zig@v1
165+
with:
166+
version: ${{ env.ZIG_VERSION }}
167+
- name: Dry Run Packaging
159168
run: |
160-
if [[ $(git status --porcelain | grep -v '^??') ]]; then
161-
echo "Code differences detected:"
162-
git diff
163-
echo "Please commit or fix these changes to proceed."
164-
exit 1
165-
else
166-
echo "No code differences detected."
167-
fi
169+
MICROZIG_VERSION=$(zig build package -- get-version)
170+
echo microzig version: $MICROZIG_VERSION
171+
zig build package -- http://localhost:8000
172+
python3 -m http.server 8000 --directory boxzer-out &
173+
sleep 1
174+
175+
cd tools/package-test
176+
zig fetch --save=microzig http://localhost:8000/${MICROZIG_VERSION}/microzig.tar.gz
177+
zig build -Doptimize=ReleaseSmall
178+
179+
jobs -p | xargs kill

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ pub fn MicroBuild(port_select: PortSelect) type {
387387
.atdf, .svd => |file| blk: {
388388
const regz_run = b.addRunArtifact(regz_exe);
389389

390+
regz_run.addArg("--microzig");
390391
regz_run.addArg("--format");
391392
regz_run.addArg(@tagName(target.chip.register_definition));
392393

port/stmicro/stm32/src/generate.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ pub fn main() !void {
421421

422422
try db.backup("stm32.regz");
423423

424-
db.to_zig(out_file.writer()) catch |err| {
424+
db.to_zig(out_file.writer(), .{ .for_microzig = true }) catch |err| {
425425
std.log.err("Failed to write", .{});
426426
return err;
427427
};

tools/regz/src/Database.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,8 +2031,10 @@ pub fn apply_patch(db: *Database, ndjson: []const u8) !void {
20312031
}
20322032
}
20332033

2034-
pub fn to_zig(db: *Database, out_writer: anytype) !void {
2035-
try gen.to_zig(db, out_writer);
2034+
pub const ToZigOptions = gen.ToZigOptions;
2035+
2036+
pub fn to_zig(db: *Database, out_writer: anytype, opts: ToZigOptions) !void {
2037+
try gen.to_zig(db, out_writer, opts);
20362038
}
20372039

20382040
test "all" {

0 commit comments

Comments
 (0)