Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. 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 and LinuxMain
  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. # Generates LinuxMain.swift, only on macOS.
  42. generate-linuxmain:
  43. ${SWIFT_TEST} --generate-linuxmain
  44. ### Protobuf Generation ########################################################
  45. %.pb.swift: %.proto ${PROTOC_GEN_SWIFT}
  46. protoc $< \
  47. --proto_path=$(dir $<) \
  48. --plugin=${PROTOC_GEN_SWIFT} \
  49. --swift_opt=Visibility=Public \
  50. --swift_out=$(dir $<)
  51. %.grpc.swift: %.proto ${PROTOC_GEN_GRPC_SWIFT}
  52. protoc $< \
  53. --proto_path=$(dir $<) \
  54. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  55. --grpc-swift_opt=Visibility=Public \
  56. --grpc-swift_out=$(dir $<)
  57. ECHO_PROTO=Sources/Examples/Echo/Model/echo.proto
  58. ECHO_PB=$(ECHO_PROTO:.proto=.pb.swift)
  59. ECHO_GRPC=$(ECHO_PROTO:.proto=.grpc.swift)
  60. # For Echo we'll generate the test client as well.
  61. ${ECHO_GRPC}: ${ECHO_PROTO} ${PROTOC_GEN_GRPC_SWIFT}
  62. protoc $< \
  63. --proto_path=$(dir $<) \
  64. --plugin=${PROTOC_GEN_GRPC_SWIFT} \
  65. --grpc-swift_opt=Visibility=Public,TestClient=true \
  66. --grpc-swift_out=$(dir $<)
  67. # Generates protobufs and gRPC client and server for the Echo example
  68. .PHONY:
  69. generate-echo: ${ECHO_PB} ${ECHO_GRPC}
  70. HELLOWORLD_PROTO=Sources/Examples/HelloWorld/Model/helloworld.proto
  71. HELLOWORLD_PB=$(HELLOWORLD_PROTO:.proto=.pb.swift)
  72. HELLOWORLD_GRPC=$(HELLOWORLD_PROTO:.proto=.grpc.swift)
  73. # Generates protobufs and gRPC client and server for the Hello World example
  74. .PHONY:
  75. generate-helloworld: ${HELLOWORLD_PB} ${HELLOWORLD_GRPC}
  76. ROUTE_GUIDE_PROTO=Sources/Examples/RouteGuide/Model/route_guide.proto
  77. ROUTE_GUIDE_PB=$(ROUTE_GUIDE_PROTO:.proto=.pb.swift)
  78. ROUTE_GUIDE_GRPC=$(ROUTE_GUIDE_PROTO:.proto=.grpc.swift)
  79. # Generates protobufs and gRPC client and server for the Route Guide example
  80. .PHONY:
  81. generate-route-guide: ${ROUTE_GUIDE_PB} ${ROUTE_GUIDE_GRPC}
  82. ### Testing ####################################################################
  83. # Normal test suite.
  84. .PHONY:
  85. test:
  86. ${SWIFT_TEST}
  87. # Normal test suite with TSAN enabled.
  88. .PHONY:
  89. test-tsan:
  90. ${SWIFT_TEST} --sanitize=thread
  91. # Checks that linuxmain has been updated: requires macOS.
  92. .PHONY:
  93. test-generate-linuxmain: generate-linuxmain
  94. @git diff --exit-code Tests/LinuxMain.swift Tests/*/XCTestManifests.swift > /dev/null || \
  95. { echo "Generated tests are out-of-date; run 'swift test --generate-linuxmain' to update them!"; exit 1; }
  96. # Runs codegen tests.
  97. .PHONY:
  98. test-plugin: ${PROTOC_GEN_GRPC_SWIFT}
  99. PROTOC_GEN_GRPC_SWIFT=${PROTOC_GEN_GRPC_SWIFT} ./dev/codegen-tests/run-tests.sh
  100. ### Misc. ######################################################################
  101. .PHONY:
  102. clean:
  103. -rm -rf Packages
  104. -rm -rf ${SWIFT_BUILD_PATH}
  105. -rm -rf ${XCODEPROJ}
  106. -rm -f Package.resolved
  107. -cd Examples/Google/NaturalLanguage && make clean