Zig Binding for ZeroMQ
Go to file
2024-02-17 14:52:20 +01:00
.github/workflows Add build action 2024-02-17 12:26:57 +01:00
src Change code formatting 2024-02-17 12:18:21 +01:00
.gitignore Add first skeleton 2024-02-17 12:09:22 +01:00
build_and_test_docker.sh Add test scripts 2024-02-17 12:18:32 +01:00
build_and_test.sh Add test scripts 2024-02-17 12:18:32 +01:00
build.zig Add first skeleton 2024-02-17 12:09:22 +01:00
LICENSE Add first skeleton 2024-02-17 12:09:22 +01:00
README.md change readme 2024-02-17 14:52:20 +01:00
test.Dockerfile Add test scripts 2024-02-17 12:18:32 +01:00

Zig Binding for ZeroMQ

This Zig library provides a ZeroMQ client.

It is implemented as a wrapper of the "High-level C Binding for ZeroMQ" (CZMQ).

IMPORTANT: The library is currently still work in progress!!

Using the Library

Minimal Example

Since this library is basically a 1:1 wrapper of CZMQ, please refer to the CZMQ documentation to get a better understanding on how the library works.

const zzmq = @import("zzmq");

var s = try zzmq.zsocket.ZSocket.init(allocator, zzmq.zsocket.ZSocketType.Pair);
defer s.deinit();

const port = try s.bind("tcp://127.0.0.1:!");

Please feel free to also have a look at the various unit tests in this library.

Adding to build process

Determine the specific release tag of the library to use in the project.

Add to the build.zig.zon file, e.g. for Zig 0.11:

.{
    .dependencies = .{
        .clap = .{
            .url = "https://github.com/nine-lives-later/zzmq/archive/refs/tags/0.1.0-zig.tar.gz",
        },
    },
}

Note: When adding the URL only, the compiler will generate an error regarding the missing .hash field, and will also provide the correct value for it. Starting with Zig 0.12 you can also use zig fetch.

It is also required to add it to the build.zig file:

const zzmq = b.dependency("zzmq", .{
    .target = target,
    .optimize = optimize,
});

// Note: starting with zig 0.12 the function will be 
//       `exe.root_module.addImport` instead of `exe.addModule`
exe.addModule("zzmq", zzmq.module("zzmq"));

exe.linkSystemLibrary("czmq");
exe.linkLibC();

Installing local dependencies

Installing CZMQ development library version 4.0 or higher is also required:

# Building on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libczmq-dev

# Running on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libczmq

Contributing

Zig Version Branches

There are branches for the supported Zig versions:

Branch Zig Version Comment
main Zig v0.11.x The latest unreleased version for Zig 0.11.

Please use a specific release tag for including the library into your project.

Testing

The library can be tested locally by running: zig build test.

Contributors

Implementation done by Felix Kollmann.

Based on the work of CZMQ, inspired by goczmq.

License

Published under the MIT license.

Please keep in mind that this library depends on CZMQ and libzmq which are published under their own respective license. They are being used as dynamically linked libraries (libczmq.so, libzmq.so), which should be fine.