Skip to content

Commit e94cce5

Browse files
committed
Merge branch 'main' into zig-master
2 parents f7db2b9 + db7ba2c commit e94cce5

194 files changed

Lines changed: 25296 additions & 5424 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ jobs:
170170
strategy:
171171
matrix:
172172
os: [ubuntu-latest, windows-latest, macos-latest]
173-
port_dir:
174-
[gigadevice/gd32, raspberrypi/rp2xxx, stmicro/stm32, wch/ch32v]
173+
port_dir: [gigadevice/gd32, espressif/esp, raspberrypi/rp2xxx, stmicro/stm32, wch/ch32v]
175174
steps:
176175
- name: Checkout
177176
uses: actions/checkout@v4

.github/workflows/lint.yml

Lines changed: 175 additions & 215 deletions
Large diffs are not rendered by default.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: CI / Unused Imports Check
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
check-unused-imports:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
steps:
16+
- name: Checkout PR code
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup Zig
22+
uses: mlugg/setup-zig@v2
23+
with:
24+
version: 0.15.1
25+
26+
- name: Build zigimports
27+
run: |
28+
git clone --depth 1 https://github.com/tusharsadhwani/zigimports.git /tmp/zigimports
29+
cd /tmp/zigimports
30+
zig build --release=safe
31+
# Binary is named zigimports-<arch>-<os>, find and symlink it
32+
ln -s /tmp/zigimports/zig-out/bin/zigimports-* /tmp/zigimports/zig-out/bin/zigimports
33+
34+
- name: Get changed Zig files
35+
id: changed-files
36+
run: |
37+
FILES=$(git diff --name-only --diff-filter=d ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '\.zig$' || true)
38+
echo "files<<EOF" >> $GITHUB_OUTPUT
39+
echo "$FILES" >> $GITHUB_OUTPUT
40+
echo "EOF" >> $GITHUB_OUTPUT
41+
42+
- name: Check for unused imports
43+
id: check
44+
run: |
45+
RESULTS=""
46+
echo "${{ steps.changed-files.outputs.files }}" | while read file; do
47+
if [ -n "$file" ] && [ -f "$file" ]; then
48+
/tmp/zigimports/zig-out/bin/zigimports "$file" 2>&1 || true
49+
fi
50+
done | tee unused_imports.txt
51+
52+
# Set output for later steps
53+
if grep -q "is unused" unused_imports.txt 2>/dev/null; then
54+
echo "has_issues=true" >> $GITHUB_OUTPUT
55+
else
56+
echo "has_issues=false" >> $GITHUB_OUTPUT
57+
fi
58+
59+
- name: Post PR comment
60+
if: steps.check.outputs.has_issues == 'true'
61+
uses: actions/github-script@v7
62+
with:
63+
script: |
64+
const fs = require('fs');
65+
66+
const content = fs.readFileSync('unused_imports.txt', 'utf8').trim();
67+
const lines = content.split('\n').filter(l => l.includes('is unused'));
68+
69+
if (lines.length === 0) return;
70+
71+
// Check for existing comment and update it
72+
const marker = '<!-- unused-imports-check -->';
73+
const comments = await github.paginate(
74+
github.rest.issues.listComments,
75+
{
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
issue_number: context.issue.number
79+
}
80+
);
81+
82+
const existing = comments.find(c =>
83+
c.user.login === 'github-actions[bot]' &&
84+
c.body.includes(marker)
85+
);
86+
87+
let body = '## ⚠️ Unused Imports Found\n\n';
88+
body += '```\n' + lines.join('\n') + '\n```\n\n';
89+
body += 'Run `zigimports --fix <file>` locally to automatically remove unused imports.\n\n';
90+
body += marker;
91+
92+
if (existing) {
93+
await github.rest.issues.updateComment({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
comment_id: existing.id,
97+
body: body
98+
});
99+
} else {
100+
await github.rest.issues.createComment({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
issue_number: context.issue.number,
104+
body: body
105+
});
106+
}
107+
108+
- name: Remove comment if no issues
109+
if: steps.check.outputs.has_issues == 'false'
110+
uses: actions/github-script@v7
111+
with:
112+
script: |
113+
const marker = '<!-- unused-imports-check -->';
114+
const comments = await github.paginate(
115+
github.rest.issues.listComments,
116+
{
117+
owner: context.repo.owner,
118+
repo: context.repo.repo,
119+
issue_number: context.issue.number
120+
}
121+
);
122+
123+
const existing = comments.find(c =>
124+
c.user.login === 'github-actions[bot]' &&
125+
c.body.includes(marker)
126+
);
127+
128+
if (existing) {
129+
await github.rest.issues.deleteComment({
130+
owner: context.repo.owner,
131+
repo: context.repo.repo,
132+
comment_id: existing.id
133+
});
134+
}

build-internals/build.zig

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub const Patch = regz.patch.Patch;
88
const uf2 = @import("uf2");
99
pub const FamilyId = uf2.FamilyId;
1010
const esp_image = @import("esp-image");
11+
const dfu = @import("dfu");
1112

1213
pub fn build(b: *Build) void {
1314
_ = b.addModule("build-internals", .{
@@ -100,23 +101,13 @@ pub const Target = struct {
100101
from.chip.copy(allocator);
101102

102103
const ret = from.dep.builder.allocator.create(Target) catch @panic("out of memory");
103-
ret.* = .{
104-
.dep = from.dep,
105-
.preferred_binary_format = options.preferred_binary_format orelse from.preferred_binary_format,
106-
.zig_target = options.zig_target orelse from.zig_target,
107-
.cpu = options.cpu orelse from.cpu,
108-
.chip = chip,
109-
.single_threaded = options.single_threaded orelse from.single_threaded,
110-
.bundle_compiler_rt = options.bundle_compiler_rt orelse from.bundle_compiler_rt,
111-
.bundle_ubsan_rt = options.bundle_ubsan_rt orelse from.bundle_ubsan_rt,
112-
.ram_image = options.ram_image orelse from.ram_image,
113-
.hal = options.hal orelse from.hal,
114-
.board = options.board orelse from.board,
115-
.linker_script = options.linker_script orelse from.linker_script,
116-
.stack = options.stack orelse from.stack,
117-
.entry = options.entry orelse from.entry,
118-
.patch_elf = options.patch_elf orelse from.patch_elf,
119-
};
104+
ret.* = from.*;
105+
106+
inline for (std.meta.fields(DeriveOptions)) |field| {
107+
const value = @field(options, field.name);
108+
if (value) |val| @field(ret, field.name) = val;
109+
}
110+
ret.chip = chip;
120111
return ret;
121112
}
122113
};
@@ -152,8 +143,11 @@ pub const Chip = struct {
152143
/// Use the provided file directly as the chip file.
153144
zig: LazyPath,
154145

155-
/// Path to embassy stm32-data directory
156-
embassy: LazyPath,
146+
/// Path to embassy stm32-data directory with optional device filter
147+
embassy: struct {
148+
path: LazyPath,
149+
device: ?[]const u8 = null,
150+
},
157151

158152
/// Single device from TI targetdb
159153
targetdb: struct {
@@ -223,7 +217,8 @@ pub const BinaryFormat = union(enum) {
223217
hex,
224218

225219
/// A [Device Firmware Upgrade](https://www.usb.org/sites/default/files/DFU_1.1.pdf) file.
226-
dfu,
220+
/// ST MicroElectronics [DfuSe](https://rc.fdr.hu/UM0391.pdf) format is also supported.
221+
dfu: dfu.Options,
227222

228223
/// The [USB Flashing Format (UF2)](https://github.com/microsoft/uf2) designed by Microsoft.
229224
uf2: uf2.Options,

build-internals/build.zig.zon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.regz = .{ .path = "../tools/regz" },
77
.uf2 = .{ .path = "../tools/uf2" },
88
.@"esp-image" = .{ .path = "../tools/esp-image" },
9+
.dfu = .{ .path = "../tools/dfu" },
910
},
1011
.paths = .{
1112
"build.zig",

build.zig

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const port_list: []const struct {
3333
.{ .name = "stm32", .dep_name = "port/stmicro/stm32" },
3434
.{ .name = "ch32v", .dep_name = "port/wch/ch32v" },
3535
.{ .name = "msp430", .dep_name = "port/texasinstruments/msp430" },
36+
.{ .name = "tm4c", .dep_name = "port/texasinstruments/tm4c" },
3637
};
3738

3839
const exe_targets: []const std.Target.Query = &.{
@@ -87,6 +88,7 @@ pub const PortSelect = struct {
8788
stm32: bool = false,
8889
ch32v: bool = false,
8990
msp430: bool = false,
91+
tm4c: bool = false,
9092

9193
pub const all: PortSelect = blk: {
9294
var ret: PortSelect = undefined;
@@ -421,7 +423,7 @@ pub fn MicroBuild(port_select: PortSelect) type {
421423
regz_run.addFileArg(file);
422424
break :blk chips_dir.path(b, b.fmt("{s}.zig", .{target.chip.name}));
423425
},
424-
.embassy => |path| blk: {
426+
.embassy => |embassy| blk: {
425427
const regz_run = b.addRunArtifact(regz_exe);
426428

427429
regz_run.addArg("--format");
@@ -435,7 +437,12 @@ pub fn MicroBuild(port_select: PortSelect) type {
435437
regz_run.addFileArg(patch_file);
436438
}
437439

438-
regz_run.addDirectoryArg(path);
440+
if (embassy.device) |device| {
441+
regz_run.addArg("--device");
442+
regz_run.addArg(device);
443+
}
444+
445+
regz_run.addDirectoryArg(embassy.path);
439446
break :blk chips_dir.path(b, b.fmt("{s}.zig", .{target.chip.name}));
440447
},
441448
.targetdb => |targetdb| blk: {
@@ -679,7 +686,13 @@ pub fn MicroBuild(port_select: PortSelect) type {
679686
options,
680687
),
681688

682-
.dfu => @panic("DFU is not implemented yet. See https://github.com/ZigEmbeddedGroup/microzig/issues/145 for more details!"),
689+
.dfu => |options| @import("tools/dfu").from_elf(
690+
fw.mb.dep.builder.dependency("tools/dfu", .{
691+
.optimize = .ReleaseSafe,
692+
}),
693+
elf_file,
694+
options,
695+
),
683696

684697
.esp => |options| @import("tools/esp-image").from_elf(
685698
fw.mb.dep.builder.dependency("tools/esp-image", .{

build.zig.zon

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22
.name = .microzig,
33
// Note: This should be changed if you fork microzig!
44
.fingerprint = 0x605a83a849186d0f,
5-
.version = "0.15.0",
5+
.version = "0.15.2",
66
.minimum_zig_version = "0.15.1",
77
.dependencies = .{
88
.@"build-internals" = .{ .path = "build-internals" },
99
.core = .{ .path = "core" },
1010
.drivers = .{ .path = "drivers" },
1111

1212
// tools
13+
.@"tools/esp-image" = .{ .path = "tools/esp-image" },
14+
.@"tools/printer" = .{ .path = "tools/printer" },
1315
.@"tools/regz" = .{ .path = "tools/regz" },
1416
.@"tools/uf2" = .{ .path = "tools/uf2" },
15-
.@"tools/esp-image" = .{ .path = "tools/esp-image" },
17+
.@"tools/dfu" = .{ .path = "tools/dfu" },
1618

1719
// modules
1820
.@"modules/foundation-libc" = .{ .path = "modules/foundation-libc" },
21+
.@"modules/freertos" = .{ .path = "modules/freertos" },
22+
.@"modules/lwip" = .{ .path = "modules/lwip" },
23+
.@"modules/network" = .{ .path = "modules/network" },
1924
.@"modules/riscv32-common" = .{ .path = "modules/riscv32-common" },
2025
.@"modules/rtt" = .{ .path = "modules/rtt" },
2126

@@ -33,6 +38,7 @@
3338
.@"port/raspberrypi/rp2xxx" = .{ .path = "port/raspberrypi/rp2xxx", .lazy = true },
3439
.@"port/stmicro/stm32" = .{ .path = "port/stmicro/stm32", .lazy = true },
3540
.@"port/texasinstruments/msp430" = .{ .path = "port/texasinstruments/msp430", .lazy = true },
41+
.@"port/texasinstruments/tm4c" = .{ .path = "port/texasinstruments/tm4c", .lazy = true },
3642
.@"port/wch/ch32v" = .{ .path = "port/wch/ch32v", .lazy = true },
3743

3844
// used for creating package tarballs

core/build.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ pub fn build(b: *std.Build) !void {
1818

1919
const run_unit_tests = b.addRunArtifact(unit_tests);
2020

21-
b.getInstallStep().dependOn(&run_unit_tests.step);
21+
const test_step = b.step("test", "Run unit tests");
22+
test_step.dependOn(&run_unit_tests.step);
2223
}

0 commit comments

Comments
 (0)