Skip to content

Commit fa37b14

Browse files
committed
refactor: generate rust in makefile directly
Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
1 parent bedc02d commit fa37b14

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

Makefile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# Copyright 2023 SECO Mind Srl
22
# SPDX-License-Identifier: Apache-2.0
33

4-
.PHONY=clean
4+
.PHONY: check all
55

6-
FILES=$(wildcard proto/edgehog/device/forwarder/*.proto)
7-
OUTPUT=rust/edgehog-device-forwarder-proto/src/proto.rs
8-
CODEGEN_SCRIPT=./scripts/codegen.sh
6+
PROTO_DIR=proto
7+
PROTO_FILES=$(wildcard $(PROTO_DIR)/edgehog/device/forwarder/*.proto)
8+
export PROTO_DIR
9+
export PROTO_FILES
910

10-
$(OUTPUT): $(FILES) $(CODEGEN_SCRIPT)
11-
$(CODEGEN_SCRIPT)
11+
# Rust
12+
RUST_OUT_DIR=rust/edgehog-device-forwarder-proto/src
13+
RUST_OUTPUT=$(RUST_OUT_DIR)/proto.rs
1214

13-
clean:
14-
rm -vr out/
15+
all: check $(RUST_OUTPUT)
16+
17+
check:
18+
./scripts/check-dependencies.sh
19+
20+
$(RUST_OUTPUT): $(PROTO_FILES)
21+
cargo run --manifest-path rust/Cargo.toml -p rust-codegen -- -w proto -o $(RUST_OUT_DIR)
22+
mv $(RUST_OUT_DIR)/edgehog.device.forwarder.rs $(RUST_OUTPUT)

scripts/check-dependencies.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
# Copyright 2023 SECO Mind Srl
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -exu
7+
8+
REQUIRED_PROTOC_MAJOR="24"
9+
10+
# check only major version of protoc
11+
PROTOC_MAJOR=$(command -v protoc >/dev/null &&
12+
protoc --version | cut -d ' ' -f 2 | cut -d . -f 1 ||
13+
true)
14+
15+
if [ "$PROTOC_MAJOR" != "$REQUIRED_PROTOC_MAJOR" ]; then
16+
echo "incompatible protoc version: found \"$PROTOC_MAJOR\", expected \"$PROTOC_MAJOR\"" >&2
17+
exit 1
18+
fi
19+
20+
if ! command -v protoc-gen-elixir >/dev/null
21+
then
22+
echo 'protoc-gen-elixir not found in PATH'
23+
exit 1
24+
fi
25+
26+
if ! command -v escript >/dev/null
27+
then
28+
echo 'escript not found in PATH'
29+
exit 1
30+
fi

scripts/codegen.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)