api: Add C support (#549)

This commit is contained in:
Diego Valcarce 2024-10-23 14:24:07 +02:00 committed by GitHub
parent d5929e0523
commit 87c918bc35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 65 additions and 3 deletions

16
api/Dockerfile-c vendored Normal file
View File

@ -0,0 +1,16 @@
FROM alpine:latest
ENV PROJECT_PATH=/chirpstack/api
RUN apk add --no-cache make git bash protobuf protobuf-dev pkgconfig autoconf automake libtool gcc g++
# Install protobuf implementation for C
RUN git clone --depth=1 https://github.com/protobuf-c/protobuf-c.git /protobuf-c
RUN cd /protobuf-c && ./autogen.sh && ./configure && make && make install
# Proto dependencies stuff
RUN git clone --depth=1 https://github.com/protocolbuffers/protobuf.git /protobuf
RUN git clone --depth=1 https://github.com/googleapis/googleapis.git /googleapis
RUN mkdir -p PROJECT_PATH
WORKDIR $PROJECT_PATH

9
api/Makefile vendored
View File

@ -1,6 +1,6 @@
.PHONY: rust grpc-web go js python md java kotlin csharp php
.PHONY: rust grpc-web go js python md java kotlin csharp php c
all: rust grpc-web go js python md java kotlin csharp php
all: rust grpc-web go js python md java kotlin csharp php c
rust:
cd rust && make
@ -30,4 +30,7 @@ csharp:
docker compose run --rm chirpstack-csharp
php:
docker compose run --rm chirpstack-api-php
docker compose run --rm chirpstack-api-php
c:
docker compose run --rm chirpstack-api-c

2
api/c/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/src/
/proto/

34
api/c/Makefile vendored Normal file
View File

@ -0,0 +1,34 @@
.PHONY: all pre-build
PROTOC := protoc-c
PROTOC_ARGS := -I=proto -I=proto/chirpstack-api --c_out=./src
GOOGLE_PROTOBUF_REQUIREMENTS =
GOOGLE_PROTOBUF_REQUIREMENTS += timestamp.proto
GOOGLE_PROTOBUF_REQUIREMENTS += duration.proto
GOOGLE_PROTOBUF_REQUIREMENTS += struct.proto
GOOGLE_PROTOBUF_REQUIREMENTS += empty.proto
GOOGLE_PROTOBUF_REQUIREMENTS += descriptor.proto
GOOGLE_PROTOBUF_OUTPUT = $(patsubst %.proto, src/google/protobuf/%.pb-c.h, $(GOOGLE_PROTOBUF_REQUIREMENTS))
all: pre-build $(GOOGLE_PROTOBUF_OUTPUT) build
pre-build:
rm -rf proto src
mkdir -p proto/chirpstack-api
mkdir -p proto/google/protobuf
cp -r ../proto/* proto/chirpstack-api/
mv proto/chirpstack-api/google/api proto/google/api
mkdir -p src
sed -i \
-r 's/(\s+bytes std)(in|out|err)(\s+=.*)/\1_\2\3/' \
proto/chirpstack-api/gw/gw.proto
src/google/protobuf/%.pb-c.h: /protobuf/src/google/protobuf/%.proto
cp $< proto/google/protobuf/
build:
find proto \
-name '*.proto' \
-type f \
-exec $(PROTOC) $(PROTOC_ARGS) {} \;

View File

@ -49,3 +49,10 @@ services:
command: bash -c "cd php && make all"
volumes:
- ./:/chirpstack/api
chirpstack-api-c:
build:
context: .
dockerfile: Dockerfile-c
command: bash -c "cd c && make all"
volumes:
- ./:/chirpstack/api