From d030e3e392090ca490f504417205c03ee89acb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20C=2E=20Fran=C3=A7a?= Date: Sat, 18 Feb 2023 11:32:35 -0300 Subject: [PATCH 1/4] zproject_zig added --- project.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project.xml b/project.xml index 8024405e..4cff0147 100644 --- a/project.xml +++ b/project.xml @@ -40,6 +40,7 @@ vs2012 Microsoft Visual Studio 2012 vs2013 Microsoft Visual Studio 2013 vs2015 Microsoft Visual Studio 2015 + zig Zig binding and build system Classes are automatically added to all build environments. Further as you add new classes to your project you can generate skeleton header and source @@ -440,6 +441,7 @@ + From 2bb406872ea730351842c3a80007c8ce76c85c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20C=2E=20Fran=C3=A7a?= Date: Sat, 18 Feb 2023 11:34:22 -0300 Subject: [PATCH 2/4] zproject_zig added --- zproject.gsl | 1 + 1 file changed, 1 insertion(+) diff --git a/zproject.gsl b/zproject.gsl index 2e7cacdb..75a45476 100644 --- a/zproject.gsl +++ b/zproject.gsl @@ -350,6 +350,7 @@ gsl from "zproject_vagrant.gsl" gsl from "zproject_vs2008.gsl" gsl from "zproject_vs20xx.gsl" gsl from "zproject_vs20xx_props.gsl" +gsl from "zproject_zig.gsl" # Build targets requested by project if defined (switches.target) From 8422442f32539bcb9df39442fc0a06d042123c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20C=2E=20Fran=C3=A7a?= Date: Sat, 18 Feb 2023 11:40:48 -0300 Subject: [PATCH 3/4] update readme Like Go, Zig has two analogies: * As programming language, commonly called *Ziglang* and also *Zig* (toolchain). --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ab5c280d..0dee4813 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ At least the following build environments are currently supported: * Android * iOS * Visual Studio +* Zig Thanks to the ZeroMQ community, you can do all the heavy lifting in C and then easily generate bindings in the following languages: @@ -91,6 +92,7 @@ Thanks to the ZeroMQ community, you can do all the heavy lifting in C and then e * QML * Qt * Ruby +* Ziglang The language bindings are minimal, meant to be wrapped in a handwritten idiomatic layer later. @@ -219,6 +221,7 @@ zproject's `project.xml` contains an extensive description of the available conf vs2012 Microsoft Visual Studio 2012 vs2013 Microsoft Visual Studio 2013 vs2015 Microsoft Visual Studio 2015 + zig Zig binding and build system Classes are automatically added to all build environments. Further as you add new classes to your project you can generate skeleton header and source @@ -619,6 +622,7 @@ zproject's `project.xml` contains an extensive description of the available conf + From 78422522f4b88ceda0c2e56f9730e59179d04a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20C=2E=20Fran=C3=A7a?= Date: Sat, 18 Feb 2023 12:17:13 -0300 Subject: [PATCH 4/4] (initial draft) Make `zproject_zig.gsl` Zig build project --- zproject_zig.gsl | 152 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 zproject_zig.gsl diff --git a/zproject_zig.gsl b/zproject_zig.gsl new file mode 100644 index 00000000..0568b0c5 --- /dev/null +++ b/zproject_zig.gsl @@ -0,0 +1,152 @@ +# Generate minimal Zig build. +# +# This is a code generator built using the iMatix GSL code generation +# language. See https://github.com/zeromq/gsl for details. +# +# Copyright (c) the Contributors as noted in the AUTHORS file. +# This file is part of zproject. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +register_target ("zig", "Zig build") + +# Target provides name space isolation for its functions + +.macro target_zig +.output "build.zig" +$(project.GENERATED_WARNING_HEADER:) + +//! Works only Zig version: 0.11.0 or higher + +const std = @import("std"); + +// Although this function looks imperative, note that its job is to +// declaratively construct a build graph that will be executed by an external +// runner. +pub fn build(b: *std.Build) 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. + const target = b.standardTargetOptions(.{}); + + // Standard optimization options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not + // set a preferred release mode, allowing the user to decide how to optimize. + const optimize = b.standardOptimizeOption(.{}); + + // Generating "platform.h" on $PWD/zig-cache (local build cache) + const config_header = if (!target.isWindows()) b.addConfigHeader(.{ + .style = .blank, + .include_path = "platform.h", + }, .{ + .CZMQ_BUILD_DRAFT_API = {}, + .HAVE_LINUX_WIRELESS_H = {}, + .HAVE_NET_IF_H = {}, + .HAVE_NET_IF_MEDIA_H = null, + .HAVE_GETIFADDRS = {}, + .HAVE_FREEIFADDRS = {}, + .HAVE_DECL_AI_V4MAPPED = 0, + }) else b.addConfigHeader(.{ + .style = .blank, + .include_path = "platform.h", + }, .{}); + + const lib = b.addSharedLibrary(.{ + .name = "zig_czmq", + // In this case the main source file is merely a path, however, in more + // complicated build scripts, this could be a generated file. + //.root_source_file = .{ .path = "bindings/zig/src/main.zig" }, // No need zig file to build library (C and/or C++ code only) + .version = .{ + .major = 4, + .minor = 2, + .patch = 2, + }, + .target = target, + .optimize = optimize, + }); + lib.addConfigHeader(config_header); + lib.addIncludePath("include"); + lib.addIncludePath(config_header.include_path); + lib.addCSourceFiles(lib_src, lib_flags); + if (target.isWindows()) { + lib.linkSystemLibraryName("ws2_32"); + lib.linkSystemLibraryName("rpcrt4"); + lib.linkSystemLibraryName("iphlpapi"); + } + lib.linkSystemLibrary("zmq"); + lib.linkLibC(); + // This declares intent for the library to be installed into the standard + // location when the user invokes the "install" step (the default step when + // running `zig build`). + lib.install(); + + // Creates a step for unit testing. + const libtest = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + libtest.addConfigHeader(config_header); + libtest.addIncludePath(config_header.include_path); + libtest.addIncludePath("include"); + libtest.addCSourceFiles(lib_src, lib_flags); + if (target.isWindows()) { + libtest.linkSystemLibraryName("ws2_32"); + libtest.linkSystemLibraryName("rpcrt4"); + libtest.linkSystemLibraryName("iphlpapi"); + } + libtest.linkSystemLibrary("zmq"); + libtest.linkLibC(); + + // This creates a build step. It will be visible in the `zig build --help` menu, + // and can be selected like this: `zig build test` + // This will evaluate the `test` step rather than the default, which is "install". + const test_step = b.step("test", "Run library tests"); + test_step.dependOn(&libtest.step); +} + +const lib_flags: []const []const u8 = &.{ + "-std=gnu99", + "-O3", + "-Wall", + "-fno-sanitize=undefined", + "-fno-sanitize-trap=undefined", + // disable undefined sanitizer (default on zig/clang wrapper) +}; +const lib_src: []const []const u8 = &.{ + "src/zactor.c", + "src/zarmour.c", + "src/zcert.c", + "src/zcertstore.c", + "src/zchunk.c", + "src/zclock.c", + "src/zconfig.c", + "src/zdigest.c", + "src/zdir.c", + "src/zdir_patch.c", + "src/zfile.c", + "src/zframe.c", + "src/zhash.c", + "src/zhashx.c", + "src/ziflist.c", + "src/zlist.c", + "src/zlistx.c", + "src/zloop.c", + "src/zmsg.c", + "src/zpoller.c", + "src/zsock.c", + "src/zstr.c", + "src/zsys.c", + "src/zuuid.c", + "src/zauth.c", + "src/zbeacon.c", + "src/zgossip.c", + "src/zmonitor.c", + "src/zproxy.c", + "src/zrex.c", + "src/zgossip_msg.c", +}; +.endmacro