build_plugin_ios.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash -eu
  2. export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M92/webrtc-ios.zip
  3. export SOLUTION_DIR=$(pwd)/Plugin~
  4. export WEBRTC_FRAMEWORK_DIR=$(pwd)/Runtime/Plugins/iOS
  5. export WEBRTC_ARCHIVE_DIR=build/webrtc.xcarchive
  6. export WEBRTC_SIM_ARCHIVE_DIR=build/webrtc-sim.xcarchive
  7. # Install cmake
  8. export HOMEBREW_NO_AUTO_UPDATE=1
  9. brew install cmake
  10. # Download webrtc
  11. curl -L $LIBWEBRTC_DOWNLOAD_URL > webrtc.zip
  12. unzip -d $SOLUTION_DIR/webrtc webrtc.zip
  13. # Build webrtc Unity plugin
  14. cd "$SOLUTION_DIR"
  15. cmake . \
  16. -G Xcode \
  17. -D CMAKE_SYSTEM_NAME=iOS \
  18. -D "CMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
  19. -D CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
  20. -D CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE=YES \
  21. -B build
  22. xcodebuild \
  23. -sdk iphonesimulator \
  24. -arch 'x86_64' \
  25. -project build/webrtc.xcodeproj \
  26. -target WebRTCLib \
  27. -configuration Release
  28. xcodebuild archive \
  29. -sdk iphonesimulator \
  30. -arch 'x86_64' \
  31. -scheme WebRTCPlugin \
  32. -project build/webrtc.xcodeproj \
  33. -configuration Release \
  34. -archivePath "$WEBRTC_SIM_ARCHIVE_DIR"
  35. xcodebuild \
  36. -sdk iphoneos \
  37. -project build/webrtc.xcodeproj \
  38. -target WebRTCLib \
  39. -configuration Release
  40. xcodebuild archive \
  41. -sdk iphoneos \
  42. -scheme WebRTCPlugin \
  43. -project build/webrtc.xcodeproj \
  44. -configuration Release \
  45. -archivePath "$WEBRTC_ARCHIVE_DIR"
  46. rm -rf "$WEBRTC_FRAMEWORK_DIR/webrtc.framework"
  47. cp -r "$WEBRTC_ARCHIVE_DIR/Products/@rpath/webrtc.framework" "$WEBRTC_FRAMEWORK_DIR/webrtc.framework"
  48. # todo(kazuki): The command below combines two libraries for supporting iOS and iOS simulator.
  49. # But currently this is commented out because the combined binary adds a troublesome task to developer
  50. # when building iOS app on XCode. We need to support it using XCFramework or another way.
  51. #
  52. # lipo -create -o "$WEBRTC_FRAMEWORK_DIR/webrtc.framework/webrtc" \
  53. # "$WEBRTC_ARCHIVE_DIR/Products/@rpath/webrtc.framework/webrtc" \
  54. # "$WEBRTC_SIM_ARCHIVE_DIR/Products/@rpath/webrtc.framework/webrtc"