Use new build.zig functions to get the correct steps
This commit is contained in:
parent
3b052372c2
commit
1f23ba8490
@ -4,55 +4,17 @@ const io = std.io;
|
|||||||
const fmt = std.fmt;
|
const fmt = std.fmt;
|
||||||
const Builder = std.build.Builder;
|
const Builder = std.build.Builder;
|
||||||
const Pkg = std.build.Pkg;
|
const Pkg = std.build.Pkg;
|
||||||
const LibExeObjStep = std.build.LibExeObjStep;
|
const InstallArtifactStep = std.build.InstallArtifactStep;
|
||||||
const ArrayList = std.ArrayList;
|
const ArrayList = std.ArrayList;
|
||||||
|
|
||||||
///! This is a modified build runner to extract information out of build.zig
|
///! This is a modified build runner to extract information out of build.zig
|
||||||
///! Modified from std.special.build_runner
|
///! Modified from the std.special.build_runner
|
||||||
|
|
||||||
// We use a custom Allocator to intercept the creation of steps
|
|
||||||
const InterceptAllocator = struct {
|
|
||||||
base_allocator: *std.mem.Allocator,
|
|
||||||
allocator: std.mem.Allocator,
|
|
||||||
steps: std.ArrayListUnmanaged(*LibExeObjStep),
|
|
||||||
|
|
||||||
fn init(base_allocator: *std.mem.Allocator) InterceptAllocator {
|
|
||||||
return .{
|
|
||||||
.base_allocator = base_allocator,
|
|
||||||
.allocator = .{
|
|
||||||
.reallocFn = realloc,
|
|
||||||
.shrinkFn = shrink,
|
|
||||||
},
|
|
||||||
.steps = .{},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Check LibExeObjStep has a unique size.
|
|
||||||
fn realloc(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {
|
|
||||||
const self = @fieldParentPtr(InterceptAllocator, "allocator", allocator);
|
|
||||||
var data = try self.base_allocator.reallocFn(self.base_allocator, old_mem, old_align, new_size, new_align);
|
|
||||||
if (old_mem.len == 0 and new_size == @sizeOf(LibExeObjStep)) {
|
|
||||||
try self.steps.append(self.base_allocator, @ptrCast(*LibExeObjStep, @alignCast(@alignOf(LibExeObjStep), data.ptr)));
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn shrink(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {
|
|
||||||
const self = @fieldParentPtr(InterceptAllocator, "allocator", allocator);
|
|
||||||
return self.base_allocator.shrinkFn(self.base_allocator, old_mem, old_align, new_size, new_align);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deinit(self: *InterceptAllocator) void {
|
|
||||||
self.steps.deinit(self.base_allocator);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
|
|
||||||
var intercept = InterceptAllocator.init(&arena.allocator);
|
const allocator = &arena.allocator;
|
||||||
defer intercept.deinit();
|
|
||||||
const allocator = &intercept.allocator;
|
|
||||||
|
|
||||||
const builder = try Builder.create(allocator, "", "", "");
|
const builder = try Builder.create(allocator, "", "", "");
|
||||||
defer builder.destroy();
|
defer builder.destroy();
|
||||||
@ -61,15 +23,16 @@ pub fn main() !void {
|
|||||||
|
|
||||||
const stdout_stream = io.getStdOut().outStream();
|
const stdout_stream = io.getStdOut().outStream();
|
||||||
|
|
||||||
// TODO: We currently add packages from every step.,
|
for (builder.getInstallStep().dependencies.items) |step| {
|
||||||
// Should we error out or keep one step or something similar?
|
std.debug.warn("step.id {}\n", .{step.id});
|
||||||
// We also flatten them, we should probably keep the nested structure.
|
if (step.cast(InstallArtifactStep)) |install_exe| {
|
||||||
for (intercept.steps.items) |step| {
|
std.debug.warn("libexeobj!\n", .{});
|
||||||
for (step.packages.items) |pkg| {
|
for (install_exe.artifact.packages.items) |pkg| {
|
||||||
try processPackage(stdout_stream, pkg);
|
try processPackage(stdout_stream, pkg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn processPackage(out_stream: var, pkg: Pkg) anyerror!void {
|
fn processPackage(out_stream: var, pkg: Pkg) anyerror!void {
|
||||||
try out_stream.print("{}\x00{}\n", .{ pkg.name, pkg.path });
|
try out_stream.print("{}\x00{}\n", .{ pkg.name, pkg.path });
|
||||||
|
Loading…
Reference in New Issue
Block a user