1818 vi_cv_dll_name_perl : /System/Library/Perl/5.18/darwin-thread-multi-2level/CORE/libperl.dylib
1919 vi_cv_dll_name_python : /System/Library/Frameworks/Python.framework/Versions/2.7/Python
2020 vi_cv_dll_name_python3 : /usr/local/Frameworks/Python.framework/Versions/3.9/Python
21+ vi_cv_dll_name_python3_arm64 : /opt/homebrew/Frameworks/Python.framework/Versions/3.9/Python
2122 vi_cv_dll_name_ruby : /usr/local/opt/ruby/lib/libruby.dylib
23+ vi_cv_dll_name_ruby_arm64 : /opt/homebrew/opt/ruby/lib/libruby.dylib
24+ vi_cv_dll_name_lua_arm64 : /opt/homebrew/lib/liblua.dylib
2225
2326 VIM_BIN : src/MacVim/build/Release/MacVim.app/Contents/MacOS/Vim
2427 MACVIM_BIN : src/MacVim/build/Release/MacVim.app/Contents/MacOS/MacVim
@@ -38,18 +41,27 @@ jobs:
3841 - os : macos-10.15
3942 xcode : 11.7
4043 - os : macos-10.15
41- publish : true
4244 - os : macos-11.0
45+ publish : true
4346
4447 runs-on : ${{ matrix.os }}
4548
4649 steps :
4750 - uses : actions/checkout@v2
4851
49- # Set up and install gettext for localization.
52+ # Set up, install, and cache gettext library for localization.
53+ #
5054 # Instead of using the default binary installed by Homebrew, need to build our own because gettext is statically
5155 # linked in MacVim, and need to be built against MACOSX_DEPLOYMENT_TARGET to ensure the built binary will work on
5256 # supported macOS versions.
57+ #
58+ # In addition, to support building a universal MacVim, we need an arm64 version of gettext as well in order to
59+ # create a universal gettext binary to link against (Homebrew only distributes thin binaries and therefore this
60+ # has to be done manually). To do that, we will just pull the bottle directly from Homebrew and patch it in using
61+ # lipo. We can't use normal brew commands to get the bottle because brew doesn't natively support cross-compiling
62+ # and we are running CI on x86_64 Macs. We also don't need to worry about the min deployment target fix on arm64
63+ # because all Apple Silicon Macs have to run on macOS 11+.
64+
5365 - name : Set up gettext
5466 if : matrix.publish
5567 run : |
@@ -71,11 +83,12 @@ jobs:
7183 brew uninstall --ignore-dependencies gettext
7284
7385 - name : Cache gettext
86+ id : cache-gettext
7487 if : matrix.publish
7588 uses : actions/cache@v2
7689 with :
7790 path : /usr/local/Cellar/gettext
78- key : gettext-homebrew-cache-${{ runner.os }} -${{ hashFiles('gettext.rb') }}
91+ key : gettext-homebrew-cache-patched-unified -${{ hashFiles('gettext.rb') }}
7992
8093 - name : Install gettext
8194 if : matrix.publish
8598 brew install -s gettext.rb # This will be a no-op if gettext was cached
8699 brew link gettext # If gettext was cached, this step is necessary to relink it to /usr/local/
87100
101+ - name : Create universal gettext with arm64 bottle
102+ if : matrix.publish && steps.cache-gettext.outputs.cache-hit != 'true'
103+ env :
104+ HOMEBREW_NO_AUTO_UPDATE : 1
105+ run : |
106+ set -o verbose
107+
108+ # Manually download and extract gettext bottle for arm64
109+ gettext_url=$(brew info --json gettext | ruby -rjson -e 'j = JSON.parse(STDIN.read); puts j[0]["bottle"]["stable"]["files"]["arm64_big_sur"]["url"]')
110+ gettext_ver=$(brew info --json gettext | ruby -rjson -e 'j = JSON.parse(STDIN.read); puts j[0]["versions"]["stable"]')
111+
112+ mkdir gettext_download
113+ cd gettext_download
114+ wget --no-verbose ${gettext_url}
115+ tar xf gettext*.tar.gz
116+
117+ # Just for diagnostics, print out the old archs. This should be a thin binary (x86_64)
118+ lipo -info /usr/local/lib/libintl.a
119+ lipo -info /usr/local/lib/libintl.dylib
120+
121+ # Create a universal binary by patching the custom built x86_64 one with the downloaded arm64 one.
122+ # Modify the actual binaries in /usr/local/Cellar instead of the symlinks to allow caching to work.
123+ lipo -create -output /usr/local/Cellar/gettext/${gettext_ver}/lib/libintl.a /usr/local/Cellar/gettext/${gettext_ver}/lib/libintl.a ./gettext/${gettext_ver}/lib/libintl.a
124+ lipo -create -output /usr/local/Cellar/gettext/${gettext_ver}/lib/libintl.dylib /usr/local/Cellar/gettext/${gettext_ver}/lib/libintl.dylib ./gettext/${gettext_ver}/lib/libintl.dylib
125+
126+ # Print out the new archs and verify they are universal with 2 archs.
127+ lipo -info /usr/local/lib/libintl.a | grep 'x86_64 arm64'
128+ lipo -info /usr/local/lib/libintl.dylib | grep 'x86_64 arm64'
129+
130+ # Set up remaining packages and tools
131+
88132 - name : Install packages
89133 if : matrix.publish
90134 env :
@@ -101,6 +145,8 @@ jobs:
101145 sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
102146 xcode-select -p
103147
148+ # All set up steps are done. Build and test MacVim below.
149+
104150 - name : Configure
105151 run : |
106152 set -o verbose
@@ -111,7 +157,6 @@ jobs:
111157 --with-tlib=ncurses
112158 --enable-cscope
113159 --enable-gui=macvim
114- --with-macarchs=x86_64
115160 --with-compiledby="GitHub Actions"
116161 )
117162 if ${{ matrix.publish == true }}; then
@@ -122,6 +167,11 @@ jobs:
122167 --enable-rubyinterp=dynamic
123168 --enable-luainterp=dynamic
124169 --with-lua-prefix=/usr/local
170+ --with-macarchs="x86_64 arm64"
171+ )
172+ else
173+ CONFOPT+=(
174+ --with-macarchs=x86_64
125175 )
126176 fi
127177 echo "CONFOPT: ${CONFOPT[@]}"
@@ -140,6 +190,12 @@ jobs:
140190 grep -q -- "-DDYNAMIC_PYTHON3_DLL=\\\\\"${vi_cv_dll_name_python3}\\\\\"" src/auto/config.mk
141191 grep -q -- "-DDYNAMIC_RUBY_DLL=\\\\\"${vi_cv_dll_name_ruby}\\\\\"" src/auto/config.mk
142192
193+ # Also search for the arm64 overrides for the default library locations, which are different from x86_64
194+ # because Homebrew puts them at a different place.
195+ grep -q -- "-DDYNAMIC_PYTHON3_DLL_ARM64=\\\\\"${vi_cv_dll_name_python3_arm64}\\\\\"" src/auto/config.mk
196+ grep -q -- "-DDYNAMIC_RUBY_DLL_ARM64=\\\\\"${vi_cv_dll_name_ruby_arm64}\\\\\"" src/auto/config.mk
197+ grep -q -- "-DDYNAMIC_LUA_DLL_ARM64=\\\\\"${vi_cv_dll_name_lua_arm64}\\\\\"" src/auto/config.mk
198+
143199 - name : Show configure output
144200 run : |
145201 cat src/auto/config.mk
@@ -185,12 +241,11 @@ jobs:
185241 echo 'Found external dynamic linkage!'; false
186242 fi
187243
188- # Make sure we are building x86_64 only. arm64 builds don't work properly now, so we don't want to accidentally build
189- # it as it will get prioritized by Apple Silicon Macs.
244+ # Make sure we are building universal x86_64 / arm64 builds and didn't accidentally create a thin app.
190245 check_arch() {
191246 local archs=($(lipo -archs "$1"))
192- if [[ ${archs[@]} != x86_64 ]]; then
193- echo "Found unexpected arch(s) in $1: ${archs[@]}"; false
247+ if [[ ${archs[@]} != " x86_64 arm64" ]]; then
248+ echo "Wrong arch(s) in $1: ${archs[@]}"; false
194249 fi
195250 }
196251 check_arch "${VIM_BIN}"
0 commit comments