From 92342d6d8ca502245e5df370fb4dda773518ff24 Mon Sep 17 00:00:00 2001 From: torque Date: Sat, 14 Sep 2024 20:10:10 -0700 Subject: [PATCH] init --- LICENSE | 21 +++++++++++++++++++++ LICENSE-PROTOBUF_C | 32 ++++++++++++++++++++++++++++++++ build.zig | 29 +++++++++++++++++++++++++++++ build.zig.zon | 18 ++++++++++++++++++ readme.md | 30 ++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 LICENSE create mode 100644 LICENSE-PROTOBUF_C create mode 100644 build.zig create mode 100644 build.zig.zon create mode 100644 readme.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ea81190 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE-PROTOBUF_C b/LICENSE-PROTOBUF_C new file mode 100644 index 0000000..386ad8d --- /dev/null +++ b/LICENSE-PROTOBUF_C @@ -0,0 +1,32 @@ +Copyright (c) 2008-2023, Dave Benson and the protobuf-c authors. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The code generated by the protoc-gen-c code generator and by the +protoc-c compiler is owned by the owner of the input files used when +generating it. This code is not standalone and requires a support +library to be linked with it. This support library is covered by the +above license. diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..e108269 --- /dev/null +++ b/build.zig @@ -0,0 +1,29 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("protobuf_c", .{}); + + const lib = b.addStaticLibrary(.{ + .name = "protobuf_c", + .target = target, + .optimize = optimize, + }); + + lib.linkLibC(); + + lib.addCSourceFiles(.{ + .root = upstream.path("protobuf-c"), + .files = &.{"protobuf-c.c"}, + .flags = &.{}, + }); + + lib.installHeader( + upstream.path("protobuf-c/protobuf-c.h"), + b.pathJoin(&.{ "protobuf-c", "protobuf-c.h" }), + ); + + b.installArtifact(lib); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..016cd28 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,18 @@ +.{ + .name = "protobuf_c", + .version = "1.5.0", + .minimum_zig_version = "0.12.0", + .dependencies = .{ + .protobuf_c = .{ + .url = "git+https://github.com/protobuf-c/protobuf-c?ref=v1.5.0#8c201f6e47a53feaab773922a743091eb6c8972a", + .hash = "12205a20f38efb23d8f688ddb208047b26235608d9fde4c84ce3302ea156443c2b12", + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "LICENSE", + "LICENSE-PROTOBUF_C", + "readme.md", + }, +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..537de7c --- /dev/null +++ b/readme.md @@ -0,0 +1,30 @@ +# `protobuf-c` Runtime + +This is the [protobuf-c runtime](https://github.com/protobuf-c/protobuf-c/tree/master/protobuf-c), packaged for [Zig](https://ziglang.org/). + +## Status + +This project only builds the `protobuf-c` runtime library. It does not build `protoc-c`, the corresponding protocol buffers C language code generator. + +The runtime library depends only on a small amount of functionality from libc, so it should compile for most targets. Linux, macOS and Windows are tested by CI. + +## Usage + +First, update your `build.zig.zon`: + +```sh +# Initialize a `zig build` project if you haven't already +zig init +# replace with the version you want to use, e.g. 1.5.0 +zig fetch --save git+https://github.com/allyourcodebase/protobuf-c# +``` + +You can then use `protobuf_c` in your `build.zig` with: + +```zig +const protobuf_c_dep = b.dependency("protobuf_c", .{ + .target = target, + .optimize = optimize, +}); +your_exe.linkLibrary(protobuf_c_dep.artifact("protobuf_c")); +```