create_macos_build_ava.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. set -e
  3. if [ "$#" -lt 8 ]; then
  4. echo "usage <BASE_DIR> <TEMP_DIRECTORY> <OUTPUT_DIRECTORY> <ENTITLEMENTS_FILE_PATH> <VERSION> <SOURCE_REVISION_ID> <CONFIGURATION> <CANARY>"
  5. exit 1
  6. fi
  7. mkdir -p "$1"
  8. mkdir -p "$2"
  9. mkdir -p "$3"
  10. BASE_DIR=$(readlink -f "$1")
  11. TEMP_DIRECTORY=$(readlink -f "$2")
  12. OUTPUT_DIRECTORY=$(readlink -f "$3")
  13. ENTITLEMENTS_FILE_PATH=$(readlink -f "$4")
  14. VERSION=$5
  15. SOURCE_REVISION_ID=$6
  16. CONFIGURATION=$7
  17. CANARY=$8
  18. if [ "$CANARY" == "1" ]; then
  19. RELEASE_TAR_FILE_NAME=ryujinx-canary-$VERSION-macos_universal.app.tar
  20. elif [ "$VERSION" == "1.1.0" ]; then
  21. RELEASE_TAR_FILE_NAME=ryujinx-$CONFIGURATION-$VERSION+$SOURCE_REVISION_ID-macos_universal.app.tar
  22. else
  23. RELEASE_TAR_FILE_NAME=ryujinx-$VERSION-macos_universal.app.tar
  24. fi
  25. ARM64_APP_BUNDLE="$TEMP_DIRECTORY/output_arm64/Ryujinx.app"
  26. X64_APP_BUNDLE="$TEMP_DIRECTORY/output_x64/Ryujinx.app"
  27. UNIVERSAL_APP_BUNDLE="$OUTPUT_DIRECTORY/Ryujinx.app"
  28. EXECUTABLE_SUB_PATH=Contents/MacOS/Ryujinx
  29. rm -rf "$TEMP_DIRECTORY"
  30. mkdir -p "$TEMP_DIRECTORY"
  31. DOTNET_COMMON_ARGS=(-p:DebugType=embedded -p:Version="$VERSION" -p:SourceRevisionId="$SOURCE_REVISION_ID" --self-contained true $EXTRA_ARGS)
  32. dotnet restore
  33. dotnet build -c "$CONFIGURATION" src/Ryujinx
  34. dotnet publish -c "$CONFIGURATION" -r osx-arm64 -o "$TEMP_DIRECTORY/publish_arm64" "${DOTNET_COMMON_ARGS[@]}" src/Ryujinx
  35. dotnet publish -c "$CONFIGURATION" -r osx-x64 -o "$TEMP_DIRECTORY/publish_x64" "${DOTNET_COMMON_ARGS[@]}" src/Ryujinx
  36. # Get rid of the support library for ARMeilleure for x64 (that's only for arm64)
  37. rm -rf "$TEMP_DIRECTORY/publish_x64/libarmeilleure-jitsupport.dylib"
  38. # Get rid of libsoundio from arm64 builds as we don't have a arm64 variant
  39. # TODO: remove this once done
  40. rm -rf "$TEMP_DIRECTORY/publish_arm64/libsoundio.dylib"
  41. pushd "$BASE_DIR/distribution/macos"
  42. ./create_app_bundle.sh "$TEMP_DIRECTORY/publish_x64" "$TEMP_DIRECTORY/output_x64" "$ENTITLEMENTS_FILE_PATH"
  43. ./create_app_bundle.sh "$TEMP_DIRECTORY/publish_arm64" "$TEMP_DIRECTORY/output_arm64" "$ENTITLEMENTS_FILE_PATH"
  44. popd
  45. rm -rf "$UNIVERSAL_APP_BUNDLE"
  46. mkdir -p "$OUTPUT_DIRECTORY"
  47. # Let's copy one of the two different app bundle and remove the executable
  48. cp -R "$ARM64_APP_BUNDLE" "$UNIVERSAL_APP_BUNDLE"
  49. rm "$UNIVERSAL_APP_BUNDLE/$EXECUTABLE_SUB_PATH"
  50. # Make its libraries universal
  51. python3 "$BASE_DIR/distribution/macos/construct_universal_dylib.py" "$ARM64_APP_BUNDLE" "$X64_APP_BUNDLE" "$UNIVERSAL_APP_BUNDLE" "**/*.dylib"
  52. if ! [ -x "$(command -v lipo)" ];
  53. then
  54. if ! [ -x "$(command -v llvm-lipo-17)" ];
  55. then
  56. LIPO=llvm-lipo
  57. else
  58. LIPO=llvm-lipo-17
  59. fi
  60. else
  61. LIPO=lipo
  62. fi
  63. # Make the executable universal
  64. $LIPO "$ARM64_APP_BUNDLE/$EXECUTABLE_SUB_PATH" "$X64_APP_BUNDLE/$EXECUTABLE_SUB_PATH" -output "$UNIVERSAL_APP_BUNDLE/$EXECUTABLE_SUB_PATH" -create
  65. # Patch up the Info.plist to have appropriate version
  66. sed -r -i.bck "s/\%\%RYUJINX_BUILD_VERSION\%\%/$VERSION/g;" "$UNIVERSAL_APP_BUNDLE/Contents/Info.plist"
  67. sed -r -i.bck "s/\%\%RYUJINX_BUILD_GIT_HASH\%\%/$SOURCE_REVISION_ID/g;" "$UNIVERSAL_APP_BUNDLE/Contents/Info.plist"
  68. rm "$UNIVERSAL_APP_BUNDLE/Contents/Info.plist.bck"
  69. # Now sign it
  70. if ! [ -x "$(command -v codesign)" ];
  71. then
  72. if ! [ -x "$(command -v rcodesign)" ];
  73. then
  74. echo "Cannot find rcodesign on your system, please install rcodesign."
  75. exit 1
  76. fi
  77. # NOTE: Currently require https://github.com/indygreg/apple-platform-rs/pull/44 to work on other OSes.
  78. # cargo install --git "https://github.com/marysaka/apple-platform-rs" --branch "fix/adhoc-app-bundle" apple-codesign --bin "rcodesign"
  79. echo "Using rcodesign for ad-hoc signing"
  80. rcodesign sign --entitlements-xml-path "$ENTITLEMENTS_FILE_PATH" "$UNIVERSAL_APP_BUNDLE"
  81. else
  82. echo "Using codesign for ad-hoc signing"
  83. codesign --entitlements "$ENTITLEMENTS_FILE_PATH" -f -s - "$UNIVERSAL_APP_BUNDLE"
  84. fi
  85. echo "Creating archive"
  86. pushd "$OUTPUT_DIRECTORY"
  87. tar --exclude "Ryujinx.app/Contents/MacOS/Ryujinx" -cvf "$RELEASE_TAR_FILE_NAME" Ryujinx.app 1> /dev/null
  88. python3 "$BASE_DIR/distribution/misc/add_tar_exec.py" "$RELEASE_TAR_FILE_NAME" "Ryujinx.app/Contents/MacOS/Ryujinx" "Ryujinx.app/Contents/MacOS/Ryujinx"
  89. gzip -9 < "$RELEASE_TAR_FILE_NAME" > "$RELEASE_TAR_FILE_NAME.gz"
  90. rm "$RELEASE_TAR_FILE_NAME"
  91. popd
  92. echo "Done"