update to new usage of build api (#9)

* update to new usage of build api

* update to new usage of build api
wch-ch32v003
Matt Knight 1 year ago committed by Matt Knight
parent 192fbe713e
commit ed88c548fb

@ -40,15 +40,15 @@ pub const Uf2Step = struct {
pub fn create(exe: *LibExeObjStep, opts: Options) *Uf2Step { pub fn create(exe: *LibExeObjStep, opts: Options) *Uf2Step {
assert(exe.kind == .exe); assert(exe.kind == .exe);
var ret = exe.builder.allocator.create(Uf2Step) catch var ret = exe.step.owner.allocator.create(Uf2Step) catch
@panic("failed to allocate"); @panic("failed to allocate");
ret.* = .{ ret.* = .{
.step = std.build.Step.init( .step = std.build.Step.init(.{
.custom, .id = .custom,
"uf2", .name = "uf2",
exe.builder.allocator, .owner = exe.step.owner,
make, .makeFn = make,
), }),
.exe = exe, .exe = exe,
.opts = opts, .opts = opts,
.output_file = .{ .step = &ret.step }, .output_file = .{ .step = &ret.step },
@ -65,25 +65,26 @@ pub const Uf2Step = struct {
} }
pub fn install(uf2_step: *Uf2Step) void { pub fn install(uf2_step: *Uf2Step) void {
const builder = uf2_step.exe.builder; const owner = uf2_step.exe.step.owner;
const name = std.mem.join(builder.allocator, "", &.{ uf2_step.exe.name, ".uf2" }) catch @panic("failed to join"); const name = std.mem.join(owner.allocator, "", &.{ uf2_step.exe.name, ".uf2" }) catch @panic("failed to join");
const install_step = builder.addInstallFileWithDir(.{ const install_step = owner.addInstallFileWithDir(.{
.generated = &uf2_step.output_file, .generated = &uf2_step.output_file,
}, .bin, name); }, .bin, name);
builder.getInstallStep().dependOn(&uf2_step.step); owner.getInstallStep().dependOn(&uf2_step.step);
builder.getInstallStep().dependOn(&install_step.step); owner.getInstallStep().dependOn(&install_step.step);
} }
fn make(step: *std.build.Step) !void { fn make(step: *std.build.Step, node: *std.Progress.Node) anyerror!void {
_ = node;
const uf2_step = @fieldParentPtr(Uf2Step, "step", step); const uf2_step = @fieldParentPtr(Uf2Step, "step", step);
const file_source = uf2_step.exe.getOutputSource(); const file_source = uf2_step.exe.getOutputSource();
const exe_path = file_source.getPath(uf2_step.exe.builder); const exe_path = file_source.getPath(uf2_step.exe.step.owner);
const dest_path = try std.mem.join(uf2_step.exe.builder.allocator, "", &.{ const dest_path = try std.mem.join(uf2_step.exe.step.owner.allocator, "", &.{
exe_path, exe_path,
".uf2", ".uf2",
}); });
var archive = Archive.init(uf2_step.exe.builder.allocator); var archive = Archive.init(uf2_step.exe.step.owner.allocator);
errdefer archive.deinit(); errdefer archive.deinit();
try archive.addElf(exe_path, uf2_step.opts); try archive.addElf(exe_path, uf2_step.opts);

Loading…
Cancel
Save