travisstaloch / protobuf-zig Goto Github PK
View Code? Open in Web Editor NEWA protocol buffers implementation in zig
License: MIT License
A protocol buffers implementation in zig
License: MIT License
currently, running $ zig build
fails. here is the output:
~/.../zig/protobuf-zig $ zig build
install
└─ install protoc-gen-zig
└─ zig build-exe protoc-gen-zig Debug native failure
error: the following command terminated unexpectedly:
... <COMMAND HERE> ...
i tried running <COMMAND HERE>
(minus the final --listen=-
arg) and it segfaults so i'm not sure what the problem is.
trying to generate code for a simple recursive message type produces the following dependency loop error.
$ script/gen-all.sh -I examples examples/recursive.proto
zig-out/bin/protoc-zig --zig_out=gen -I examples examples/recursive.proto
zig test gen/recursive.pb.zig --pkg-begin protobuf src/lib.zig --pkg-begin protobuf src/lib.zig --pkg-end -freference-trace
src/google/protobuf/compiler/protobuf-types.zig:144:13: error: dependency loop detected
pub const descriptor = MessageDescriptor.init(Self);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
init: src/google/protobuf/compiler/protobuf-types.zig:305:56
descriptor: src/google/protobuf/compiler/protobuf-types.zig:144:49
field_descriptors: gen/recursive.pb.zig:64:5
i'm tracking ziglang/zig#12325 hoping it will fix this. i'd rather wait for it than proceed with generating c code and using it cause the c route gets messy very fast. i don't to deal with 3 files per generated .proto nor want users to have to do so.
what is happening here? each generated .proto message type needs to have const descriptor
and field_descriptors
decls. this is because in deserialize() desc
needs a reference to fields
here. and later a desc.field
needs a reference back to a MessageDescriptor
here.
i have considered and played with these workarounds:
gen.zig#output_format = .c
. however this means that i have to make sure my zig structs are exactly synced up with c structs. this is a pain to do manually. maybe it could be automated? its easier to just wait for now and see if the issue above fixes it.
{Field,Message,Enum}Descriptor
in a .proto file and generate zig and c code from it.The following file results in the error below it.
// examples/proto3_optional.proto
syntax = "proto3";
message Proto3MsgWithOptional {
optional string hello = 1;
}
$ zig build run -- examples/proto3_optional.proto
# ... garbage protobuf output here
proto3_optional.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-zig hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.
SystemProtocError
~/projects/zig/protobuf-zig/src/main.zig:93:9: 0x2301a4 in main (protoc-zig)
return error.SystemProtocError;
^
i think protobuf-zig's main.zig is missing a step for integrating with protoc. it reads a protobuf encoded CodeGeneratorRequest but never sends a CodeGeneratorResponse back. Instead, it just writes directly to the file.
the resulting CodeGeneratorResponse needs to have the FEATURE_PROTO3_OPTIONAL set
RESOURCES:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.