xentropic-dev/zopcua
A Zig wrapper for open62541 that makes OPC UA development feel native to Zig through idiomatic patterns and abstracted C complexities.
This library is under active development and NOT ready for production use.
This wrapper aims to make working with open62541 feel native to Zig by:
This library will not reach full feature parity with open62541 for some time. If you need functionality that isn't yet wrapped, please open an issue!
📚 View the full API documentation
Add zopcua to your project:
zig fetch --save git+https://github.com/xentropic-dev/zopcua.git
Then in your build.zig:
const std = @import("std");
const zopcua = @import("zopcua");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "my-app",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
// Add zopcua - automatically handles module import and platform-specific linking
zopcua.setup(exe, .{});
b.installArtifact(exe);
}
That's it! The setup function automatically:
ua module to your executablezopcua requires mbedTLS for cryptographic operations and secure communication. By default, mbedTLS is statically linked from vendored sources - no system installation required.
If you prefer to use system-installed mbedTLS libraries instead:
zopcua.setup(exe, .{
.mbedtls = .system, // Use system mbedTLS instead of vendored
});
When using system mbedTLS, ensure the libraries are installed:
brew install mbedtlssudo apt install libmbedtls-devconst std = @import("std");
const ua = @import("ua");
pub fn main() !void {
var server = try ua.Server.init();
defer server.deinit();
try server.runUntilInterrupt(); // Blocks here until Ctrl-C
}
# Build the library (uses vendored mbedTLS by default)
zig build
# Build with system mbedTLS
zig build -Dmbedtls=system
# Run tests
zig build test
# Generate documentation
zig build docs
This wrapper library is licensed under the MIT License. See LICENSE for details.
The underlying open62541 library is licensed under the Mozilla Public License 2.0. See the open62541 repository for details.
Contributions are welcome! Please feel free to submit a Pull Request.