Skip to content

Commit

Permalink
update to zig 0.13.0-dev.347+30a35a897
Browse files Browse the repository at this point in the history
Signed-off-by: Tw <[email protected]>
  • Loading branch information
tw4452852 committed May 31, 2024
1 parent 3b4c249 commit c1b7203
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
20 changes: 9 additions & 11 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ fn create_bpf_prog(ctx: *const Ctx, src_path: []const u8) *std.Build.Step.Compil

const prog = ctx.b.addObject(.{
.name = name,
.root_source_file = .{
.path = src_path,
},
.root_source_file = ctx.b.path(src_path),
.target = ctx.b.resolveTargetQuery(.{
.cpu_arch = switch (ctx.target.result.cpu.arch.endian()) {
.big => .bpfeb,
Expand Down Expand Up @@ -43,7 +41,7 @@ fn create_vmlinux(b: *std.Build) *std.Build.Module {
const libbpf = create_libbpf(b, target, optimize);
const exe = b.addExecutable(.{
.name = "vmlinux_dumper",
.root_source_file = .{ .path = "src/vmlinux_dumper/main.zig" },
.root_source_file = b.path("src/vmlinux_dumper/main.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -57,18 +55,18 @@ fn create_vmlinux(b: *std.Build) *std.Build.Module {
const stdout = run_exe.captureStdOut();
const vmlinux_h = b.addInstallFile(stdout, "vmlinux.h");
const zigify = b.addTranslateC(.{
.root_source_file = .{ .path = b.getInstallPath(vmlinux_h.dir, vmlinux_h.dest_rel_path) },
.root_source_file = .{.cwd_relative = b.getInstallPath(vmlinux_h.dir, vmlinux_h.dest_rel_path)},
.target = target,
.optimize = optimize,
});
zigify.addIncludeDir("src/vmlinux_dumper");
zigify.step.dependOn(&vmlinux_h.step);
return b.addModule("vmlinux", .{ .root_source_file = .{ .generated = &zigify.output_file } });
return b.addModule("vmlinux", .{ .root_source_file = .{ .generated = .{ .file = &zigify.output_file } } });
}

fn create_bpf(b: *std.Build, vmlinux: *std.Build.Module) *std.Build.Module {
return b.addModule("bpf", .{
.root_source_file = .{ .path = "src/bpf/root.zig" },
.root_source_file = b.path("src/bpf/root.zig"),
.imports = &.{.{ .name = "vmlinux", .module = vmlinux }},
});
}
Expand Down Expand Up @@ -128,7 +126,7 @@ fn create_target_step(ctx: *const Ctx, main_path: []const u8, prog_path: []const

const exe = ctx.b.addExecutable(.{
.name = if (exe_name) |name| name else "zbpf",
.root_source_file = .{ .path = main_path },
.root_source_file = ctx.b.path(main_path),
.target = ctx.target,
.optimize = ctx.optimize,
});
Expand Down Expand Up @@ -159,7 +157,7 @@ fn create_test_step(ctx: *const Ctx) !void {
const filter = ctx.b.option([]const u8, "test", "test filter");
// Creates a step for unit testing.
const exe_tests = ctx.b.addTest(.{
.root_source_file = .{ .path = "src/tests/root.zig" },
.root_source_file = ctx.b.path("src/tests/root.zig"),
.target = ctx.target,
.optimize = ctx.optimize,
.filter = filter,
Expand Down Expand Up @@ -195,12 +193,12 @@ fn create_test_step(ctx: *const Ctx) !void {
fn create_docs_step(ctx: *const Ctx) !void {
const exe = ctx.b.addObject(.{
.name = "docs",
.root_source_file = .{ .path = "src/bpf/root.zig" },
.root_source_file = ctx.b.path("src/bpf/root.zig"),
.target = ctx.target,
.optimize = ctx.optimize,
});

const dumb_vmlinux = ctx.b.addModule("dumb_vmlinux", .{ .root_source_file = .{ .path = "src/docs/dummy_vmlinux.zig" } });
const dumb_vmlinux = ctx.b.addModule("dumb_vmlinux", .{ .root_source_file = ctx.b.path("src/docs/dummy_vmlinux.zig") });
const bpf = create_bpf(ctx.b, dumb_vmlinux);
exe.root_module.addImport("bpf", bpf);

Expand Down
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.{
.name = "zbpf",
.version = "0.1.3",
.version = "0.1.4",
.paths = .{""},
.dependencies = .{
.libbpf = .{
.url = "https://github.com/tw4452852/libbpf_zig/archive/refs/tags/1.3.0-3.tar.gz",
.hash = "122061fb7ea6cc1795c8188b5cb0788cdab3f69fd189f5f6d9f11e91f2bb0553435b",
.url = "https://github.com/tw4452852/libbpf_zig/archive/refs/tags/1.3.0-4.tar.gz",
.hash = "1220c5343f425d2c8e0c9369de40f988ea67161c47d2f3432d55a115eba37a20bb6c",
},
},
}
2 changes: 1 addition & 1 deletion src/tests/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn open_tracebuf_pipe(clean: bool) !std.fs.File {

// clean trace buffer if request
if (clean) {
try cwd.writeFile2(.{
try cwd.writeFile(.{
.sub_path = tracefs_mount_dir ++ "/trace",
.data = "\n",
.flags = .{},
Expand Down
4 changes: 2 additions & 2 deletions src/tests/xdp_ping.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test "xdp_ping" {

var buf: [16]u8 = undefined;
const pattern = try std.fmt.bufPrint(&buf, "{x}", .{expected});
var result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &.{ "ping", "-4", "-c", "1", "-p", pattern, "-s", "4", "localhost" } });
var result = try std.process.Child.run(.{ .allocator = allocator, .argv = &.{ "ping", "-4", "-c", "1", "-p", pattern, "-s", "4", "localhost" } });
if (testing.expect(result.term.Exited == 0)) |_| {
allocator.free(result.stdout);
allocator.free(result.stderr);
Expand All @@ -64,7 +64,7 @@ test "xdp_ping" {
}

const pattern6 = try std.fmt.bufPrint(&buf, "{x}", .{expected6});
result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &.{ "ping", "-6", "-c", "1", "-p", pattern6, "-s", "4", "localhost" } });
result = try std.process.Child.run(.{ .allocator = allocator, .argv = &.{ "ping", "-6", "-c", "1", "-p", pattern6, "-s", "4", "localhost" } });
if (testing.expect(result.term.Exited == 0)) |_| {
allocator.free(result.stdout);
allocator.free(result.stderr);
Expand Down

0 comments on commit c1b7203

Please sign in to comment.