Skip to content

Commit

Permalink
docs: consolidate macOS build instructions and scripts (neovide#2716)
Browse files Browse the repository at this point in the history
* docs: consolidate macos build instructions and scripts

- add a new file `macos-builder/readme.md` with instructions on building and packaging neovide for macos
- update the `macos-builder/run` script to set the release directory based on the architecture target
- modify the `dmg_name` variable in the `macos-builder/run` script to include the architecture target
- update paths and filenames in the `notes` section for correctness and file presence
- assume the script runs in a macos environment with the required tools installed

* build: update macos build workflow configurations

- update the target architecture variable assignments in the macos build workflow

* ci: support multiple architectures in github actions

- add support for building `x86_64-apple-darwin` in github action
- add support for building `aarch64-apple-darwin` in github action
- update the `run` script in the `macos-builder` directory to take an architecture parameter

* chore: remove redundant code and improve efficiency

- remove redundant echo statement from `macos-builder/run`
  • Loading branch information
falcucci authored Jul 19, 2024
1 parent 9f71253 commit 3960baa
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
77 changes: 77 additions & 0 deletions macos-builder/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Neovide Packaging for macOS

This script is designed to build (if needed) and package the Neovide application packaging it into a macOS `.app` bundle, and then creating a `.dmg` disk image for distribution.

## Prerequisites

Before running the script, ensure you have the following dependencies installed:

- [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)
- [create-dmg](https://github.com/create-dmg/create-dmg)
- [codesign](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution)

**Run the Script**:

```bash
./macos-builder/run aarch64-apple-darwin
```

### Steps

**Set Up Release Directory**:
The script sets the `RELEASE_DIR` based on the `TARGET_ARCHITECTURE` environment variable. If `TARGET_ARCHITECTURE` is not set, it defaults to `target/release`.

```bash
RELEASE_DIR=${TARGET_ARCHITECTURE:+target/${TARGET_ARCHITECTURE}/release}
RELEASE_DIR=${RELEASE_DIR:-target/release}
```

**Build the Project**:
If the release directory does not exist, the script runs the `cargo build --release` command to build the project.

_*This is for local development purposes since you would typically build the project beforehand.*_

```bash
if [ ! -d "${RELEASE_DIR}" ]; then
cargo build --release ${TARGET_ARCHITECTURE:+--target "${TARGET_ARCHITECTURE}"}
fi
```

**Prepare the Application Bundle**:

- Sets up directories for the `.app` bundle.
- Copies the built binary and other necessary resources into the bundle.
- Signs the application using `codesign`.

```bash
mkdir -p "${APP_BINARY_DIR}"
mkdir -p "${APP_EXTRAS_DIR}"
cp -fRp "${APP_TEMPLATE}" "${APP_DIR}"
cp -fp "${APP_BINARY}" "${APP_BINARY_DIR}"
touch -r "${APP_BINARY}" "${APP_DIR}/${APP_NAME}"
codesign --remove-signature "${APP_DIR}/${APP_NAME}"
codesign --force --deep --sign - "${APP_DIR}/${APP_NAME}"
```

**Create the Disk Image**:
Uses `create-dmg` to create a `.dmg` file for the application.

```bash
create-dmg \
--filesystem "${DMG_FILESYSTEM}" \
--format "${DMG_FORMAT}" \
--volname "${DMG_VOLNAME}" \
--volicon "${DMG_ICNS}" \
--background "${DMG_BACKGROUND}" \
--window-size 650 470 \
--icon-size 80 \
--icon Neovide.app 240 320 \
--app-drop-link 410 320 \
"${APP_DIR}/${DMG_NAME}" \
"${APP_DIR}/${APP_NAME}"
```

## Notes

- Ensure all paths and filenames are correct and that the necessary files (like `Neovide.icns` and `neovide-dmg-background.tiff`) are present in their respective directories.
- The script assumes a macOS environment with the necessary tools installed.
16 changes: 14 additions & 2 deletions macos-builder/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

set -e

if [ -n "$1" ]; then
TARGET_ARCHITECTURE=$1
fi

RELEASE_DIR=${TARGET_ARCHITECTURE:+target/${TARGET_ARCHITECTURE}/release}
RELEASE_DIR=${RELEASE_DIR:-target/release}

if [ ! -d "${RELEASE_DIR}" ]; then
echo "Release directory '${RELEASE_DIR}' does not exist."
echo "Running 'cargo build --release${TARGET_ARCHITECTURE:+ --target ${TARGET_ARCHITECTURE}}' ..."
cargo build --release ${TARGET_ARCHITECTURE:+--target "${TARGET_ARCHITECTURE}"}
fi

TARGET="neovide"
EXTRAS_DIR="extra"
ASSETS_DIR="assets"
RELEASE_DIR="target/$1/release"
BUNDLE_DIR="${RELEASE_DIR}/bundle"

APP_NAME="Neovide.app"
Expand All @@ -15,7 +27,7 @@ APP_BINARY="${RELEASE_DIR}/${TARGET}"
APP_BINARY_DIR="${APP_DIR}/${APP_NAME}/Contents/MacOS"
APP_EXTRAS_DIR="${APP_DIR}/${APP_NAME}/Contents/Resources"

DMG_NAME="Neovide-$1.dmg"
DMG_NAME="Neovide${TARGET_ARCHITECTURE:+-${TARGET_ARCHITECTURE}}.dmg"
DMG_VOLNAME="Neovide"
DMG_FILESYSTEM="HFS+"
DMG_FORMAT="UDZO"
Expand Down

0 comments on commit 3960baa

Please sign in to comment.