build-extension.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash
  2. set -e
  3. dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
  4. pushd "$dir" > /dev/null
  5. if [ ! -d ../godot-cpp ]; then
  6. echo "No godot-cpp clone found. Run ./setup-extension.sh <Godot branch or tag> <dev> first."
  7. exit 1
  8. fi
  9. options=""
  10. dev="false"
  11. raw_platform=${1%/} # Store the raw platform name before adding platform=
  12. platform="platform=$raw_platform" # Add platform= prefix
  13. arch=$2
  14. if [ -f "../godot-cpp/dev" ]; then
  15. dev="true"
  16. echo "DEV build"
  17. fi
  18. if [ $dev == "true" ]; then
  19. options="$options dev_build=true"
  20. fi
  21. if [ -z $raw_platform ]; then
  22. echo "Platform: current"
  23. platform=""
  24. else
  25. echo "Platform: $raw_platform"
  26. fi
  27. if [ ! -z "$arch" ]; then
  28. echo "Architecture: $arch"
  29. if [ "$raw_platform" == "linux" ] || [ "$raw_platform" == "android" ]; then
  30. options="$options arch=$arch"
  31. fi
  32. fi
  33. cpus=2
  34. if [ "$OSTYPE" == "msys" ]; then
  35. os="windows"
  36. cpus=$NUMBER_OF_PROCESSORS
  37. elif [[ "$OSTYPE" == "darwin"* ]]; then
  38. os="macos"
  39. cpus=$(sysctl -n hw.logicalcpu)
  40. if [ `uname -m` == "arm64" ]; then
  41. echo "Would do Apple Silicon specific setup"
  42. fi
  43. else
  44. os="linux"
  45. cpus=$(grep -c ^processor /proc/cpuinfo)
  46. fi
  47. echo "CPUS: $cpus"
  48. pushd ..
  49. if [ "$raw_platform" == "ios" ]; then
  50. BINDIR="example-v4-extension/bin/ios"
  51. mkdir -p $BINDIR
  52. # Step 1: Build simulator binaries
  53. echo "Building for iOS simulator..."
  54. scons -j $cpus $options $platform target=template_debug arch=universal ios_simulator=yes
  55. mv $BINDIR/ios.framework/libspine_godot.ios.template_debug $BINDIR/libspine_godot.ios.template_debug.simulator.a
  56. scons -j $cpus $options $platform target=template_release arch=universal ios_simulator=yes
  57. mv $BINDIR/ios.framework/libspine_godot.ios.template_release $BINDIR/libspine_godot.ios.template_release.simulator.a
  58. # Step 2: Build device binaries
  59. echo "Building for iOS device..."
  60. scons -j $cpus $options $platform target=template_debug arch=arm64 ios_simulator=no
  61. mv $BINDIR/ios.framework/libspine_godot.ios.template_debug $BINDIR/libspine_godot.ios.template_debug.a
  62. scons -j $cpus $options $platform target=template_release arch=arm64 ios_simulator=no
  63. mv $BINDIR/ios.framework/libspine_godot.ios.template_release $BINDIR/libspine_godot.ios.template_release.a
  64. # Step 3: Create xcframeworks
  65. echo "Creating xcframeworks..."
  66. xcodebuild -create-xcframework \
  67. -library $BINDIR/libspine_godot.ios.template_debug.a \
  68. -library $BINDIR/libspine_godot.ios.template_debug.simulator.a \
  69. -output $BINDIR/libspine_godot.ios.template_debug.xcframework
  70. xcodebuild -create-xcframework \
  71. -library $BINDIR/libspine_godot.ios.template_release.a \
  72. -library $BINDIR/libspine_godot.ios.template_release.simulator.a \
  73. -output $BINDIR/libspine_godot.ios.template_release.xcframework
  74. # Cleanup intermediate files
  75. rm -f $BINDIR/*.a
  76. rm -rf $BINDIR/ios.framework
  77. elif [ "$raw_platform" == "macos" ]; then
  78. BINDIR="example-v4-extension/bin/macos/macos.framework"
  79. TMPDIR="example-v4-extension/bin/macos/tmp"
  80. mkdir -p $BINDIR $TMPDIR
  81. # Build x86_64 binaries
  82. echo "Building for macOS x86_64..."
  83. scons -j $cpus $options $platform target=editor arch=x86_64
  84. mv $BINDIR/libspine_godot.macos.editor $TMPDIR/libspine_godot.macos.editor.x86_64
  85. scons -j $cpus $options $platform target=template_debug arch=x86_64
  86. mv $BINDIR/libspine_godot.macos.template_debug $TMPDIR/libspine_godot.macos.template_debug.x86_64
  87. scons -j $cpus $options $platform target=template_release arch=x86_64
  88. mv $BINDIR/libspine_godot.macos.template_release $TMPDIR/libspine_godot.macos.template_release.x86_64
  89. # Build arm64 binaries
  90. echo "Building for macOS arm64..."
  91. scons -j $cpus $options $platform target=editor arch=arm64
  92. mv $BINDIR/libspine_godot.macos.editor $TMPDIR/libspine_godot.macos.editor.arm64
  93. scons -j $cpus $options $platform target=template_debug arch=arm64
  94. mv $BINDIR/libspine_godot.macos.template_debug $TMPDIR/libspine_godot.macos.template_debug.arm64
  95. scons -j $cpus $options $platform target=template_release arch=arm64
  96. mv $BINDIR/libspine_godot.macos.template_release $TMPDIR/libspine_godot.macos.template_release.arm64
  97. # Create universal binaries
  98. echo "Creating universal binaries..."
  99. lipo -create \
  100. $TMPDIR/libspine_godot.macos.editor.x86_64 \
  101. $TMPDIR/libspine_godot.macos.editor.arm64 \
  102. -output $BINDIR/libspine_godot.macos.editor
  103. lipo -create \
  104. $TMPDIR/libspine_godot.macos.template_debug.x86_64 \
  105. $TMPDIR/libspine_godot.macos.template_debug.arm64 \
  106. -output $BINDIR/libspine_godot.macos.template_debug
  107. lipo -create \
  108. $TMPDIR/libspine_godot.macos.template_release.x86_64 \
  109. $TMPDIR/libspine_godot.macos.template_release.arm64 \
  110. -output $BINDIR/libspine_godot.macos.template_release
  111. # Cleanup intermediate files
  112. rm -rf $TMPDIR
  113. elif [ "$raw_platform" == "web" ]; then
  114. BINDIR="example-v4-extension/bin/web"
  115. mkdir -p $BINDIR
  116. # Build threaded versions
  117. echo "Building web with threads..."
  118. scons -j $cpus $options $platform target=template_debug
  119. scons -j $cpus $options $platform target=template_release
  120. # Build non-threaded versions
  121. echo "Building web without threads..."
  122. scons -j $cpus $options $platform target=template_debug threads=no
  123. scons -j $cpus $options $platform target=template_release threads=no
  124. else
  125. # Normal build process for other platforms
  126. if [ "$raw_platform" != "android" ] && [ "$raw_platform" != "web" ]; then
  127. scons -j $cpus $options $platform target=editor
  128. fi
  129. scons -j $cpus $options $platform target=template_debug
  130. scons -j $cpus $options $platform target=template_release
  131. fi
  132. popd
  133. popd