Skip to content

Commit b4106e4

Browse files
committed
Use Python 3 stable ABI to build MacVim, and better Python discovery
Vim added support for using Python 3 stable ABI in 9.0.1776, which allows us to safely load Python libraries of a different version from what Vim was built against. Modify our CI to use that. This allows user to use whatever Python version they want as long as it's above the minimum target. Given that macOS/Xcode still ships with 3.9 by default, we build using 3.9 as the minimum version. Also, change our Python detection script to work better. Change all explicit versions in our paths to refer to the "Current" version instead which for the most part should "just work" instead of requiring an exact match every time we or Python update to a new version (e.g. Homebrew will update the Current version to point to the latest Python3). Also add support for finding Python 3 from Xcode Command Line Tools which was previously not ok to use technically because it's 3.9 and before stable ABI support we couldn't load it safely as MacVim was built using newer versions. Fix #1351.
1 parent 95366b5 commit b4106e4

2 files changed

Lines changed: 28 additions & 33 deletions

File tree

.github/workflows/ci-macvim.yaml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ env:
2121
CC: clang
2222

2323
VERSIONER_PERL_VERSION: '5.30' # macOS default Perl installation uses this to determine which one to use
24-
PYTHON3_VERSION: '3.11' # Make sure to keep src/MacVim/vimrc synced with the Python version here for the Python DLL detection logic.
2524

2625
vi_cv_path_python: /usr/local/bin/python
2726
vi_cv_path_python3: /usr/local/bin/python3
2827
vi_cv_path_plain_lua: /usr/local/bin/lua
2928
vi_cv_path_ruby: /usr/local/opt/ruby/bin/ruby
3029
vi_cv_dll_name_perl: /System/Library/Perl/%s/darwin-thread-multi-2level/CORE/libperl.dylib
3130
vi_cv_dll_name_python: /usr/local/Frameworks/Python.framework/Versions/2.7/Python
32-
vi_cv_dll_name_python3: /usr/local/Frameworks/Python.framework/Versions/%s/Python
33-
vi_cv_dll_name_python3_arm64: /opt/homebrew/Frameworks/Python.framework/Versions/%s/Python
31+
vi_cv_dll_name_python3: /usr/local/Frameworks/Python.framework/Versions/Current/Python
32+
vi_cv_dll_name_python3_arm64: /opt/homebrew/Frameworks/Python.framework/Versions/Current/Python
3433
vi_cv_dll_name_ruby: /usr/local/opt/ruby/lib/libruby.dylib
3534
vi_cv_dll_name_ruby_arm64: /opt/homebrew/opt/ruby/lib/libruby.dylib
3635
vi_cv_dll_name_lua_arm64: /opt/homebrew/lib/liblua.dylib
@@ -140,22 +139,8 @@ jobs:
140139
brew unlink perl
141140
fi
142141
143-
# With Perl and Python, we need to manually specify the version number for various reasons
144-
# (e.g. library paths include the version number). Because of that, check that the version
145-
# matches the expectation and fail if they don't, so we can go and fix it. Only do for
146-
# Python because a wrong Perl version would just fail the build later.
147-
if [[ "$(python3 --version)" != *"Python $PYTHON3_VERSION"* ]]; then
148-
printf "\n"
149-
echo "Wrong Python 3 version: $(python3 --version). Expected $PYTHON3_VERSION."
150-
printf "\n"
151-
echo "This likely happened because Homebrew was updated to point to a newer version of"
152-
echo "Python 3. Update PYTHON3_VERSION to fix this."
153-
exit -1
154-
fi
155-
142+
# With Perl, we need to manually specify the version number because the dylib path depends on it.
156143
echo "vi_cv_dll_name_perl=$(printf $vi_cv_dll_name_perl $VERSIONER_PERL_VERSION)" >> $GITHUB_ENV
157-
echo "vi_cv_dll_name_python3=$(printf $vi_cv_dll_name_python3 $PYTHON3_VERSION)" >> $GITHUB_ENV
158-
echo "vi_cv_dll_name_python3_arm64=$(printf $vi_cv_dll_name_python3_arm64 $PYTHON3_VERSION)" >> $GITHUB_ENV
159144
160145
# All set up steps are done. Build and test MacVim below.
161146

@@ -176,6 +161,7 @@ jobs:
176161
--enable-perlinterp=dynamic
177162
--enable-pythoninterp=dynamic
178163
--enable-python3interp=dynamic
164+
--with-python3-stable-abi=3.9 # macOS and Xcode currently ships 3.9, so we don't want go higher than that.
179165
--enable-rubyinterp=dynamic
180166
--enable-luainterp=dynamic
181167
--with-lua-prefix=/usr/local

src/MacVim/vimrc

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,43 @@ set nocompatible
1010
set backspace+=indent,eol,start
1111

1212
" Python2
13-
" MacVim is configured by default to use the pre-installed System python2
14-
" version. However, following code tries to find a Homebrew, MacPorts or
15-
" an installation from python.org:
13+
" MacVim is configured by default in the binary release to use the
14+
" pre-installed System python2 version. However, following code tries to
15+
" find a Homebrew, MacPorts or an installation from python.org:
1616
if exists("&pythondll") && exists("&pythonhome")
17+
" Homebrew python 2.7
1718
if filereadable("/usr/local/Frameworks/Python.framework/Versions/2.7/Python")
18-
" Homebrew python 2.7
1919
set pythondll=/usr/local/Frameworks/Python.framework/Versions/2.7/Python
20+
21+
" MacPorts python 2.7
2022
elseif filereadable("/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python")
21-
" MacPorts python 2.7
2223
set pythondll=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python
24+
25+
" https://www.python.org/downloads/mac-osx/
2326
elseif filereadable("/Library/Frameworks/Python.framework/Versions/2.7/Python")
24-
" https://www.python.org/downloads/mac-osx/
2527
set pythondll=/Library/Frameworks/Python.framework/Versions/2.7/Python
2628
endif
2729
endif
2830

2931
" Python3
30-
" MacVim is configured by default to use Homebrew python3 version
31-
" If this cannot be found, following code tries to find a MacPorts
32-
" or an installation from python.org:
32+
" MacVim is configured by default in the binary release to set
33+
" pythonthreedll to Homebrew python3. If it cannot be found, the following
34+
" code tries to find Python3 from other popular locations. Note that we are
35+
" using "Current" for the version, because Vim supports the stable ABI and
36+
" therefore any new version of Python3 will work.
3337
if exists("&pythonthreedll") && exists("&pythonthreehome") &&
3438
\ !filereadable(&pythonthreedll)
35-
if filereadable("/opt/local/Library/Frameworks/Python.framework/Versions/3.11/Python")
36-
" MacPorts python
37-
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/3.11/Python
38-
elseif filereadable("/Library/Frameworks/Python.framework/Versions/3.11/Python")
39-
" https://www.python.org/downloads/mac-osx/
40-
set pythonthreedll=/Library/Frameworks/Python.framework/Versions/3.11/Python
39+
" MacPorts python
40+
if filereadable("/opt/local/Library/Frameworks/Python.framework/Versions/Current/Python")
41+
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/Current/Python
42+
43+
" macOS default Python, installed by 'xcode-select --install'
44+
elseif filereadable("/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/Current/Python3")
45+
set pythonthreedll=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/Current/Python3
46+
47+
" https://www.python.org/downloads/mac-osx/
48+
elseif filereadable("/Library/Frameworks/Python.framework/Versions/Current/Python")
49+
set pythonthreedll=/Library/Frameworks/Python.framework/Versions/Current/Python
4150
endif
4251
endif
4352

0 commit comments

Comments
 (0)