Skip to content

Commit

Permalink
update to zig 0.13 (#21)
Browse files Browse the repository at this point in the history
hi there,

I updated this project to build on zig 0.13, would happily contribute.

protocol.py is updated, build scripts updated, examples work, tests pass

---------

Co-authored-by: Jacek Pospychala <[email protected]>
Co-authored-by: Malcolm Still <[email protected]>
  • Loading branch information
3 people authored Jun 15, 2024
1 parent 6f2ae20 commit 4b54931
Show file tree
Hide file tree
Showing 24 changed files with 507 additions and 361 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.7.0
version: 0.13.0
- run: zig build test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.7.0
- run: zig fmt --check src/*.zig
version: 0.13.0
- run: zig fmt --check src/*.zig
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ example.o
bin/

zig-cache/
zig-out/

inject.sh

*.xcf

TOUR.md
*.pdf
src/example.zig
src/example.zig
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ require.

### Build

- A zig compiler (tested on at least 0.7.0)
- A zig compiler (tested on at least 0.13.0)

### Regenerating `src/protocol.zig`

Expand Down
35 changes: 26 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
const Builder = @import("std").build.Builder;
const std = @import("std");

pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("zig-amqp", "src/amqp.zig");
lib.setBuildMode(mode);
lib.install();
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

var main_tests = b.addTest("src/amqp.zig");
main_tests.setBuildMode(mode);
const lib = b.addStaticLibrary(.{
.name = "zig-amqp",
.root_source_file = .{ .path = "src/amqp.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);

_ = b.addModule("amqp", .{
.root_source_file = .{ .path = "src/amqp.zig" },
.target = target,
.optimize = optimize,
});

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

const run_lib_unit_tests = b.addRunArtifact(main_tests);

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
test_step.dependOn(&run_lib_unit_tests.step);
}
12 changes: 12 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.{
.name = "amqp",
.version = "0.0.0",

.dependencies = .{},

.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}
30 changes: 15 additions & 15 deletions examples/simple_consume/build.zig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const Builder = @import("std").build.Builder;
const std = @import("std");

pub fn build(b: *Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const amqpDep = b.dependency("amqp", .{});
const amqp = amqpDep.module("amqp");

const exe = b.addExecutable("simple_consume", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackagePath("amqp", "../../src/amqp.zig");
exe.install();
const exe = b.addExecutable(.{
.name = "simple_consume",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("amqp", amqp);

const run_cmd = exe.run();
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
Expand Down
15 changes: 15 additions & 0 deletions examples/simple_consume/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.{
.name = "simple_consumer",
.version = "0.0.0",

.dependencies = .{
.amqp = .{
.url = "../../",
.hash = "12201e2af5138be09dec4dfdd163cf8ef3c15c7c39e202661b64d71c6271a9d0886e",
},
},

.paths = .{
"",
},
}
8 changes: 4 additions & 4 deletions examples/simple_consume/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub fn main() !void {
var consumer = try ch.basicConsume("simple_publish", .{ .no_ack = true }, null);
var i: usize = 0;
while (true) : (i += 1) {
var message = try consumer.next();
var header = message.header;
var body = message.body;
std.debug.warn("{}\n", .{body});
const message = try consumer.next();
_ = message.header;
const body = message.body;
std.debug.print("{s}\n", .{body});
}
}
30 changes: 15 additions & 15 deletions examples/simple_consume_two_channels/build.zig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const Builder = @import("std").build.Builder;
const std = @import("std");

pub fn build(b: *Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const amqpDep = b.dependency("amqp", .{});
const amqp = amqpDep.module("amqp");

const exe = b.addExecutable("simple_consume_two_channels", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackagePath("amqp", "../../src/amqp.zig");
exe.install();
const exe = b.addExecutable(.{
.name = "simple_consume",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("amqp", amqp);

const run_cmd = exe.run();
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
Expand Down
36 changes: 36 additions & 0 deletions examples/simple_consume_two_channels/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.{
.name = "simple_consume_two_channels",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.11.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
.amqp = .{
.url = "../../",
.hash = "12201e2af5138be09dec4dfdd163cf8ef3c15c7c39e202661b64d71c6271a9d0886e",
},
},
.paths = .{
// This makes *all* files, recursively, included in this package. It is generally
// better to explicitly list the files and directories instead, to insure that
// fetching from tarballs, file system paths, and version control all result
// in the same contents hash.
"",
// For example...
//"build.zig",
//"build.zig.zon",
//"src",
//"LICENSE",
//"README.md",
},
}
16 changes: 8 additions & 8 deletions examples/simple_consume_two_channels/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub fn main() !void {
var consumer2 = try ch2.basicConsume("simple_publish", .{ .no_ack = true }, null);
var i: usize = 0;
while (true) : (i += 1) {
var message1 = try consumer1.next();
var header1 = message1.header;
var body1 = message1.body;
std.debug.warn("@1: {}\n", .{body1});
const message1 = try consumer1.next();
_ = message1.header;
const body1 = message1.body;
std.debug.print("@1: {any}\n", .{body1});

var message2 = try consumer2.next();
var header2 = message2.header;
var body2 = message2.body;
std.debug.warn("@2: {}\n", .{body2});
const message2 = try consumer2.next();
_ = message2.header;
const body2 = message2.body;
std.debug.print("@2: {any}\n", .{body2});
}
}
30 changes: 15 additions & 15 deletions examples/simple_publish/build.zig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const Builder = @import("std").build.Builder;
const std = @import("std");

pub fn build(b: *Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const amqpDep = b.dependency("amqp", .{});
const amqp = amqpDep.module("amqp");

const exe = b.addExecutable("simple_publish", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackagePath("amqp", "../../src/amqp.zig");
exe.install();
const exe = b.addExecutable(.{
.name = "simple_consume",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("amqp", amqp);

const run_cmd = exe.run();
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
Expand Down
36 changes: 36 additions & 0 deletions examples/simple_publish/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.{
.name = "simple_publish",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.11.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
.amqp = .{
.url = "../../",
.hash = "12201e2af5138be09dec4dfdd163cf8ef3c15c7c39e202661b64d71c6271a9d0886e",
},
},
.paths = .{
// This makes *all* files, recursively, included in this package. It is generally
// better to explicitly list the files and directories instead, to insure that
// fetching from tarballs, file system paths, and version control all result
// in the same contents hash.
"",
// For example...
//"build.zig",
//"build.zig.zon",
//"src",
//"LICENSE",
//"README.md",
},
}
30 changes: 15 additions & 15 deletions examples/simple_publish_single/build.zig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const Builder = @import("std").build.Builder;
const std = @import("std");

pub fn build(b: *Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const amqpDep = b.dependency("amqp", .{});
const amqp = amqpDep.module("amqp");

const exe = b.addExecutable("simple_publish_single", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackagePath("amqp", "../../src/amqp.zig");
exe.install();
const exe = b.addExecutable(.{
.name = "simple_consume",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("amqp", amqp);

const run_cmd = exe.run();
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
Expand Down
Loading

0 comments on commit 4b54931

Please sign in to comment.