Skip to content

Commit

Permalink
Merge pull request #18 from jmbaur/zig-0.12.0
Browse files Browse the repository at this point in the history
Migrate to zig 0.12
  • Loading branch information
jmbaur authored Apr 26, 2024
2 parents cff1435 + cd62787 commit 15554fa
Show file tree
Hide file tree
Showing 22 changed files with 490 additions and 352 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: build
on:
workflow_dispatch: # allows manual triggering
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Native build for x86_64-linux
run: nix build --print-build-logs .\#tinyboot
- name: Cross build for aarch64-linux
run: nix build --print-build-logs .\#pkgsCross.aarch64-multiplatform.tinyboot
- name: Check nix flake
run: nix flake check --print-build-logs
28 changes: 14 additions & 14 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@ const log = std.log;
const builtin = @import("builtin");

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

const coreboot_support = b.option(bool, "coreboot", "Support for coreboot integration") orelse true;
const tboot_loader_options = b.addOptions();
tboot_loader_options.addOption(bool, "coreboot_support", coreboot_support);

const target = b.standardTargetOptions(.{ .default_target = .{ .cpu_model = .baseline } });

const optimize = b.standardOptimizeOption(.{});

const tboot_loader_optimize = if (optimize == std.builtin.OptimizeMode.Debug)
std.builtin.OptimizeMode.Debug
else
// Always use release small, smallest size is our goal.
std.builtin.OptimizeMode.ReleaseSmall;

const linux_kexec_header_translated = b.addTranslateC(.{
.source_file = .{ .path = "src/linux.h" },
const linux_headers_translated = b.addTranslateC(.{
.root_source_file = .{ .path = "src/linux.h" },
.target = target,
.optimize = tboot_loader_optimize,
});

const linux_headers_module = linux_kexec_header_translated.createModule();
const linux_headers_module = linux_headers_translated.addModule("linux_headers");

const zbor_dep = b.dependency("zbor", .{
.target = target,
Expand All @@ -37,16 +36,16 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = tboot_loader_optimize,
});
tboot_loader.addModule("linux_headers", linux_headers_module);
tboot_loader.addModule("zbor", zbor_module);
tboot_loader.addOptions("build_options", tboot_loader_options);
tboot_loader.root_module.addImport("zbor", zbor_module);
tboot_loader.root_module.addOptions("build_options", tboot_loader_options);
tboot_loader.root_module.addImport("linux_headers", linux_headers_module);

// make the default step just compile tboot-loader
b.default_step = &tboot_loader.step;

// runs on builder
const cpio_tool = b.addRunArtifact(b.addExecutable(.{
.name = "cpio",
.target = b.host,
.root_source_file = .{ .path = "src/cpio/main.zig" },
}));
cpio_tool.addArtifactArg(tboot_loader);
Expand Down Expand Up @@ -88,22 +87,23 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
});
modem_tool.addModule("linux_headers", linux_headers_module);
modem_tool.root_module.addImport("linux_headers", linux_headers_module);
b.installArtifact(modem_tool);

const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/test.zig" },
.target = target,
.optimize = optimize,
});
unit_tests.addModule("linux_headers", linux_headers_module);
unit_tests.addOptions("build_options", tboot_loader_options);

unit_tests.root_module.addOptions("build_options", tboot_loader_options);
unit_tests.root_module.addImport("linux_headers", linux_headers_module);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&b.addRunArtifact(unit_tests).step);

const runner_tool = b.addRunArtifact(b.addExecutable(.{
.name = "tboot-runner",
.target = b.host,
.root_source_file = .{ .path = "src/runner.zig" },
}));
runner_tool.step.dependOn(&cpio_archive.step);
Expand Down
6 changes: 4 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
.name = "tinyboot",
.version = "0.0.1",

.paths = .{ "build.zig", "build.zig.zon", "src" },

.dependencies = .{
.zbor = .{
.url = "https://github.com/r4gus/zbor/archive/refs/tags/0.12.3.tar.gz",
.hash = "1220bbea0285a5d555320b00dde5ced378254c8be144d155d8f886ab4a4e9a855881",
.url = "https://github.com/r4gus/zbor/archive/refs/tags/0.13.1.tar.gz",
.hash = "122051750f4d7ecc9b705f1bbea1d431956306c74dafa4e9b625b11a34fab4c06933",
},
},
}
6 changes: 3 additions & 3 deletions deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

linkFarm "zig-packages" [
{
name = "1220bbea0285a5d555320b00dde5ced378254c8be144d155d8f886ab4a4e9a855881";
name = "122051750f4d7ecc9b705f1bbea1d431956306c74dafa4e9b625b11a34fab4c06933";
path = fetchzip {
url = "https://github.com/r4gus/zbor/archive/refs/tags/0.12.3.tar.gz";
hash = "sha256-q5UerAa9fvhCWv4wKUGUmdmEX9CGmxgQcE6VMB3QMhU=";
url = "https://github.com/r4gus/zbor/archive/refs/tags/0.13.1.tar.gz";
hash = "sha256-AMhdM20LA+NP4nJSvIPvr8N+Xk36C4WqUOc70PLYkWA=";
};
}
]
69 changes: 62 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 15554fa

Please sign in to comment.