Skip to content

Commit 4d4a339

Browse files
committed
macos: build and link against libedit
libreadline is GPL v3. Python supports linking against libedit, which has a more permissive license. So, this commit teaches the build system to build libedit and to link the readline extension against it. Doing this with our custom-built ncurses resulted in a failure to find the terminfo database. The workaround is to build/link against the system ncurses. I'm not sure if this is ideal, as it leaves a dependency on libraries in /usr/lib. But it is the easiest way to make the "readline" module work. I'll have to research how all this stuff works and see if we can ship ncurses safely on macOS.
1 parent 5118fcc commit 4d4a339

File tree

7 files changed

+89
-5
lines changed

7 files changed

+89
-5
lines changed

Diff for: README.rst

+22
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,31 @@ the output of this project into derived works.**
134134
Dependency Notes
135135
================
136136

137+
DBM
138+
---
139+
137140
Python has the option of building its ``_dbm`` extension against
138141
NDBM, GDBM, and Berkeley DB. Both NDBM and GDBM are GNU GPL Version 3.
139142
Modern versions of Berkeley DB are GNU AGPL v3. Versions 6.0.19 and
140143
older are licensed under the Sleepycat License. The Sleepycat License
141144
is more permissive. So we build the ``_dbm`` extension against BDB
142145
6.0.19.
146+
147+
readline / libedit / ncurses
148+
----------------------------
149+
150+
Python has the option of building its ``readline`` extension against
151+
either ``libreadline`` or ``libedit``. ``libreadline`` is licensed GNU
152+
GPL Version 3 and ``libedit`` has a more permissive license. We choose
153+
to link against ``libedit`` because of the more permissive license.
154+
155+
``libedit``/``libreadline`` link against a curses library, most likely
156+
``ncurses``. And ``ncurses`` has tie-ins with a terminal database. This
157+
is a thorny situation, as terminal databases can be difficult to
158+
distribute because end-users often want software to respect their
159+
terminal databases. But for that to work, ``ncurses`` needs to be compiled
160+
in a way that respects the user's environment.
161+
162+
On macOS, we statically link a ``libedit`` we compile ourselves. We
163+
dynamically link against ``libncurses``, which is provided by the
164+
system, typically in ``/usr/lib``.

Diff for: cpython-macos/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ $(OUTDIR)/bdb-macos.tar: $(HERE)/build-bdb.sh
1515
$(OUTDIR)/bzip2-macos.tar: $(HERE)/build-bzip2.sh
1616
$(BUILD) bzip2
1717

18+
$(OUTDIR)/libedit-macos.tar: $(HERE)/build-libedit.sh
19+
$(BUILD) libedit
20+
1821
$(OUTDIR)/libffi-macos.tar: $(HERE)/build-libffi.sh
1922
$(BUILD) libffi
2023

@@ -41,6 +44,7 @@ PYTHON_DEPENDS := \
4144
$(HERE)/build-cpython.sh \
4245
$(OUTDIR)/bdb-macos.tar \
4346
$(OUTDIR)/bzip2-macos.tar \
47+
$(OUTDIR)/libedit-macos.tar \
4448
$(OUTDIR)/libffi-macos.tar \
4549
$(OUTDIR)/ncurses-macos.tar \
4650
$(OUTDIR)/openssl-macos.tar \

Diff for: cpython-macos/build-libedit.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
set -ex
7+
8+
ROOT=`pwd`
9+
10+
export CC=clang
11+
export CXX=clang++
12+
13+
tar -xf libedit-${LIBEDIT_VERSION}.tar.gz
14+
pushd libedit-${LIBEDIT_VERSION}
15+
16+
./configure --prefix /
17+
18+
make -j ${NUM_CPUS}
19+
make -j ${NUM_CPUIS} install DESTDIR=${ROOT}/out

Diff for: cpython-macos/build.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
b'nis',
3838
# Not available on macOS.
3939
b'ossaudiodev',
40-
# Not yet supported.
41-
b'readline',
4240
# Not available on macOS.
4341
b'spwd',
4442
}
@@ -124,8 +122,10 @@ def build_cpython():
124122

125123
extract_tar_to_directory(BUILD / 'bdb-macos.tar', deps_dir)
126124
extract_tar_to_directory(BUILD / 'bzip2-macos.tar', deps_dir)
125+
extract_tar_to_directory(BUILD / 'libedit-macos.tar', deps_dir)
127126
extract_tar_to_directory(BUILD / 'libffi-macos.tar', deps_dir)
128-
extract_tar_to_directory(BUILD / 'ncurses-macos.tar', deps_dir)
127+
# We use the system ncurses and statically link (for now).
128+
#extract_tar_to_directory(BUILD / 'ncurses-macos.tar', deps_dir)
129129
extract_tar_to_directory(BUILD / 'openssl-macos.tar', deps_dir)
130130
extract_tar_to_directory(BUILD / 'sqlite-macos.tar', deps_dir)
131131
extract_tar_to_directory(BUILD / 'uuid-macos.tar', deps_dir)
@@ -180,7 +180,7 @@ def main():
180180
with log_path.open('wb') as log_fh:
181181
LOG_FH[0] = log_fh
182182

183-
if action in ('bdb', 'bzip2', 'libffi', 'openssl', 'ncurses', 'sqlite', 'uuid', 'xz', 'zlib'):
183+
if action in ('bdb', 'bzip2', 'libedit', 'libffi', 'openssl', 'ncurses', 'sqlite', 'uuid', 'xz', 'zlib'):
184184
simple_build(action)
185185

186186
elif action == 'cpython':

Diff for: cpython-macos/static-modules

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ _testmultiphase _testmultiphase.c
3030
_uuid _uuidmodule.c -luuid
3131
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3232
pyexpat pyexpat.c expat/xmlparse.c expat/xmlrole.c expat/xmltok.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat
33-
#readline readline.c -I/tools/deps/include -I/tools/deps/include/ncurses -L/tools/deps/lib -lreadline -lncurses
33+
readline readline.c -ledit -lncurses
3434
xxlimited xxlimited.c -DPy_LIMITED_API=0x03050000

Diff for: python-licenses.rst

+33
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,39 @@ the library. If this is what you want to do, use the GNU Lesser General
11121112
Public License instead of this License. But first, please read
11131113
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
11141114
1115+
libedit
1116+
=======
1117+
1118+
Copyright (c) 1992, 1993
1119+
The Regents of the University of California. All rights reserved.
1120+
1121+
This code is derived from software contributed to Berkeley by
1122+
Christos Zoulas of Cornell University.
1123+
1124+
Redistribution and use in source and binary forms, with or without
1125+
modification, are permitted provided that the following conditions
1126+
are met:
1127+
1. Redistributions of source code must retain the above copyright
1128+
notice, this list of conditions and the following disclaimer.
1129+
2. Redistributions in binary form must reproduce the above copyright
1130+
notice, this list of conditions and the following disclaimer in the
1131+
documentation and/or other materials provided with the distribution.
1132+
3. Neither the name of the University nor the names of its contributors
1133+
may be used to endorse or promote products derived from this software
1134+
without specific prior written permission.
1135+
1136+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1137+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1138+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1139+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1140+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1141+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1142+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1143+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1144+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1145+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1146+
SUCH DAMAGE.
1147+
11151148
libffi
11161149
======
11171150

Diff for: pythonbuild/downloads.py

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
'sha256': '9b45c759ff397512eae4d938ff82827b1bd7ccba49920777e5b5e460baeb245f',
8383
'version': '7.0.0',
8484
},
85+
'libedit': {
86+
'url': 'https://www.thrysoee.dk/editline/libedit-20181209-3.1.tar.gz',
87+
'size': 521931,
88+
'sha256': '2811d70c0b000f2ca91b7cb1a37203134441743c4fcc9c37b0b687f328611064',
89+
'version': '20181209-3.1',
90+
},
8591
'libffi': {
8692
'url': 'ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz',
8793
'size': 940837,

0 commit comments

Comments
 (0)