diff --git a/.github/workflows/auto-pr.yml b/.github/workflows/auto-pr.yml deleted file mode 100644 index fc80d70..0000000 --- a/.github/workflows/auto-pr.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Downstream Updates -on: - workflow_dispatch: - push: - branches: - - main - -jobs: - update: - runs-on: ubuntu-latest - strategy: - matrix: - repo: [ - hardware-support-template, - espressif-esp, - gigadevice-gd32, - microchip-atmega, - nordic-nrf5x, - nxp-lpc, - raspberrypi-rp2040, - stmicro-stm32, - ] - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - repository: ZigEmbeddedGroup/${{ matrix.repo }} - submodules: recursive - fetch-depth: 0 - - - name: Update - id: update - run: | - cd deps/microzig - git pull origin main - echo "DESCRIPTION=$(git log -1 --pretty=%B | head -n 1)" >> $GITHUB_OUTPUT - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5.0.1 - with: - token: ${{ secrets.PR_TOKEN }} - branch: downstream/update-microzig - commit-message: update microzig - delete-branch: true - title: Update microzig - body: ${{ steps.update.outputs.DESCRIPTION }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f41ccca..90decfa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,7 @@ jobs: strategy: matrix: os: [ + linux-latest, windows-latest, macos-latest, ] diff --git a/build.zig b/build.zig index 55e2ac8..275882a 100644 --- a/build.zig +++ b/build.zig @@ -5,8 +5,9 @@ const std = @import("std"); const LibExeObjStep = std.build.LibExeObjStep; const Module = std.build.Module; -const FileSource = std.build.FileSource; -const Builder = std.Build; +const LazyPath = std.build.LazyPath; +const OptionsStep = std.build.OptionsStep; +const Build = std.Build; // alias for packages pub const LinkerScriptStep = @import("src/modules/LinkerScriptStep.zig"); @@ -45,7 +46,7 @@ pub const EmbeddedExecutable = struct { app_module.dependencies.put(name, module) catch @panic("OOM"); } - pub fn installArtifact(exe: *EmbeddedExecutable, b: *Builder) void { + pub fn installArtifact(exe: *EmbeddedExecutable, b: *Build) void { b.installArtifact(exe.inner); } @@ -61,7 +62,7 @@ pub const EmbeddedExecutable = struct { exe.inner.addCSourceFile(file, flags); } - pub fn addOptions(exe: *EmbeddedExecutable, module_name: []const u8, options: *std.build.OptionsStep) void { + pub fn addOptions(exe: *EmbeddedExecutable, module_name: []const u8, options: *OptionsStep) void { exe.inner.addOptions(module_name, options); const app_module = exe.inner.modules.get("app").?; const opt_module = exe.inner.modules.get(module_name).?; @@ -79,100 +80,56 @@ fn root_dir() []const u8 { pub const EmbeddedExecutableOptions = struct { name: []const u8, - source_file: std.build.FileSource, + source_file: LazyPath, backing: Backing, optimize: std.builtin.OptimizeMode = .Debug, - linkerscript_source_file: ?FileSource = null, + linkerscript_source_file: ?LazyPath = null, }; -pub fn addEmbeddedExecutable( - builder: *std.build.Builder, - opts: EmbeddedExecutableOptions, -) *EmbeddedExecutable { +pub fn addEmbeddedExecutable(b: *Build, opts: EmbeddedExecutableOptions) *EmbeddedExecutable { const has_board = (opts.backing == .board); const chip = switch (opts.backing) { - .chip => |c| c, - .board => |b| b.chip, + .chip => |chip| chip, + .board => |board| board.chip, }; const has_hal = chip.hal != null; - const config_file_name = blk: { - const hash = hash_blk: { - var hasher = std.hash.SipHash128(1, 2).init("abcdefhijklmnopq"); - - hasher.update(chip.name); - // TODO: this will likely crash for generated sources, need to - // properly hook this up to the build cache api - hasher.update(chip.source.getPath(builder)); - hasher.update(chip.cpu.name); - hasher.update(chip.cpu.source.getPath(builder)); - - if (opts.backing == .board) { - hasher.update(opts.backing.board.name); - // TODO: see above - hasher.update(opts.backing.board.source.getPath(builder)); - } - - var mac: [16]u8 = undefined; - hasher.final(&mac); - break :hash_blk mac; - }; - - const file_prefix = "zig-cache/microzig/config-"; - const file_suffix = ".zig"; - var ld_file_name: [file_prefix.len + 2 * hash.len + file_suffix.len]u8 = undefined; - const filename = std.fmt.bufPrint(&ld_file_name, "{s}{}{s}", .{ - file_prefix, - std.fmt.fmtSliceHexLower(&hash), - file_suffix, - }) catch unreachable; - - break :blk builder.dupe(filename); + // TODO: let the user override which ram section to use the stack on, + // for now just using the first ram section in the memory region list + const first_ram = blk: { + for (chip.memory_regions) |region| { + if (region.kind == .ram) + break :blk region; + } else @panic("no ram memory region found for setting the end-of-stack address"); }; - { - // TODO: let the user override which ram section to use the stack on, - // for now just using the first ram section in the memory region list - const first_ram = blk: { - for (chip.memory_regions) |region| { - if (region.kind == .ram) - break :blk region; - } else @panic("no ram memory region found for setting the end-of-stack address"); - }; - - std.fs.cwd().makeDir(std.fs.path.dirname(config_file_name).?) catch {}; - var config_file = std.fs.cwd().createFile(config_file_name, .{}) catch unreachable; - defer config_file.close(); - - var writer = config_file.writer(); + const config = b.addOptions(); + config.addOption(bool, "has_hal", has_hal); + config.addOption(bool, "has_board", has_board); + if (has_board) + config.addOption([]const u8, "board_name", opts.backing.board.name); - writer.print("pub const has_hal = {};\n", .{has_hal}) catch unreachable; - writer.print("pub const has_board = {};\n", .{has_board}) catch unreachable; - if (has_board) - writer.print("pub const board_name = \"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(opts.backing.board.name)}) catch unreachable; - - writer.print("pub const chip_name = \"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.name)}) catch unreachable; - writer.print("pub const cpu_name = \"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.cpu.name)}) catch unreachable; - writer.print("pub const end_of_stack = 0x{X:0>8};\n\n", .{first_ram.offset + first_ram.length}) catch unreachable; - } + config.addOption([]const u8, "chip_name", chip.name); + config.addOption([]const u8, "cpu_name", chip.name); + config.addOption(usize, "end_of_stack", first_ram.offset + first_ram.length); - const microzig_module = builder.createModule(.{ + const microzig_module = b.createModule(.{ .source_file = .{ .path = comptime std.fmt.comptimePrint("{s}/src/microzig.zig", .{root_dir()}) }, }); - microzig_module.dependencies.put("config", builder.createModule(.{ - .source_file = .{ .path = config_file_name }, + microzig_module.dependencies.put("config", b.createModule(.{ + .source_file = config.getSource(), })) catch unreachable; - microzig_module.dependencies.put("chip", builder.createModule(.{ + microzig_module.dependencies.put("chip", b.createModule(.{ .source_file = chip.source, .dependencies = &.{ .{ .name = "microzig", .module = microzig_module }, }, })) catch unreachable; - microzig_module.dependencies.put("cpu", builder.createModule(.{ + microzig_module.dependencies.put("cpu", b.createModule(.{ .source_file = chip.cpu.source, .dependencies = &.{ .{ .name = "microzig", .module = microzig_module }, @@ -180,7 +137,7 @@ pub fn addEmbeddedExecutable( })) catch unreachable; if (chip.hal) |hal_module_source| { - microzig_module.dependencies.put("hal", builder.createModule(.{ + microzig_module.dependencies.put("hal", b.createModule(.{ .source_file = hal_module_source, .dependencies = &.{ .{ .name = "microzig", .module = microzig_module }, @@ -190,7 +147,7 @@ pub fn addEmbeddedExecutable( switch (opts.backing) { .board => |board| { - microzig_module.dependencies.put("board", builder.createModule(.{ + microzig_module.dependencies.put("board", b.createModule(.{ .source_file = board.source, .dependencies = &.{ .{ .name = "microzig", .module = microzig_module }, @@ -200,16 +157,16 @@ pub fn addEmbeddedExecutable( else => {}, } - const app_module = builder.createModule(.{ + const app_module = b.createModule(.{ .source_file = opts.source_file, .dependencies = &.{ .{ .name = "microzig", .module = microzig_module }, }, }); - const exe = builder.allocator.create(EmbeddedExecutable) catch unreachable; + const exe = b.allocator.create(EmbeddedExecutable) catch unreachable; exe.* = EmbeddedExecutable{ - .inner = builder.addExecutable(.{ + .inner = b.addExecutable(.{ .name = opts.name, .root_source_file = .{ .path = comptime std.fmt.comptimePrint("{s}/src/start.zig", .{root_dir()}) }, .target = chip.cpu.target, @@ -228,7 +185,7 @@ pub fn addEmbeddedExecutable( if (opts.linkerscript_source_file) |linkerscript_source_file| { exe.inner.setLinkerScriptPath(linkerscript_source_file); } else { - const linkerscript = LinkerScriptStep.create(builder, chip) catch unreachable; + const linkerscript = LinkerScriptStep.create(b, chip) catch unreachable; exe.inner.setLinkerScriptPath(.{ .generated = &linkerscript.generated_file }); } @@ -242,7 +199,7 @@ pub fn addEmbeddedExecutable( } /// This build script validates usage patterns we expect from MicroZig -pub fn build(b: *std.build.Builder) !void { +pub fn build(b: *Build) !void { const backings = @import("test/backings.zig"); const optimize = b.standardOptimizeOption(.{}); diff --git a/docs/tricks.adoc b/docs/tricks.adoc index 11055a9..6eda21f 100644 --- a/docs/tricks.adoc +++ b/docs/tricks.adoc @@ -1,14 +1,3 @@ = Tips and Tricks This document has some `build.zig` tricks for other pages to reference. - -== Packaging and Paths - -TODO - -[source,zig] ----- -fn root_dir() []const u8 { - return std.fs.path.dirname(@src().file) orelse unreachable; -} ----- diff --git a/src/modules/Board.zig b/src/modules/Board.zig index eb114bf..8e09b4a 100644 --- a/src/modules/Board.zig +++ b/src/modules/Board.zig @@ -2,5 +2,5 @@ const std = @import("std"); const Chip = @import("Chip.zig"); name: []const u8, -source: std.build.FileSource, +source: std.build.LazyPath, chip: Chip, diff --git a/src/modules/Chip.zig b/src/modules/Chip.zig index b26aecd..3676fc9 100644 --- a/src/modules/Chip.zig +++ b/src/modules/Chip.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const FileSource = std.build.FileSource; +const LazyPath = std.build.LazyPath; const MemoryRegion = @import("MemoryRegion.zig"); const Cpu = @import("Cpu.zig"); @@ -7,10 +7,10 @@ const Cpu = @import("Cpu.zig"); const Chip = @This(); name: []const u8, -source: FileSource, +source: LazyPath, cpu: Cpu, -hal: ?FileSource = null, -json_register_schema: ?FileSource = null, +hal: ?LazyPath = null, +json_register_schema: ?LazyPath = null, memory_regions: []const MemoryRegion, pub fn from_standard_paths(comptime root_dir: []const u8, args: struct { diff --git a/src/modules/Cpu.zig b/src/modules/Cpu.zig index 4f9bcb9..e4cd307 100644 --- a/src/modules/Cpu.zig +++ b/src/modules/Cpu.zig @@ -1,5 +1,5 @@ const std = @import("std"); name: []const u8, -source: std.build.FileSource, +source: std.build.LazyPath, target: std.zig.CrossTarget,