Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const port_list: []const struct {
};

pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const generate_linker_script_mod = b.createModule(.{
Expand All @@ -56,6 +57,65 @@ pub fn build(b: *Build) void {
);

b.installArtifact(generate_linker_script_exe);

pass_through_module(b, "drivers", b.dependency(
"drivers",
.{},
).module("drivers"));

pass_through_module(b, "bounded-array", b.dependency(
"modules/bounded-array",
.{},
).module("bounded-array"));

// const libc_single_threaded = b.option(bool, "libc_single_threaded", "Create a single-threaded libc implementation (default: false)");
// pass_through_module(b, "foundation-libc", b.dependency(
// "modules/foundation-libc",
// .{ .target = target, .optimize = optimize, .single_threaded = libc_single_threaded },
// ).module("")); // Library, not module

const freertos_port_name = b.option(
@import("modules/freertos").FreeRTOS_Port,
"freertos_port",
"FreeRTOS port to use",
);
const freertos_idle_hook = b.option(bool, "freertos_idle_hook", "Enable");
const freertos_tick_hook = b.option(bool, "freertos_tick_hook", "Enable FreeRTOS tick hook");
pass_through_module(b, "freertos", b.dependency(
"modules/freertos",
.{
.target = target,
.optimize = optimize,
.port_name = freertos_port_name,
.cfg_idle_hook = freertos_idle_hook,
.cfg_tick_hook = freertos_tick_hook,
},
).module("freertos"));

// pass_through_module(b, "lwip", b.dependency(
// "modules/lwip",
// .{ .target = target, .optimize = optimize },
// ).module("")); // Library, not module

pass_through_module(b, "net", b.dependency(
"modules/network",
.{ .target = target, .optimize = optimize },
).module("net"));

pass_through_module(b, "riscv32-common", b.dependency(
"modules/riscv32-common",
.{ .target = target, .optimize = optimize },
).module("riscv32-common"));

pass_through_module(b, "rtt", b.dependency(
"modules/rtt",
.{ .target = target, .optimize = optimize },
).module("rtt"));

pass_through_module(b, "virtual-io", b.dependency(
"modules/virtual-io",
.{ .target = target, .optimize = optimize },
).module("virtual-io"));
}

pub const PortSelect = struct {
Expand Down Expand Up @@ -822,3 +882,17 @@ inline fn custom_find_import_pkg_hash_or_fatal(comptime dep_name: []const u8) []

@panic("dependency not found");
}

fn pass_through_module(b: *std.Build, name: []const u8, module: *std.Build.Module) void {
const gop = b.modules.getOrPutValue(
b.graph.arena,
b.graph.dupeString(name),
module,
) catch @panic("OOM");
if (gop.found_existing) {
std.debug.panic(
"A module with the name '{s}' has already been added to the package.",
.{name},
);
}
}
4 changes: 3 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
.@"tools/flags" = .{ .path = "tools/flags" },

// modules
.@"modules/bounded-array" = .{ .path = "modules/bounded-array" },
.@"modules/foundation-libc" = .{ .path = "modules/foundation-libc" },
//.@"modules/freertos" = .{ .path = "modules/freertos" },
.@"modules/freertos" = .{ .path = "modules/freertos" },
.@"modules/lwip" = .{ .path = "modules/lwip" },
.@"modules/network" = .{ .path = "modules/network" },
.@"modules/riscv32-common" = .{ .path = "modules/riscv32-common" },
.@"modules/rtt" = .{ .path = "modules/rtt" },
.@"modules/virtual-io" = .{ .path = "modules/virtual-io" },

// simulators
.@"sim/aviron" = .{ .path = "sim/aviron", .lazy = true },
Expand Down
2 changes: 1 addition & 1 deletion modules/freertos/build.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const Translator = @import("translate_c").Translator;

const FreeRTOS_Port = enum {
pub const FreeRTOS_Port = enum {
RP2040,
RP2350_ARM,
RP2350_RISCV,
Expand Down
Loading