Skip to content

Commit bcd7a9e

Browse files
committed
Generate protobuf/gRPC evaluation client
1 parent 8f9929e commit bcd7a9e

File tree

6 files changed

+1807
-2
lines changed

6 files changed

+1807
-2
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ trim_trailing_whitespace = true
99

1010
[*.{sh,swift-format,yaml}]
1111
indent_size = 2
12+
13+
[Makefile]
14+
indent_style = tab

.licenseignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
*.txt
88
*.yaml
99
Package.swift
10+
Makefile
11+
.gitmodules
12+
flagd-schemas/
13+
*/Generated/**

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Code generation
2+
# -----------------------------------------------------------------------------
3+
PROTO_ROOT = flagd-schemas/protobuf
4+
PROTOS += $(PROTO_ROOT)/flagd/evaluation/v1/evaluation.proto
5+
GEN_SWIFT_ROOT = Sources/Flagd/Generated
6+
GEN_SWIFTS = $(patsubst $(PROTO_ROOT)/%.proto,$(GEN_SWIFT_ROOT)/%.pb.swift,$(PROTOS))
7+
GEN_GRPC_SWIFTS = $(subst $(PROTO_ROOT),$(GEN_SWIFT_ROOT),$(PROTOS:.proto=.grpc.swift))
8+
PROTOC_GEN_SWIFT = .build/debug/protoc-gen-swift
9+
PROTOC_GEN_GRPC_SWIFT = .build/debug/protoc-gen-grpc-swift
10+
11+
$(PROTOC_GEN_SWIFT):
12+
swift build --product protoc-gen-swift
13+
14+
$(PROTOC_GEN_GRPC_SWIFT):
15+
swift build --product protoc-gen-grpc-swift
16+
17+
$(GEN_SWIFTS): $(PROTOS) $(PROTOC_GEN_SWIFT)
18+
@mkdir -pv $(GEN_SWIFT_ROOT)
19+
protoc $(PROTOS) \
20+
--proto_path=$(PROTO_ROOT) \
21+
--plugin=$(PROTOC_GEN_SWIFT) \
22+
--swift_out=$(GEN_SWIFT_ROOT) \
23+
--swift_opt=Visibility=Internal \
24+
--experimental_allow_proto3_optional
25+
26+
$(GEN_GRPC_SWIFTS): $(PROTOS) $(PROTOC_GEN_GRPC_SWIFT)
27+
@mkdir -pv $(GEN_SWIFT_ROOT)
28+
protoc $(PROTOS) \
29+
--proto_path=$(PROTO_ROOT) \
30+
--plugin=$(PROTOC_GEN_GRPC_SWIFT) \
31+
--plugin=$(PROTOC_GEN_SWIFT) \
32+
--swift_out=$(GEN_SWIFT_ROOT) \
33+
--swift_opt=Visibility=Internal \
34+
--grpc-swift_out=Client=true,Server=false:$(GEN_SWIFT_ROOT)
35+
36+
.PHONY: generate
37+
generate: $(GEN_SWIFTS) $(GEN_GRPC_SWIFTS)
38+
39+
.PHONY: delete-generated-code
40+
delete-generated-code: # Delete all pb.swift and .grpc.swift files.
41+
@read -p "Delete all *.pb.swift and *.grpc.swift files in Sources/Flagd [y/N]" ans && [ $${ans:-N} = y ]
42+
find Sources -name *.pb.swift -delete -o -name *.grpc.swift -delete

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ let package = Package(
1313
.library(name: "Flagd", targets: ["Flagd"])
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/swift-open-feature/swift-open-feature.git", branch: "main")
16+
.package(url: "https://github.com/swift-open-feature/swift-open-feature.git", branch: "main"),
17+
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.8.0"),
1718
],
1819
targets: [
1920
.target(
2021
name: "Flagd",
2122
dependencies: [
22-
.product(name: "OpenFeature", package: "swift-open-feature")
23+
.product(name: "OpenFeature", package: "swift-open-feature"),
24+
.product(name: "GRPC", package: "grpc-swift"),
2325
]
2426
),
2527
.testTarget(

0 commit comments

Comments
 (0)