Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catchup to changes introduced by ziglang/zig#14498 #101

Merged
merged 9 commits into from
Feb 6, 2023
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
version: master

- name: Build tests
run: zig build -Drelease-small
run: zig build -Doptimize=ReleaseSmall
8 changes: 5 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const chips = microzig.chips;
const Backing = microzig.Backing;

pub fn build(b: *std.build.Builder) !void {
const mode = b.standardReleaseOptions();
// Standard optimization options allow the person running `zig build -Doptimize=...` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

const test_step = b.step("test", "Builds and runs the library test suite");

Expand Down Expand Up @@ -52,11 +55,10 @@ pub fn build(b: *std.build.Builder) !void {
b.fmt("test-{s}-{s}.elf", .{ tst.name, cfg.name }),
tst.source,
cfg.backing,
.{},
.{.optimize = optimize },
);

if (filter == null or exe.inner.target.cpu_arch.? == filter.?) {
exe.inner.setBuildMode(mode);
exe.inner.install();

test_step.dependOn(&exe.inner.step);
Expand Down
8 changes: 2 additions & 6 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub const BuildOptions = struct {
// a hal package is a package with ergonomic wrappers for registers for a
// given mcu, it's only dependency can be microzig
hal_package_path: ?std.build.FileSource = null,
optimize: std.builtin.OptimizeMode = std.builtin.OptimizeMode.Debug,
};

pub const EmbeddedExecutable = struct {
Expand All @@ -56,10 +57,6 @@ pub const EmbeddedExecutable = struct {
});
}

pub fn setBuildMode(exe: *EmbeddedExecutable, mode: std.builtin.Mode) void {
exe.inner.setBuildMode(mode);
}

pub fn install(exe: *EmbeddedExecutable) void {
exe.inner.install();
}
Expand Down Expand Up @@ -177,7 +174,7 @@ pub fn addEmbeddedExecutable(
};

var exe = EmbeddedExecutable{
.inner = builder.addExecutable(name, root_path ++ "core/microzig.zig"),
.inner = builder.addExecutable(.{ .name = name, .root_source_file = .{ .path = root_path ++ "core/microzig.zig" }, .target = chip.cpu.target, .optimize = options.optimize }),
.app_packages = std.ArrayList(Pkg).init(builder.allocator),
};

Expand All @@ -186,7 +183,6 @@ pub fn addEmbeddedExecutable(
// might not be true for all machines (Pi Pico), but
// for the HAL it's true (it doesn't know the concept of threading)
exe.inner.single_threaded = true;
exe.inner.setTarget(chip.cpu.target);

const linkerscript = LinkerScriptStep.create(builder, chip) catch unreachable;
exe.inner.setLinkerScriptPath(.{ .generated = &linkerscript.generated_file });
Expand Down