Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Python 3 stable ABI to build MacVim, and better Python discovery #1428

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions .github/workflows/ci-macvim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ env:
CC: clang

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

vi_cv_path_python: /usr/local/bin/python
vi_cv_path_python3: /usr/local/bin/python3
vi_cv_path_plain_lua: /usr/local/bin/lua
vi_cv_path_ruby: /usr/local/opt/ruby/bin/ruby
vi_cv_dll_name_perl: /System/Library/Perl/%s/darwin-thread-multi-2level/CORE/libperl.dylib
vi_cv_dll_name_python: /usr/local/Frameworks/Python.framework/Versions/2.7/Python
vi_cv_dll_name_python3: /usr/local/Frameworks/Python.framework/Versions/%s/Python
vi_cv_dll_name_python3_arm64: /opt/homebrew/Frameworks/Python.framework/Versions/%s/Python
vi_cv_dll_name_python3: /usr/local/Frameworks/Python.framework/Versions/Current/Python
vi_cv_dll_name_python3_arm64: /opt/homebrew/Frameworks/Python.framework/Versions/Current/Python
vi_cv_dll_name_ruby: /usr/local/opt/ruby/lib/libruby.dylib
vi_cv_dll_name_ruby_arm64: /opt/homebrew/opt/ruby/lib/libruby.dylib
vi_cv_dll_name_lua_arm64: /opt/homebrew/lib/liblua.dylib
Expand Down Expand Up @@ -140,22 +139,8 @@ jobs:
brew unlink perl
fi

# With Perl and Python, we need to manually specify the version number for various reasons
# (e.g. library paths include the version number). Because of that, check that the version
# matches the expectation and fail if they don't, so we can go and fix it. Only do for
# Python because a wrong Perl version would just fail the build later.
if [[ "$(python3 --version)" != *"Python $PYTHON3_VERSION"* ]]; then
printf "\n"
echo "Wrong Python 3 version: $(python3 --version). Expected $PYTHON3_VERSION."
printf "\n"
echo "This likely happened because Homebrew was updated to point to a newer version of"
echo "Python 3. Update PYTHON3_VERSION to fix this."
exit -1
fi

# With Perl, we need to manually specify the version number because the dylib path depends on it.
echo "vi_cv_dll_name_perl=$(printf $vi_cv_dll_name_perl $VERSIONER_PERL_VERSION)" >> $GITHUB_ENV
echo "vi_cv_dll_name_python3=$(printf $vi_cv_dll_name_python3 $PYTHON3_VERSION)" >> $GITHUB_ENV
echo "vi_cv_dll_name_python3_arm64=$(printf $vi_cv_dll_name_python3_arm64 $PYTHON3_VERSION)" >> $GITHUB_ENV

# All set up steps are done. Build and test MacVim below.

Expand All @@ -176,6 +161,7 @@ jobs:
--enable-perlinterp=dynamic
--enable-pythoninterp=dynamic
--enable-python3interp=dynamic
--with-python3-stable-abi=3.9 # macOS and Xcode currently ships 3.9, so we don't want go higher than that.
--enable-rubyinterp=dynamic
--enable-luainterp=dynamic
--with-lua-prefix=/usr/local
Expand Down
39 changes: 24 additions & 15 deletions src/MacVim/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,43 @@ set nocompatible
set backspace+=indent,eol,start

" Python2
" MacVim is configured by default to use the pre-installed System python2
" version. However, following code tries to find a Homebrew, MacPorts or
" an installation from python.org:
" MacVim is configured by default in the binary release to use the
" pre-installed System python2 version. However, following code tries to
" find a Homebrew, MacPorts or an installation from python.org:
if exists("&pythondll") && exists("&pythonhome")
" Homebrew python 2.7
if filereadable("/usr/local/Frameworks/Python.framework/Versions/2.7/Python")
" Homebrew python 2.7
set pythondll=/usr/local/Frameworks/Python.framework/Versions/2.7/Python

" MacPorts python 2.7
elseif filereadable("/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python")
" MacPorts python 2.7
set pythondll=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python

" https://www.python.org/downloads/mac-osx/
elseif filereadable("/Library/Frameworks/Python.framework/Versions/2.7/Python")
" https://www.python.org/downloads/mac-osx/
set pythondll=/Library/Frameworks/Python.framework/Versions/2.7/Python
endif
endif

" Python3
" MacVim is configured by default to use Homebrew python3 version
" If this cannot be found, following code tries to find a MacPorts
" or an installation from python.org:
" MacVim is configured by default in the binary release to set
" pythonthreedll to Homebrew python3. If it cannot be found, the following
" code tries to find Python3 from other popular locations. Note that we are
" using "Current" for the version, because Vim supports the stable ABI and
" therefore any new version of Python3 will work.
if exists("&pythonthreedll") && exists("&pythonthreehome") &&
\ !filereadable(&pythonthreedll)
if filereadable("/opt/local/Library/Frameworks/Python.framework/Versions/3.11/Python")
" MacPorts python
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/3.11/Python
elseif filereadable("/Library/Frameworks/Python.framework/Versions/3.11/Python")
" https://www.python.org/downloads/mac-osx/
set pythonthreedll=/Library/Frameworks/Python.framework/Versions/3.11/Python
" MacPorts python
if filereadable("/opt/local/Library/Frameworks/Python.framework/Versions/Current/Python")
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/Current/Python

" macOS default Python, installed by 'xcode-select --install'
elseif filereadable("/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/Current/Python3")
set pythonthreedll=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/Current/Python3

" https://www.python.org/downloads/mac-osx/
elseif filereadable("/Library/Frameworks/Python.framework/Versions/Current/Python")
set pythonthreedll=/Library/Frameworks/Python.framework/Versions/Current/Python
endif
endif

Expand Down