Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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:=--build-path=${SWIFT_BUILD_PATH} --configuration=${SWIFT_BUILD_CONFIGURATION}
  7. # protoc plugins.
  8. PROTOC_GEN_SWIFT=${SWIFT_BUILD_PATH}/${SWIFT_BUILD_CONFIGURATION}/protoc-gen-swift
  9. PROTOC_GEN_GRPC_SWIFT=${SWIFT_BUILD_PATH}/${SWIFT_BUILD_CONFIGURATION}/protoc-gen-grpc-swift
  10. SWIFT_BUILD:=${SWIFT} build ${SWIFT_FLAGS}
  11. SWIFT_TEST:=${SWIFT} test ${SWIFT_FLAGS}
  12. SWIFT_PACKAGE:=${SWIFT} package ${SWIFT_FLAGS}
  13. # Name of generated xcodeproj
  14. XCODEPROJ:=GRPC.xcodeproj
  15. ### Package and plugin build targets ###########################################
  16. all:
  17. ${SWIFT_BUILD}
  18. .PHONY:
  19. plugins: ${PROTOC_GEN_SWIFT} ${PROTOC_GEN_GRPC_SWIFT}
  20. ${PROTOC_GEN_SWIFT}:
  21. ${SWIFT_BUILD} --product protoc-gen-swift
  22. ${PROTOC_GEN_GRPC_SWIFT}:
  23. ${SWIFT_BUILD} --product protoc-gen-grpc-swift
  24. interop-test-runner:
  25. ${SWIFT_BUILD} --product GRPCInteroperabilityTests
  26. interop-backoff-test-runner:
  27. ${SWIFT_BUILD} --product GRPCConnectionBackoffInteropTest
  28. ### Xcodeproj and LinuxMain
  29. .PHONY:
  30. project: ${XCODEPROJ}
  31. ${XCODEPROJ}:
  32. ${SWIFT_PACKAGE} generate-xcodeproj --output $@
  33. @-ruby fix-project-settings.rb GRPC.xcodeproj || \
  34. echo "Consider running 'sudo gem install xcodeproj' to automatically set correct indentation settings for the generated project."
  35. # Generates LinuxMain.swift, only on macOS.
  36. generate-linuxmain:
  37. ${SWIFT_TEST} --generate-linuxmain
  38. ### Protobuf Generation ########################################################
  39. %.pb.swift: %.proto ${PROTOC_GEN_SWIFT}
  40. protoc $< \
  41. --proto_path=$(dir $<) \
  42. --plugin=${PROTOC_GEN_SWIFT} \
  43. --swift_opt=Visibility=Public \
  44. --swift_out=$(dir $<)
  45. %.grpc.swift: %.proto ${PROTOC_GEN_GRPC_SWIFT}
  46. protoc $< \
  47. --proto_path=$(dir $<) \
  48. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  49. --grpc-swift_opt=Visibility=Public \
  50. --grpc-swift_out=$(dir $<)
  51. ECHO_PROTO=Sources/Examples/Echo/Model/echo.proto
  52. ECHO_PB=$(ECHO_PROTO:.proto=.pb.swift)
  53. ECHO_GRPC=$(ECHO_PROTO:.proto=.grpc.swift)
  54. # Generates protobufs and gRPC client and server for the Echo example
  55. .PHONY:
  56. generate-echo: ${ECHO_PB} ${ECHO_GRPC}
  57. HELLOWORLD_PROTO=Sources/Examples/HelloWorld/Model/helloworld.proto
  58. HELLOWORLD_PB=$(HELLOWORLD_PROTO:.proto=.pb.swift)
  59. HELLOWORLD_GRPC=$(HELLOWORLD_PROTO:.proto=.grpc.swift)
  60. # Generates protobufs and gRPC client and server for the Hello World example
  61. .PHONY:
  62. generate-helloworld: ${HELLOWORLD_PB} ${HELLOWORLD_GRPC}
  63. ROUTE_GUIDE_PROTO=Sources/Examples/RouteGuide/Model/route_guide.proto
  64. ROUTE_GUIDE_PB=$(ROUTE_GUIDE_PROTO:.proto=.pb.swift)
  65. ROUTE_GUIDE_GRPC=$(ROUTE_GUIDE_PROTO:.proto=.grpc.swift)
  66. # Generates protobufs and gRPC client and server for the Route Guide example
  67. .PHONY:
  68. generate-route-guide: ${ROUTE_GUIDE_PB} ${ROUTE_GUIDE_GRPC}
  69. ### Testing ####################################################################
  70. # Normal test suite.
  71. .PHONY:
  72. test:
  73. ${SWIFT_TEST}
  74. # Checks that linuxmain has been updated: requires macOS.
  75. .PHONY:
  76. test-generate-linuxmain: generate-linuxmain
  77. @git diff --exit-code Tests/LinuxMain.swift Tests/*/XCTestManifests.swift > /dev/null || \
  78. { echo "Generated tests are out-of-date; run 'swift test --generate-linuxmain' to update them!"; exit 1; }
  79. # Generates code for the Echo server and client and tests them against 'golden' data.
  80. .PHONY:
  81. test-plugin: ${ECHO_PROTO} ${PROTOC_GEN_GRPC_SWIFT} ${ECHO_GRPC}
  82. protoc $< \
  83. --proto_path=$(dir $<) \
  84. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  85. --grpc-swift_opt=Visibility=Public \
  86. --grpc-swift_out=/tmp
  87. diff -u /tmp/echo.grpc.swift ${ECHO_GRPC}
  88. ### Misc. ######################################################################
  89. .PHONY:
  90. clean:
  91. -rm -rf Packages
  92. -rm -rf ${SWIFT_BUILD_PATH}
  93. -rm -rf ${XCODEPROJ}
  94. -rm -f Package.pins Package.resolved
  95. -cd Examples/Google/Datastore && make clean
  96. -cd Examples/Google/NaturalLanguage && make clean
  97. -cd Examples/Google/Spanner && make clean