Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate flagd evaluation gRPC client #1

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ trim_trailing_whitespace = true

[*.{sh,swift-format,yaml}]
indent_size = 2

[Makefile]
indent_style = tab
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "flagd-schemas"]
path = flagd-schemas
url = https://github.com/open-feature/flagd-schemas
4 changes: 4 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
*.txt
*.yaml
Package.swift
Makefile
.gitmodules
flagd-schemas/
*/Generated/**
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Code generation
# -----------------------------------------------------------------------------
PROTO_ROOT = flagd-schemas/protobuf
PROTOS += $(PROTO_ROOT)/flagd/evaluation/v1/evaluation.proto
GEN_SWIFT_ROOT = Sources/Flagd/Generated
GEN_SWIFTS = $(patsubst $(PROTO_ROOT)/%.proto,$(GEN_SWIFT_ROOT)/%.pb.swift,$(PROTOS))
GEN_GRPC_SWIFTS = $(subst $(PROTO_ROOT),$(GEN_SWIFT_ROOT),$(PROTOS:.proto=.grpc.swift))
PROTOC_GEN_SWIFT = .build/debug/protoc-gen-swift
PROTOC_GEN_GRPC_SWIFT = .build/debug/protoc-gen-grpc-swift

$(PROTOC_GEN_SWIFT):
swift build --product protoc-gen-swift

$(PROTOC_GEN_GRPC_SWIFT):
swift build --product protoc-gen-grpc-swift

$(GEN_SWIFTS): $(PROTOS) $(PROTOC_GEN_SWIFT)
@mkdir -pv $(GEN_SWIFT_ROOT)
protoc $(PROTOS) \
--proto_path=$(PROTO_ROOT) \
--plugin=$(PROTOC_GEN_SWIFT) \
--swift_out=$(GEN_SWIFT_ROOT) \
--swift_opt=Visibility=Internal \
--experimental_allow_proto3_optional

$(GEN_GRPC_SWIFTS): $(PROTOS) $(PROTOC_GEN_GRPC_SWIFT)
@mkdir -pv $(GEN_SWIFT_ROOT)
protoc $(PROTOS) \
--proto_path=$(PROTO_ROOT) \
--plugin=$(PROTOC_GEN_GRPC_SWIFT) \
--plugin=$(PROTOC_GEN_SWIFT) \
--swift_out=$(GEN_SWIFT_ROOT) \
--swift_opt=Visibility=Internal \
--grpc-swift_out=Client=true,Server=false:$(GEN_SWIFT_ROOT)

.PHONY: generate
generate: $(GEN_SWIFTS) $(GEN_GRPC_SWIFTS)

.PHONY: delete-generated-code
delete-generated-code: # Delete all pb.swift and .grpc.swift files.
@read -p "Delete all *.pb.swift and *.grpc.swift files in Sources/Flagd [y/N]" ans && [ $${ans:-N} = y ]
find Sources -name *.pb.swift -delete -o -name *.grpc.swift -delete
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ let package = Package(
.library(name: "Flagd", targets: ["Flagd"])
],
dependencies: [
.package(url: "https://github.com/swift-open-feature/swift-open-feature.git", branch: "main")
.package(url: "https://github.com/swift-open-feature/swift-open-feature.git", branch: "main"),
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.8.0"),
],
targets: [
.target(
name: "Flagd",
dependencies: [
.product(name: "OpenFeature", package: "swift-open-feature")
.product(name: "OpenFeature", package: "swift-open-feature"),
.product(name: "GRPC", package: "grpc-swift"),
]
),
.testTarget(
Expand Down
Loading
Loading