mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
Include libadwaita and other dependencies in the app bundle on macOS (#271)
* Include libadwaita and other dependencies in the app bundle on macOS * Fix missing pipes * Use recent bash for associative array support (declare -A) * Use correct path for homebrew bash on Intel macOS * Get homebrew path from the brew command * Simplify copy-macos-dylib and convert to POSIX sh Remove need for recent bash altogether * Fix permissions nit * Update macOS dylib copy script path in release workflow * fix a few typos * fix script invocation in pre-release.yml --------- Co-authored-by: Apoorv Khandelwal <mail@apoorvkh.com> Co-authored-by: Ferdinand Schober <ferdinandschober20@gmail.com>
This commit is contained in:
committed by
GitHub
parent
94e6372218
commit
0a0d91b0da
8
.github/workflows/pre-release.yml
vendored
8
.github/workflows/pre-release.yml
vendored
@@ -94,7 +94,9 @@ jobs:
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
run: |
|
||||
cargo bundle --release
|
||||
scripts/copy-macos-dylib.sh "target/release/bundle/osx/Lan Mouse.app/Contents/MacOS/lan-mouse"
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
@@ -120,7 +122,9 @@ jobs:
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
run: |
|
||||
cargo bundle --release
|
||||
scripts/copy-macos-dylib.sh "target/release/bundle/osx/Lan Mouse.app/Contents/MacOS/lan-mouse"
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
|
||||
8
.github/workflows/rust.yml
vendored
8
.github/workflows/rust.yml
vendored
@@ -112,7 +112,9 @@ jobs:
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle
|
||||
run: |
|
||||
cargo bundle
|
||||
scripts/copy-macos-dylib.sh
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/debug/bundle/osx
|
||||
@@ -142,7 +144,9 @@ jobs:
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle
|
||||
run: |
|
||||
cargo bundle
|
||||
scripts/copy-macos-dylib.sh
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/debug/bundle/osx
|
||||
|
||||
8
.github/workflows/tagged-release.yml
vendored
8
.github/workflows/tagged-release.yml
vendored
@@ -90,7 +90,9 @@ jobs:
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
run: |
|
||||
cargo bundle --release
|
||||
scripts/copy-macos-dylib.sh "target/release/bundle/osx/Lan Mouse.app/Contents/MacOS/lan-mouse"
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
@@ -116,7 +118,9 @@ jobs:
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
run: |
|
||||
cargo bundle --release
|
||||
scripts/copy-macos-dylib.sh "target/release/bundle/osx/Lan Mouse.app/Contents/MacOS/lan-mouse"
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
|
||||
23
README.md
23
README.md
@@ -83,7 +83,6 @@ paru -S lan-mouse-git
|
||||
|
||||
<details>
|
||||
<summary>Fedora</summary>
|
||||
|
||||
You can install Lan Mouse from the [Terra Repository](https://terra.fyralabs.com).
|
||||
|
||||
|
||||
@@ -94,6 +93,18 @@ dnf install lan-mouse
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>MacOS</summary>
|
||||
|
||||
- Download the package for your Mac (Intel or ARM) from the releases page
|
||||
- Unzip it
|
||||
- Remove the quarantine with `xattr -rd com.apple.quarantine "Lan Mouse.app"`
|
||||
- Launch the app
|
||||
- Grant accessibility permissions in System Preferences
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Manual Installation</summary>
|
||||
|
||||
@@ -172,7 +183,15 @@ For a detailed list of available features, checkout the [Cargo.toml](./Cargo.tom
|
||||
<summary>MacOS</summary>
|
||||
|
||||
```sh
|
||||
brew install libadwaita pkg-config
|
||||
# Install dependencies
|
||||
brew install libadwaita pkg-config imagemagick
|
||||
cargo install cargo-bundle
|
||||
# Create the macOS icon file
|
||||
scripts/makeicns.sh
|
||||
# Create the .app bundle
|
||||
cargo bundle
|
||||
# Copy all dynamic libraries into the bundle, and update the bundle to find them there
|
||||
scripts/copy-macos-dylib.sh
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
1
dylibs/.gitignore
vendored
Normal file
1
dylibs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*
|
||||
93
scripts/copy-macos-dylib.sh
Executable file
93
scripts/copy-macos-dylib.sh
Executable file
@@ -0,0 +1,93 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
homebrew_path=""
|
||||
exec_path="target/debug/bundle/osx/Lan Mouse.app/Contents/MacOS/lan-mouse"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
$0: Copy all Homebrew libraries into the macOS app bundle.
|
||||
USAGE: $0 [-h] [-b homebrew_path] [exec_path]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Show this help message and exit
|
||||
-b Path to Homebrew installation (default: $homebrew_path)
|
||||
exec_path Path to the main executable in the app bundle
|
||||
(default: get from `brew --prefix`)
|
||||
|
||||
When macOS apps are linked to dynamic libraries (.dylib files),
|
||||
the fully qualified path to the library is embedded in the binary.
|
||||
If the libraries come from Homebrew, that means that Homebrew must be present
|
||||
and the libraries must be installed in the same location on the user's machine.
|
||||
|
||||
This script copies all of the Homebrew libraries that an executable links to into the app bundle
|
||||
and tells all the binaries in the bundle to look for them there.
|
||||
EOF
|
||||
}
|
||||
|
||||
# Gather command-line arguments
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
-h | --help ) usage; exit 0;;
|
||||
-b | --homebrew ) homebrew_path="$1"; shift 2;;
|
||||
* ) exec_path="$1"; shift;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$homebrew_path" ]; then
|
||||
homebrew_path="$(brew --prefix)"
|
||||
fi
|
||||
|
||||
# Path to the .app bundle
|
||||
bundle_path=$(dirname "$(dirname "$(dirname "$exec_path")")")
|
||||
# Path to the Frameworks directory
|
||||
fwks_path="$bundle_path/Contents/Frameworks"
|
||||
mkdir -p "$fwks_path"
|
||||
|
||||
# Copy and fix references for a binary (executable or dylib)
|
||||
#
|
||||
# This function will:
|
||||
# - Copy any referenced dylibs from /opt/homebrew to the Frameworks directory
|
||||
# - Update the binary to reference the local copy instead
|
||||
# - Add the Frameworks directory to the binary's RPATH
|
||||
# - Recursively process the copied dylibs
|
||||
fix_references() {
|
||||
local bin="$1"
|
||||
|
||||
# Get all Homebrew libraries referenced by the binary
|
||||
libs=$(otool -L "$bin" | awk -v homebrew="$homebrew_path" '$0 ~ homebrew {print $1}')
|
||||
|
||||
echo "$libs" | while IFS= read -r old_path; do
|
||||
local base_name="$(basename "$old_path")"
|
||||
local dest="$fwks_path/$base_name"
|
||||
|
||||
if [ ! -e "$dest" ]; then
|
||||
echo "Copying $old_path -> $dest"
|
||||
cp -f "$old_path" "$dest"
|
||||
# Ensure the copied dylib is writable so that xattr -rd /path/to/Lan\ Mouse.app works.
|
||||
chmod 644 "$dest"
|
||||
|
||||
echo "Updating $dest to have install_name of @rpath/$base_name..."
|
||||
install_name_tool -id "@rpath/$base_name" "$dest"
|
||||
|
||||
# Recursively process this dylib
|
||||
fix_references "$dest"
|
||||
fi
|
||||
|
||||
echo "Updating $bin to reference @rpath/$base_name..."
|
||||
install_name_tool -change "$old_path" "@rpath/$base_name" "$bin"
|
||||
done
|
||||
}
|
||||
|
||||
fix_references "$exec_path"
|
||||
|
||||
# Ensure the main executable has our Frameworks path in its RPATH
|
||||
if ! otool -l "$exec_path" | grep -q "@executable_path/../Frameworks"; then
|
||||
echo "Adding RPATH to $exec_path"
|
||||
install_name_tool -add_rpath "@executable_path/../Frameworks" "$exec_path"
|
||||
fi
|
||||
|
||||
# Se-sign the .app
|
||||
codesign --force --deep --sign - "$bundle_path"
|
||||
|
||||
echo "Done!"
|
||||
Reference in New Issue
Block a user