Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # Which Swift to use.
  2. SWIFT:=swift
  3. # Where products will be built; this is the SPM default.
  4. SWIFT_BUILD_PATH:=./.build
  5. SWIFT_BUILD_CONFIGURATION=debug
  6. SWIFT_FLAGS=--scratch-path=${SWIFT_BUILD_PATH} --configuration=${SWIFT_BUILD_CONFIGURATION}
  7. # Force release configuration (for plugins)
  8. SWIFT_FLAGS_RELEASE=$(patsubst --configuration=%,--configuration=release,$(SWIFT_FLAGS))
  9. # protoc plugins.
  10. PROTOC_GEN_SWIFT=${SWIFT_BUILD_PATH}/release/protoc-gen-swift
  11. PROTOC_GEN_GRPC_SWIFT=${SWIFT_BUILD_PATH}/release/protoc-gen-grpc-swift
  12. SWIFT_BUILD:=${SWIFT} build ${SWIFT_FLAGS}
  13. SWIFT_BUILD_RELEASE:=${SWIFT} build ${SWIFT_FLAGS_RELEASE}
  14. SWIFT_TEST:=${SWIFT} test ${SWIFT_FLAGS}
  15. SWIFT_PACKAGE:=${SWIFT} package ${SWIFT_FLAGS}
  16. # Name of generated xcodeproj
  17. XCODEPROJ:=GRPC.xcodeproj
  18. ### Package and plugin build targets ###########################################
  19. all:
  20. ${SWIFT_BUILD}
  21. Package.resolved:
  22. ${SWIFT_PACKAGE} resolve
  23. .PHONY:
  24. plugins: ${PROTOC_GEN_SWIFT} ${PROTOC_GEN_GRPC_SWIFT}
  25. cp $^ .
  26. ${PROTOC_GEN_SWIFT}: Package.resolved
  27. ${SWIFT_BUILD_RELEASE} --product protoc-gen-swift
  28. ${PROTOC_GEN_GRPC_SWIFT}: Sources/protoc-gen-grpc-swift/*.swift
  29. ${SWIFT_BUILD_RELEASE} --product protoc-gen-grpc-swift
  30. interop-test-runner:
  31. ${SWIFT_BUILD} --product GRPCInteroperabilityTests
  32. interop-backoff-test-runner:
  33. ${SWIFT_BUILD} --product GRPCConnectionBackoffInteropTest
  34. ### Xcodeproj
  35. .PHONY:
  36. project: ${XCODEPROJ}
  37. ${XCODEPROJ}:
  38. ${SWIFT_PACKAGE} generate-xcodeproj --output $@
  39. @-ruby scripts/fix-project-settings.rb GRPC.xcodeproj || \
  40. echo "Consider running 'sudo gem install xcodeproj' to automatically set correct indentation settings for the generated project."
  41. ### Protobuf Generation ########################################################
  42. %.pb.swift: %.proto ${PROTOC_GEN_SWIFT}
  43. protoc $< \
  44. --proto_path=$(dir $<) \
  45. --plugin=${PROTOC_GEN_SWIFT} \
  46. --swift_opt=Visibility=Public \
  47. --swift_out=$(dir $<)
  48. %.grpc.swift: %.proto ${PROTOC_GEN_GRPC_SWIFT}
  49. protoc $< \
  50. --proto_path=$(dir $<) \
  51. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  52. --grpc-swift_opt=Visibility=Public \
  53. --grpc-swift_out=$(dir $<)
  54. ECHO_PROTO=Sources/Examples/Echo/Model/echo.proto
  55. ECHO_PB=$(ECHO_PROTO:.proto=.pb.swift)
  56. ECHO_GRPC=$(ECHO_PROTO:.proto=.grpc.swift)
  57. # For Echo we'll generate the test client as well.
  58. ${ECHO_GRPC}: ${ECHO_PROTO} ${PROTOC_GEN_GRPC_SWIFT}
  59. protoc $< \
  60. --proto_path=$(dir $<) \
  61. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  62. --grpc-swift_opt=Visibility=Public,TestClient=true \
  63. --grpc-swift_out=$(dir $<)
  64. # Generates protobufs and gRPC client and server for the Echo example
  65. .PHONY:
  66. generate-echo: ${ECHO_PB} ${ECHO_GRPC}
  67. HELLOWORLD_PROTO=Sources/Examples/HelloWorld/Model/helloworld.proto
  68. HELLOWORLD_PB=$(HELLOWORLD_PROTO:.proto=.pb.swift)
  69. HELLOWORLD_GRPC=$(HELLOWORLD_PROTO:.proto=.grpc.swift)
  70. # Generates protobufs and gRPC client and server for the Hello World example
  71. .PHONY:
  72. generate-helloworld: ${HELLOWORLD_PB} ${HELLOWORLD_GRPC}
  73. ROUTE_GUIDE_PROTO=Sources/Examples/RouteGuide/Model/route_guide.proto
  74. ROUTE_GUIDE_PB=$(ROUTE_GUIDE_PROTO:.proto=.pb.swift)
  75. ROUTE_GUIDE_GRPC=$(ROUTE_GUIDE_PROTO:.proto=.grpc.swift)
  76. # Generates protobufs and gRPC client and server for the Route Guide example
  77. .PHONY:
  78. generate-route-guide: ${ROUTE_GUIDE_PB} ${ROUTE_GUIDE_GRPC}
  79. NORMALIZATION_PROTO=Tests/GRPCTests/Codegen/Normalization/normalization.proto
  80. NORMALIZATION_PB=$(NORMALIZATION_PROTO:.proto=.pb.swift)
  81. NORMALIZATION_GRPC=$(NORMALIZATION_PROTO:.proto=.grpc.swift)
  82. # For normalization we'll explicitly keep the method casing.
  83. ${NORMALIZATION_GRPC}: ${NORMALIZATION_PROTO} ${PROTOC_GEN_GRPC_SWIFT}
  84. protoc $< \
  85. --proto_path=$(dir $<) \
  86. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  87. --grpc-swift_opt=KeepMethodCasing=true \
  88. --grpc-swift_out=$(dir $<)
  89. # Generates protobufs and gRPC client and server for the Route Guide example
  90. .PHONY:
  91. generate-normalization: ${NORMALIZATION_PB} ${NORMALIZATION_GRPC}
  92. SERIALIZATION_GRPC_REFLECTION=Tests/GRPCTests/Codegen/Serialization/echo.grpc.reflection.txt
  93. # For serialization we'll set the ReflectionData option to true.
  94. ${SERIALIZATION_GRPC_REFLECTION}: ${ECHO_PROTO} ${PROTOC_GEN_GRPC_SWIFT}
  95. protoc $< \
  96. --proto_path=$(dir $<) \
  97. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  98. --grpc-swift_opt=Client=false,Server=false,ReflectionData=true \
  99. --grpc-swift_out=$(dir ${SERIALIZATION_GRPC_REFLECTION})
  100. # Generates binary file containing the serialized file descriptor proto for the Serialization test
  101. .PHONY:
  102. generate-reflection-data: ${SERIALIZATION_GRPC_REFLECTION}
  103. REFLECTION_PROTO=Sources/GRPCReflectionService/Model/reflection.proto
  104. REFLECTION_PB=$(REFLECTION_PROTO:.proto=.pb.swift)
  105. REFLECTION_GRPC=$(REFLECTION_PROTO:.proto=.grpc.swift)
  106. # For Reflection we'll generate only the Server code.
  107. ${REFLECTION_GRPC}: ${REFLECTION_PROTO} ${PROTOC_GEN_GRPC_SWIFT}
  108. protoc $< \
  109. --proto_path=$(dir $<) \
  110. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  111. --grpc-swift_opt=Client=false \
  112. --grpc-swift_out=$(dir $<)
  113. # Generates protobufs and gRPC server for the Reflection Service
  114. .PHONY:
  115. generate-reflection: ${REFLECTION_PB} ${REFLECTION_GRPC}
  116. ### Testing ####################################################################
  117. # Normal test suite.
  118. .PHONY:
  119. test:
  120. ${SWIFT_TEST}
  121. # Normal test suite with TSAN enabled.
  122. .PHONY:
  123. test-tsan:
  124. ${SWIFT_TEST} --sanitize=thread
  125. # Runs codegen tests.
  126. .PHONY:
  127. test-plugin: ${PROTOC_GEN_GRPC_SWIFT}
  128. PROTOC_GEN_GRPC_SWIFT=${PROTOC_GEN_GRPC_SWIFT} ./dev/codegen-tests/run-tests.sh
  129. ### Misc. ######################################################################
  130. .PHONY:
  131. clean:
  132. -rm -rf Packages
  133. -rm -rf ${SWIFT_BUILD_PATH}
  134. -rm -rf ${XCODEPROJ}
  135. -rm -f Package.resolved
  136. -cd Examples/Google/NaturalLanguage && make clean