Makefile 4.2 KB

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