diff --git a/board-support/nordic-nrf5x/microzig-package.json b/board-support/nordic-nrf5x/microzig-package.json index 7be87c1..5697daa 100644 --- a/board-support/nordic-nrf5x/microzig-package.json +++ b/board-support/nordic-nrf5x/microzig-package.json @@ -1,4 +1,4 @@ { - "package_name": "nordic/nrf52", - "package_type": "board-support" -} + "package_name": "nordic/nrf5x", + "package_type": "board-support" +} \ No newline at end of file diff --git a/examples/nordic-nrf5x/build.zig b/examples/nordic-nrf5x/build.zig index 85a2b6f..8b200d1 100644 --- a/examples/nordic-nrf5x/build.zig +++ b/examples/nordic-nrf5x/build.zig @@ -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, }; diff --git a/examples/nordic-nrf5x/build.zig.zon b/examples/nordic-nrf5x/build.zig.zon deleted file mode 100644 index 2034409..0000000 --- a/examples/nordic-nrf5x/build.zig.zon +++ /dev/null @@ -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", - }, - }, -} diff --git a/examples/nordic-nrf5x/microzig-package.json b/examples/nordic-nrf5x/microzig-package.json new file mode 100644 index 0000000..a3c636e --- /dev/null +++ b/examples/nordic-nrf5x/microzig-package.json @@ -0,0 +1,7 @@ +{ + "package_name": "nordic/nrf5x", + "package_type": "example", + "inner_dependencies": [ + "nordic/nrf5x" + ] +} \ No newline at end of file diff --git a/examples/nxp-lpc/build.zig b/examples/nxp-lpc/build.zig index a6f0b30..b43360d 100644 --- a/examples/nxp-lpc/build.zig +++ b/examples/nxp-lpc/build.zig @@ -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, }; diff --git a/examples/nxp-lpc/build.zig.zon b/examples/nxp-lpc/build.zig.zon deleted file mode 100644 index aa5a11a..0000000 --- a/examples/nxp-lpc/build.zig.zon +++ /dev/null @@ -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", - }, - }, -} diff --git a/examples/nxp-lpc/microzig-package.json b/examples/nxp-lpc/microzig-package.json new file mode 100644 index 0000000..32638dd --- /dev/null +++ b/examples/nxp-lpc/microzig-package.json @@ -0,0 +1,7 @@ +{ + "package_name": "nxp/lpc", + "package_type": "example", + "inner_dependencies": [ + "nxp/lpc" + ] +} \ No newline at end of file diff --git a/tools/create-pkg-descriptor.zig b/tools/create-pkg-descriptor.zig index 13dd899..8b06253 100644 --- a/tools/create-pkg-descriptor.zig +++ b/tools/create-pkg-descriptor.zig @@ -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); +} diff --git a/tools/validate-all-examples.sh b/tools/validate-all-examples.sh index 494efb8..bf50cde 100755 --- a/tools/validate-all-examples.sh +++ b/tools/validate-all-examples.sh @@ -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 diff --git a/tools/validate-example.py b/tools/validate-example.py index 12dac7b..d04c8af 100755 --- a/tools/validate-example.py +++ b/tools/validate-example.py @@ -66,8 +66,6 @@ def main(): cwd=build_root, ) - # print(list(example_build_root.glob("*"))) - execute( "zig", "build",