Makes nxp/lpc and nordic/nrf5x examples, fixes bug in build.zig.zon generation

wch-ch32v003
Felix "xq" Queißner 8 months ago
parent 7a33e6fd55
commit 71e60e3c44

@ -1,4 +1,4 @@
{
"package_name": "nordic/nrf52",
"package_name": "nordic/nrf5x",
"package_type": "board-support"
}

@ -1,15 +1,20 @@
const std = @import("std");
const nrf5x = @import("nrf5x");
const MicroZig = @import("microzig-build");
const available_examples = [_]Example{
.{ .name = "nrf52480-dongle_blinky", .target = nrf5x.boards.nordic.nRF52840_Dongle, .file = "src/blinky.zig" },
.{ .target = "board:nordic/nRF52840_Dongle", .name = "nrf52480-dongle_blinky", .file = "src/blinky.zig" },
};
pub fn build(b: *std.Build) void {
const microzig = @import("microzig").init(b, "microzig");
const microzig = MicroZig.createBuildEnvironment(b, .{});
const optimize = b.standardOptimizeOption(.{});
const show_targets_step = b.step("show-targets", "Shows all available MicroZig targets");
show_targets_step.dependOn(microzig.getShowTargetsStep());
for (available_examples) |example| {
const target = microzig.findTarget(example.target).?;
// `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`.
//
@ -17,7 +22,7 @@ pub fn build(b: *std.Build) void {
// cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{
.name = example.name,
.target = example.target,
.target = target,
.optimize = optimize,
.source_file = .{ .path = example.file },
});
@ -34,7 +39,7 @@ pub fn build(b: *std.Build) void {
}
const Example = struct {
target: @import("microzig").Target,
target: []const u8,
name: []const u8,
file: []const u8,
};

@ -1,14 +0,0 @@
.{
.name = "microzig-nordic-nrf5x-examples",
.version = "0.1.0",
.dependencies = .{
.microzig = .{
.url = "https://github.com/ZigEmbeddedGroup/microzig/archive/c6c9ec4516f57638e751141085c9d76120990312.tar.gz",
.hash = "1220af58bdaa721b8189f3a7adfda660517dd354463463388e96d69fe4ceccf80b92",
},
.nrf5x = .{
.url = "https://github.com/ZigEmbeddedGroup/nordic-nrf5x/archive/0ab136860ccf7eb1d07969c3ef523f3cd898e2ff.tar.gz",
.hash = "1220980da06f9634dcff06afefa7aa111bd030018fea49f79e86657dab69621e1d08",
},
},
}

@ -0,0 +1,7 @@
{
"package_name": "nordic/nrf5x",
"package_type": "example",
"inner_dependencies": [
"nordic/nrf5x"
]
}

@ -1,15 +1,20 @@
const std = @import("std");
const lpc = @import("lpc");
const MicroZig = @import("microzig-build");
const available_examples = [_]ExampleDesc{
.{ .name = "mbed-lpc1768_blinky", .target = lpc.boards.mbed.lpc1768, .file = "src/blinky.zig" },
.{ .target = "board:mbed/lpc1768", .name = "mbed-lpc1768_blinky", .file = "src/blinky.zig" },
};
pub fn build(b: *std.Build) void {
const microzig = @import("microzig").init(b, "microzig");
const microzig = MicroZig.createBuildEnvironment(b, .{});
const optimize = b.standardOptimizeOption(.{});
const show_targets_step = b.step("show-targets", "Shows all available MicroZig targets");
show_targets_step.dependOn(microzig.getShowTargetsStep());
for (available_examples) |example| {
const target = microzig.findTarget(example.target).?;
// `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`.
//
@ -17,7 +22,7 @@ pub fn build(b: *std.Build) void {
// cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{
.name = example.name,
.target = example.target,
.target = target,
.optimize = optimize,
.source_file = .{ .path = example.file },
});
@ -34,7 +39,7 @@ pub fn build(b: *std.Build) void {
}
const ExampleDesc = struct {
target: @import("microzig").Target,
target: []const u8,
name: []const u8,
file: []const u8,
};

@ -1,14 +0,0 @@
.{
.name = "microzig-nxp-lpc-examples",
.version = "0.1.0",
.dependencies = .{
.microzig = .{
.url = "https://github.com/ZigEmbeddedGroup/microzig/archive/c6c9ec4516f57638e751141085c9d76120990312.tar.gz",
.hash = "1220af58bdaa721b8189f3a7adfda660517dd354463463388e96d69fe4ceccf80b92",
},
.lpc = .{
.url = "https://github.com/ZigEmbeddedGroup/nxp-lpc/archive/130a1316c0892415e7da958a5e9548ed87bba54d.tar.gz",
.hash = "1220165879f85a1d51656d35b3963a95f3585dc665fc7414f76aa6aad4e6635536cf",
},
},
}

@ -0,0 +1,7 @@
{
"package_name": "nxp/lpc",
"package_type": "example",
"inner_dependencies": [
"nxp/lpc"
]
}

@ -34,18 +34,21 @@ const Timestamp = struct {
};
const MetaData = struct {
const Type = enum {
@"board-support",
core,
build,
example,
const Type = enum(u32) {
// we "abuse" the enum value here to map our keys to a priority mapping:
// Zig 0.11 must have dependencies with inner dependencies in the right order,
// otherwise the build system won't find the dependencies:
build = 0, // must always be first
core = 300,
@"board-support" = 500,
example = 900,
};
package_name: []const u8,
package_type: Type,
version: []const u8,
inner_dependencies: []const []const u8 = &.{},
inner_dependencies: [][]const u8 = &.{},
external_dependencies: std.json.Value = .null,
archive: ?Archive = null,
@ -122,6 +125,8 @@ pub fn main() !void {
}
}
std.sort.block([]const u8, package.inner_dependencies, all_packages, orderPackagesByPriority);
// Add all other dependencies:
for (package.inner_dependencies) |dep_name| {
const dep = findPackage(all_packages, dep_name).?;
@ -140,3 +145,18 @@ pub fn main() !void {
try buffered_stdout.flush();
}
fn orderPackagesByPriority(mt: []MetaData, lhs_name: []const u8, rhs_name: []const u8) bool {
const rhs = findPackage(mt, rhs_name).?;
const lhs = findPackage(mt, lhs_name).?;
const rhs_prio = @intFromEnum(rhs.package_type);
const lhs_prio = @intFromEnum(lhs.package_type);
if (lhs_prio < rhs_prio)
return true;
if (lhs_prio > rhs_prio)
return false;
return std.ascii.lessThanIgnoreCase(lhs_name, rhs_name);
}

@ -9,3 +9,4 @@ mkdir -p "${tmpdir}"
"${root}/validate-example.py" --build-root "${tmpdir}" --example raspberrypi/rp2040
"${root}/validate-example.py" --build-root "${tmpdir}" --example stmicro/stm32
"${root}/validate-example.py" --build-root "${tmpdir}" --example nxp/lpc

@ -66,8 +66,6 @@ def main():
cwd=build_root,
)
# print(list(example_build_root.glob("*")))
execute(
"zig",
"build",

Loading…
Cancel
Save