Makefile 4.0 KB

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