Skip to content

Commit

Permalink
update to Zig 2024.1.0-mach
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
emidoots committed Jan 14, 2024
1 parent c095b33 commit bb05d71
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
42 changes: 30 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,32 @@ const sysaudio = @import("mach_sysaudio");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const module = b.addModule("mach-opus", .{ .source_file = .{ .path = "src/lib.zig" } });

const sysaudio_dep = b.dependency("mach_sysaudio", .{ .target = target, .optimize = optimize });
const sysaudio_dep = b.dependency("mach_sysaudio", .{
.target = target,
.optimize = optimize,
});
const opusfile_dep = b.dependency("opusfile", .{
.target = target,
.optimize = optimize,
});
const opusenc_dep = b.dependency("opusenc", .{
.target = target,
.optimize = optimize,
});

const module = b.addModule("mach-opus", .{
.root_source_file = .{ .path = "src/lib.zig" },
});
module.linkLibrary(opusfile_dep.artifact("opusfile"));
module.linkLibrary(opusenc_dep.artifact("opusenc"));

const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
});
link(b, main_tests);
addPaths(main_tests);
b.installArtifact(main_tests);

const test_step = b.step("test", "Run library tests");
Expand All @@ -26,10 +42,9 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
link(b, example);
example.addModule("mach-opus", module);
example.addModule("mach-sysaudio", sysaudio_dep.module("mach-sysaudio"));
sysaudio.link(b, example);
example.root_module.addImport("mach-opus", module);
example.root_module.addImport("mach-sysaudio", sysaudio_dep.module("mach-sysaudio"));
addPaths(example);
b.installArtifact(example);

const example_run_cmd = b.addRunArtifact(example);
Expand All @@ -39,9 +54,12 @@ pub fn build(b: *std.Build) void {
example_run_step.dependOn(&example_run_cmd.step);
}

pub fn link(b: *std.Build, step: *std.build.CompileStep) void {
const opusfile_dep = b.dependency("opusfile", .{ .target = step.target, .optimize = step.optimize });
const opusenc_dep = b.dependency("opusenc", .{ .target = step.target, .optimize = step.optimize });
step.linkLibrary(opusfile_dep.artifact("opusfile"));
step.linkLibrary(opusenc_dep.artifact("opusenc"));
pub fn addPaths(step: *std.Build.Step.Compile) void {
sysaudio.addPaths(step);
}

pub fn link(b: *std.Build, step: *std.Build.Step.Compile) void {
_ = b;
_ = step;
@panic("link(b, step) has been deprecated, use addPaths(step) instead");
}
16 changes: 8 additions & 8 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
},
.dependencies = .{
.opusfile = .{
.url = "https://pkg.machengine.org/opusfile/234b8f39f232a61a6c901f62044ca97590bfd725.tar.gz",
.hash = "12203293a3503683ee57c0f348899ab1f6d2c6aa7a84e8bbfd4df46a9c8faa7ba305",
.url = "https://pkg.machengine.org/opusfile/e24d748b96d6b2a3164d4b8373346fd42d113c1b.tar.gz",
.hash = "1220a87381d9328511d0d8d7d0aefc65f4df769700cabc27462d4e212ea53a6f30d4",
},
.opusenc = .{
.url = "https://pkg.machengine.org/opusenc/59c144092c9f664b69c146cbd7a047aed23cda9d.tar.gz",
.hash = "1220bbd308fbb76b958e5f45237a0b0022993abd70d543ad22ffaa0a03812176608e",
.url = "https://pkg.machengine.org/opusenc/b855a67fd2a2171cae506579795eb3817c8c3925.tar.gz",
.hash = "12205b82e9375d940b78e8c7df0b84bd1015c9a8c5b2a6b6ff2c21454a2763ef7aa6",
},
.mach_sysaudio = .{
.url = "https://pkg.machengine.org/mach-sysaudio/f987d55fefbb7b7ef5c742ad2e64db68a5a2110d.tar.gz",
.hash = "1220539dbe43f4651bac0495175d5567661c8b9c323fb4fbea9aa1de67a2a7b26566",
.url = "https://pkg.machengine.org/mach-sysaudio/8e4d73150af291d63a5390b157552ce0bbcd4a1d.tar.gz",
.hash = "12206c2ca0378bbc54721553e8167c037325e95e2791379fbe0e245a34334679dc90",
},
.linux_audio_headers = .{
.url = "https://pkg.machengine.org/linux-audio-headers/6b182ff9d51009ca903f3bac63777fbfa654e5f5.tar.gz",
.hash = "122052c4415f4d5be98e3324083939af644d5f8eddd2e6a1a544596645eda8cf411a",
.url = "https://pkg.machengine.org/linux-audio-headers/302c41dc4ab5fa292c3062e9e0d26c7f62652740.tar.gz",
.hash = "1220dc84528a0e298467bec65ab158426306961f08e7555eab9eef684ef126893689",
},
},
}
2 changes: 1 addition & 1 deletion examples/play.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn main() !void {
var iter = std.mem.split(u8, line, ":");
const cmd = std.mem.trimRight(u8, iter.first(), &std.ascii.whitespace);
if (std.mem.eql(u8, cmd, "vol")) {
var vol = try std.fmt.parseFloat(f32, std.mem.trim(u8, iter.next().?, &std.ascii.whitespace));
const vol = try std.fmt.parseFloat(f32, std.mem.trim(u8, iter.next().?, &std.ascii.whitespace));
try player.setVolume(vol);
} else if (std.mem.eql(u8, cmd, "pause")) {
try player.pause();
Expand Down
2 changes: 1 addition & 1 deletion src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn decodeStream(
) (DecodeError || std.io.StreamSource.ReadError)!Opus {
var decoder = Decoder{ .allocator = allocator, .stream = stream };
var err: c_int = 0;
var opus_file = c.op_open_callbacks(
const opus_file = c.op_open_callbacks(
&decoder,
&c.OpusFileCallbacks{
.read = Decoder.readCallback,
Expand Down

0 comments on commit bb05d71

Please sign in to comment.