diff options
| author | David Lönnhager <david.l@mullvad.net> | 2025-02-22 16:36:37 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-03-05 23:32:13 +0100 |
| commit | 5191c455b76fed7cfaac0e3a7593f422553d42a8 (patch) | |
| tree | 934fe562b7380b459c737b84dbf5a44b617b9346 | |
| parent | a343c50b33f254c50fc42dd874fcbca5a84f6d3f (diff) | |
| download | mullvadvpn-5191c455b76fed7cfaac0e3a7593f422553d42a8.tar.xz mullvadvpn-5191c455b76fed7cfaac0e3a7593f422553d42a8.zip | |
Add packaging of macOS app to build.sh
| -rw-r--r-- | .github/workflows/downloader.yml | 9 | ||||
| -rw-r--r-- | installer-downloader/assets/Info.plist | 34 | ||||
| -rwxr-xr-x[-rw-r--r--] | installer-downloader/build.sh | 99 |
3 files changed, 136 insertions, 6 deletions
diff --git a/.github/workflows/downloader.yml b/.github/workflows/downloader.yml index ae8aabd4a8..9b25aa783b 100644 --- a/.github/workflows/downloader.yml +++ b/.github/workflows/downloader.yml @@ -55,13 +55,12 @@ jobs: - name: Check file size uses: ./.github/actions/check-file-size with: - artifact: "C:/cargo-target/release/installer-downloader.exe" + artifact: "./installer-downloader/dist/MullvadDownloader.exe" max_size: ${{ env.MAX_BINARY_SIZE }} build-macos: runs-on: macos-latest env: - # TODO: Figure out a reasonable limit for macOS # If the file is larger than this, a regression has probably been introduced. # You should think twice before increasing this limit. MAX_BINARY_SIZE: 2097152 @@ -69,12 +68,14 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Install Rust + run: rustup target add x86_64-apple-darwin + - name: Build - shell: bash run: ./installer-downloader/build.sh - name: Check file size uses: ./.github/actions/check-file-size with: - artifact: "./target/release/installer-downloader" + artifact: "./installer-downloader/dist/MullvadDownloader.dmg" max_size: ${{ env.MAX_BINARY_SIZE }} diff --git a/installer-downloader/assets/Info.plist b/installer-downloader/assets/Info.plist new file mode 100644 index 0000000000..be1ca1be38 --- /dev/null +++ b/installer-downloader/assets/Info.plist @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>installer-downloader</string> + <key>CFBundleGetInfoString</key> + <string></string> + <key>CFBundleIconFile</key> + <string>icon.icns</string> + <key>CFBundleIdentifier</key> + <string>net.mullvad.MullvadDownloader</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleLongVersionString</key> + <string></string> + <key>CFBundleName</key> + <string>net.mullvad.MullvadDownloader</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>0.1</string> + <key>CFBundleVersion</key> + <string></string> + <key>CSResourcesFileMapped</key> + <true/> + <key>LSRequiresCarbon</key> + <true/> + <key>NSHighResolutionCapable</key> + <true/> +</dict> +</plist>
\ No newline at end of file diff --git a/installer-downloader/build.sh b/installer-downloader/build.sh index eb9b87e91f..a425c10ff6 100644..100755 --- a/installer-downloader/build.sh +++ b/installer-downloader/build.sh @@ -24,5 +24,100 @@ source ../scripts/utils/host # shellcheck disable=SC1091 source ../scripts/utils/log -RUSTFLAGS="-C codegen-units=1 -C panic=abort -C strip=symbols -C opt-level=z" \ - cargo build --bin installer-downloader --release +CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"../target"} +DIST_DIR="./dist" + +function build_executable { + local -a target_args=() + + if [[ -n "${1-}" ]]; then + target_args+=(--target "$1") + fi + + # Old bash versions complain about empty array expansion when -u is set + set +u + + RUSTFLAGS="-C codegen-units=1 -C panic=abort -C strip=symbols -C opt-level=z" \ + cargo build --bin installer-downloader --release "${target_args[@]}" + + set -u +} + +function dist_windows_app { + cp "$CARGO_TARGET_DIR/release/installer-downloader.exe" "$DIST_DIR/MullvadDownloader.exe" +} + +# Combine executables on macOS +function lipo_executables { + local target_exes + target_exes=() + + rm -rf "$DIST_DIR/installer-downloader" + + case $HOST in + x86_64-apple-darwin) target_exes=( + "$CARGO_TARGET_DIR/release/installer-downloader" + "$CARGO_TARGET_DIR/aarch64-apple-darwin/release/installer-downloader" + ) + ;; + aarch64-apple-darwin) target_exes=( + "$CARGO_TARGET_DIR/release/installer-downloader" + "$CARGO_TARGET_DIR/x86_64-apple-darwin/release/installer-downloader" + ) + ;; + esac + + lipo "${target_exes[@]}" -create -output "$DIST_DIR/installer-downloader" +} + +function dist_macos_app { + local app_path + bundle_name="MullvadDownloader" + bundle_id="net.mullvad.$bundle_name" + app_path="$DIST_DIR/$bundle_name.app/" + + # Build app bundle + echo "Building $app_path..." + + rm -rf "$app_path" + + mkdir -p "$app_path/Contents/Resources" + cp "../dist-assets/icon.icns" "$app_path/Contents/Resources/" + + mkdir -p "$app_path/Contents/MacOS" + + cp ./assets/Info.plist "$app_path/Contents/Info.plist" + cp "$DIST_DIR/installer-downloader" "$app_path/Contents/MacOS/installer-downloader" + + # Ad-hoc sign app bundle + codesign --force --deep --identifier "$bundle_id" --sign - \ + --timestamp=none --verbose=0 -o runtime \ + "$DIST_DIR/$bundle_name.app" + + # Pack in .dmg + echo "Creating .dmg image..." + + hdiutil create -volname "MullvadDownloader" -srcfolder "$app_path" -ov -format UDZO \ + "$DIST_DIR/MullvadDownloader.dmg" + + # TODO: sign image? +} + +mkdir -p "$DIST_DIR" + +if [[ "$(uname -s)" == "Darwin" ]]; then + case $HOST in + x86_64-apple-darwin) TARGETS=("" aarch64-apple-darwin);; + aarch64-apple-darwin) TARGETS=("" x86_64-apple-darwin);; + esac + + for t in "${TARGETS[@]:-"$HOST"}"; do + build_executable "$t" + done + + lipo_executables + dist_macos_app +elif [[ "$(uname -s)" == "MINGW"* ]]; then + build_executable + dist_windows_app +fi |
