ci(release): build a universal binary on macOS

After some tweaks to our dep builds, we can now build a universal binary
for macOS by using `CMAKE_OSX_ARCHITECTURES`. So, let's do that. This
requires a number of additional changes:

1. We need to build on macOS 11, since earlier versions do not support
   building universal (M1 + Intel) binaries.
2. We need to provision a universal `libintl`. The linker will look for
   an ARM64 version of this library when linking the `nvim` binary.

While we're here:
1. Link statically to `libintl`. This allows to to avoid having to do
   any install name rewriting or codesigning to package Neovim.
2. Bump the `MACOSX_DEPLOYMENT_TARGET` to `11`. We're already using a
   `libintl` built by Homebrew (through the pre-installed version of
   `gettext`), and that is built for macOS 11.

In order to ensure we link to `libintl.a` instead of `libintl.dylib`, we
have to make sure that CMake can't find the latter. This ideally should
be a matter of doing `brew unlink gettext`. However, CMake is too adept
at finding things that Homebrew has installed (even when not linked), so
we have to do a bit more than that. This appears in the additional step
ensuring static linkage to `libintl`.

We end up breaking some Homebrew-installed software in the process, and
some of these software is called during our build (e.g. curl, git,
wget). To avoid any adverse effects, let's just uninstall them.
This commit is contained in:
Carlo Cabrera 2022-06-24 23:48:17 +08:00
parent b70f160414
commit d0644fa9bf
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 27 additions and 18 deletions

View File

@ -22,7 +22,7 @@ ${NVIM_VERSION}
1. Download **nvim-macos.tar.gz** 1. Download **nvim-macos.tar.gz**
2. Extract: `tar xzvf nvim-macos.tar.gz` 2. Extract: `tar xzvf nvim-macos.tar.gz`
3. Run `./nvim-osx64/bin/nvim` 3. Run `./nvim-macos/bin/nvim`
### Linux (x64) ### Linux (x64)

View File

@ -78,7 +78,7 @@ jobs:
retention-days: 1 retention-days: 1
macOS: macOS:
runs-on: macos-10.15 runs-on: macos-11
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
@ -91,27 +91,36 @@ jobs:
run: printf 'NVIM_BUILD_TYPE=Release\n' >> $GITHUB_ENV run: printf 'NVIM_BUILD_TYPE=Release\n' >> $GITHUB_ENV
- if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name == 'nightly') - if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name == 'nightly')
run: printf 'NVIM_BUILD_TYPE=RelWithDebInfo\n' >> $GITHUB_ENV run: printf 'NVIM_BUILD_TYPE=RelWithDebInfo\n' >> $GITHUB_ENV
- name: Provision universal `libintl`
run: |
GETTEXT_PREFIX="$(brew --prefix gettext)"
printf 'GETTEXT_PREFIX=%s\n' "$GETTEXT_PREFIX" >> $GITHUB_ENV
bottle_tag="arm64_big_sur"
brew fetch --bottle-tag="$bottle_tag" gettext
cd "$(mktemp -d)"
tar xf "$(brew --cache)"/**/*gettext*${bottle_tag}*.tar.gz
lipo gettext/*/lib/libintl.a "${GETTEXT_PREFIX}/lib/libintl.a" -create -output libintl.a
mv -f libintl.a /usr/local/lib/
- name: Ensure static linkage to `libintl`
run: |
# We're about to mangle `gettext`, so let's remove any potentially broken
# installs (e.g. curl, git) as those could interfere with our build.
brew uninstall $(brew uses --installed --recursive gettext)
brew unlink gettext
ln -sf "$(brew --prefix)/opt/$(readlink "${GETTEXT_PREFIX}")/bin"/* /usr/local/bin/
rm -f "$GETTEXT_PREFIX"
- name: Build release - name: Build release
run: | run: |
make CMAKE_BUILD_TYPE=${NVIM_BUILD_TYPE} CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX:PATH= -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11" export MACOSX_DEPLOYMENT_TARGET="$(sw_vers -productVersion | cut -f1 -d.)"
make DESTDIR="$GITHUB_WORKSPACE/build/release/nvim-osx64" install OSX_FLAGS="-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} -DCMAKE_OSX_ARCHITECTURES=arm64\;x86_64"
make CMAKE_BUILD_TYPE=${NVIM_BUILD_TYPE} \
CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX:PATH= $OSX_FLAGS" \
DEPS_CMAKE_FLAGS="$OSX_FLAGS"
make DESTDIR="$GITHUB_WORKSPACE/build/release/nvim-macos" install
- name: Create package - name: Create package
run: | run: |
cd "$GITHUB_WORKSPACE/build/release" cd "$GITHUB_WORKSPACE/build/release"
mkdir -p nvim-osx64/libs tar cfz nvim-macos.tar.gz nvim-macos
libs=($(otool -L nvim-osx64/bin/nvim | sed 1d | sed -E -e 's|^[[:space:]]*||' -e 's| .*||'))
echo "libs:"
for lib in "${libs[@]}"; do
if echo "$lib" | grep -q -E 'libSystem|CoreServices' 2>/dev/null; then
echo " [skipped] $lib"
else
echo " $lib"
relname="libs/${lib##*/}"
cp -L "$lib" "nvim-osx64/$relname"
install_name_tool -change "$lib" "@executable_path/../$relname" nvim-osx64/bin/nvim
fi
done
tar cfz nvim-macos.tar.gz nvim-osx64
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
with: with:
name: nvim-macos name: nvim-macos