Created
February 4, 2023 21:42
-
-
Save andrewrk/d1e6173448ab2bc350233cc20025ba56 to your computer and use it in GitHub Desktop.
example of embedding a generated executable inside another one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub export fn _start() void {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn build(b: *std.Build) void { | |
const target = b.standardTargetOptions(.{}); | |
const optimize = b.standardOptimizeOption(.{}); | |
const bootloader = b.addExecutable(.{ | |
.name = "bootloader", | |
.root_source_file = .{ .path = "bootloader.zig" }, | |
.target = .{ | |
.cpu_arch = .x86, | |
.os_tag = .freestanding, | |
}, | |
.optimize = .ReleaseSmall, | |
}); | |
const exe = b.addExecutable(.{ | |
.name = "embed-generated-file", | |
.root_source_file = .{ .path = "main.zig" }, | |
.target = target, | |
.optimize = optimize, | |
}); | |
exe.addAnonymousModule("bootloader.elf", .{ | |
.source_file = bootloader.getOutputSource(), | |
}); | |
exe.install(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const blah = @embedFile("bootloader.elf"); | |
pub fn main() !void { | |
std.debug.print("first 3 bytes: " ++ blah[0..3] ++ "\n", .{}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment