Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Feb 26, 2024
1 parent b519ca2 commit 3b9c542
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
5 changes: 0 additions & 5 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
.name = "microzig",
.version = "0.0.0",
.dependencies = .{
.eggzon = .{
.url = "https://github.com/mattnite/eggzon/archive/8b3ecf9664d2a74d703a45b5162901bb9fa45727.tar.gz",
.hash = "1220b22d0a9ac853ca8b40e51e44ca1868d5592d982bb4d6b5498ab0027ed5bc4ee5",
},

// packages within the monorepo so that others can reach them
.@"microzig/build" = .{ .path = "build" },
.@"microzig/core" = .{ .path = "core" },
Expand Down
34 changes: 16 additions & 18 deletions build/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn build(b: *Build) !void {

/// Creates a new MicroZig build environment that can be used to create new firmware.
pub fn init(b: *Build, opts: struct {
dependency_name: []const u8 = "microzig",
dependency_name: []const u8 = "microzig/build",
}) *MicroZig {
const mz_dep = b.dependency(opts.dependency_name, .{});
const core_dep = mz_dep.builder.dependency("microzig/core", .{});
Expand Down Expand Up @@ -150,15 +150,15 @@ pub fn add_firmware(
.{ .name = "microzig", .module = fw.modules.microzig },
},
});
fw.modules.microzig.dependencies.put("chip", fw.modules.chip) catch @panic("out of memory");
fw.modules.microzig.addImport("chip", fw.modules.chip);

fw.modules.cpu = micro_build.createModule(.{
.root_source_file = chip.cpu.source_file,
.imports = &.{
.{ .name = "microzig", .module = fw.modules.microzig },
},
});
fw.modules.microzig.dependencies.put("cpu", fw.modules.cpu) catch @panic("out of memory");
fw.modules.microzig.addImport("cpu", fw.modules.cpu);

if (maybe_hal) |hal| {
fw.modules.hal = micro_build.createModule(.{
Expand All @@ -167,7 +167,7 @@ pub fn add_firmware(
.{ .name = "microzig", .module = fw.modules.microzig },
},
});
fw.modules.microzig.dependencies.put("hal", fw.modules.hal.?) catch @panic("out of memory");
fw.modules.microzig.addImport("hal", fw.modules.hal.?);
}

if (maybe_board) |brd| {
Expand All @@ -177,7 +177,7 @@ pub fn add_firmware(
.{ .name = "microzig", .module = fw.modules.microzig },
},
});
fw.modules.microzig.dependencies.put("board", fw.modules.board.?) catch @panic("out of memory");
fw.modules.microzig.addImport("board", fw.modules.board.?);
}

fw.modules.app = host_build.createModule(.{
Expand All @@ -188,26 +188,24 @@ pub fn add_firmware(
});

const umm = mz.microzig_core.builder.dependency("umm-zig", .{}).module("umm");
fw.modules.microzig.dependencies.put("umm", umm) catch @panic("out of memory");
fw.modules.microzig.addImport("umm", umm);

fw.artifact.addModule("app", fw.modules.app);
fw.artifact.addModule("microzig", fw.modules.microzig);
fw.artifact.root_module.addImport("app", fw.modules.app);
fw.artifact.root_module.addImport("microzig", fw.modules.microzig);

fw.artifact.strip = false; // we always want debug symbols, stripping brings us no benefit on embedded
fw.artifact.single_threaded = options.single_threaded orelse fw.target.single_threaded;
fw.artifact.bundle_compiler_rt = options.bundle_compiler_rt orelse fw.target.bundle_compiler_rt;

if (linker_script) |ls| {
fw.artifact.setLinkerScriptPath(ls);
} else {
// If not specified then generate the linker script
fw.artifact.setLinkerScript(
mz.generateLinkerScript(chip.*) catch @panic("out of memory"),
mz.generate_linkerscript(chip.*) catch @panic("out of memory"),
);
}

if (options.target.configure) |configure| {
configure(fw.env, fw);
configure(fw.mz, fw);
}

return fw;
Expand Down Expand Up @@ -258,10 +256,10 @@ fn dependency(env: *MicroZig, name: []const u8, args: anytype) *Build.Dependency
return env.self.builder.dependency(name, args);
}

fn generate_linkerscript(env: *MicroZig, chip: Chip) !Build.LazyPath {
const cpu = env.getCpuDescriptor(chip.cpu);
fn generate_linkerscript(mz: *MicroZig, chip: Chip) !Build.LazyPath {
const target = mz.host_build.resolveTargetQuery(chip.cpu.target);

var contents = std.ArrayList(u8).init(env.host_build.allocator);
var contents = std.ArrayList(u8).init(mz.host_build.allocator);
const writer = contents.writer();
try writer.print(
\\/*
Expand All @@ -278,7 +276,7 @@ fn generate_linkerscript(env: *MicroZig, chip: Chip) !Build.LazyPath {
\\
\\
, .{
.cpu = cpu.name,
.cpu = target.result.cpu.model.name,
.chip = chip.name,
});

Expand Down Expand Up @@ -340,7 +338,7 @@ fn generate_linkerscript(env: *MicroZig, chip: Chip) !Build.LazyPath {
\\
);

switch (cpu.target.getCpuArch()) {
switch (target.result.cpu.arch) {
.arm, .thumb => try writer.writeAll(
\\ .ARM.exidx : {
\\ *(.ARM.exidx* .gnu.linkonce.armexidx.*)
Expand Down Expand Up @@ -380,7 +378,7 @@ fn generate_linkerscript(env: *MicroZig, chip: Chip) !Build.LazyPath {
// \\
// );

const write = env.host_build.addWriteFiles();
const write = mz.host_build.addWriteFiles();

return write.add("linker.ld", contents.items);
}
Expand Down

0 comments on commit 3b9c542

Please sign in to comment.