Last active
January 25, 2021 17:13
-
-
Save zachlewis/8e0b6b0bb089f45b9df7ac85904dcfbd to your computer and use it in GitHub Desktop.
Python rez package build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = "python" | |
version = "3.7.4" | |
authors = ["Guido van Rossum"] | |
description = \ | |
""" | |
The Python programming language. | |
""" | |
requires = [ | |
#'libexpat-2.2.9+', | |
#'zlib-1.2.3+', | |
] | |
private_build_requires = [ | |
gcc, # or `llvm` | |
#'xz-5.2.4+', | |
] | |
@early() | |
def pyver(): | |
import sys | |
return { | |
'2.7': '2.7', | |
'3.6': '3.6m', | |
'3.7': '3.7m', | |
'3.8': '3.8', | |
'3.9': '3.9' | |
}['.'.join(str(this.version).split('.')[0:2])] | |
@early() | |
def variants(): | |
from rez.package_py_utils import expand_requires | |
requires = ["platform-**", "arch-**", "os-**"] | |
return [expand_requires(*requires)] | |
@early() | |
def tools(): | |
# conditionally enumerate python 2 / 3 tools | |
maj, mnr = this.version.split('.')[0:2] | |
pyver = '.'.join([maj, mnr]) | |
all_vers = ['python{0}', 'python{0}-config', 'pydoc{0}', 'pip{0}'] | |
py2_only = ['smtpd.py'] | |
py3_only = ['pyenv', 'idle3'] | |
tools = py2_only if int(maj) < 3 else py3_only + ['idle'] | |
variants = ['', maj, pyver] | |
for tool in all_vers: | |
for variant in variants: | |
tools.append(tool.format(variant)) | |
return tools + ['2to3', 'idle'] | |
@early() | |
def uuid(): | |
import uuid | |
return str(uuid.uuid5(uuid.NAMESPACE_DNS, name)) | |
def pre_build_commands(): | |
pyver = str(this.version) | |
url = "http://www.python.org/ftp/python/{pyver}/Python-{pyver}.tgz" % (pyver, pyver) | |
env.CFLAGS = ("-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions " | |
"-fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches " | |
"-m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv $CFLAGS") | |
env.LDFLAGS = "-Wl,-z,relro,-rpath=${build.install_path}/lib $LDFLAGS" | |
env.REZ_BUILD_CONFIGURE_OPTIONS = " ".join([ | |
"--prefix={build.install_path}", | |
"--enable-ipv6", | |
"--enable-shared", | |
"--enable-unicode=ucs4", | |
"--with-dbmliborder=gdbm:ndbm:bdb", # build DBM module against GDBM instead of Berkley DB | |
"--with-system-expat", # use system libexpat | |
"--with-system-ffi", # use system libffi | |
"--with-ensurepip=yes", # install pip | |
"--with-computed-gotos=yes", | |
"--enable-optimizations", | |
"--enable-loadable-sqlite-extensions", | |
#"--with-dtrace", | |
"--with-valgrind", | |
#"--build=x86-64-redhat-linux-gnu " | |
#"--host=x86_64-redhat-linux-gnu " | |
#"--without-ensurepip " | |
]) | |
py_maj = int(this.version[0]) | |
def link_cmd(exe): | |
return 'ln -sfv {exe}{this.version.major} {build.install_path}/bin/{exe}' if py_maj > 2 else '' | |
env.REZ_BUILD_DOWNLOAD_CMD = 'wget %s' % url | |
env.REZ_BUILD_LINK_CMD_0 = link_cmd('python') | |
env.REZ_BUILD_LINK_CMD_1 = link_cmd('idle') | |
env.REZ_BUILD_LINK_CMD_2 = link_cmd('pydoc') | |
env.REZ_BUILD_LINK_CMD_3 = link_cmd('pip') | |
env.REZ_BUILD_LINK_CMD_4 = 'ln -sfv python{this.version.major}-config {build.install_path}/bin/python-config' | |
env.REZ_BUILD_LINK_CMD_5 = 'ln -sfv {build.install_path}/bin/python{this.version.major} {build.install_path}/bin/rez-python' | |
build_command = """ | |
$REZ_BUILD_DOWNLOAD_CMD | |
tar -xvf Python*.tgz --strip 1 | |
./configure $REZ_BUILD_CONFIGURE_OPTIONS | |
make install -j$REZ_BUILD_THREAD_COUNT VERBOSE=1 | |
$REZ_BUILD_LINK_CMD_0 | |
$REZ_BUILD_LINK_CMD_1 | |
$REZ_BUILD_LINK_CMD_2 | |
$REZ_BUILD_LINK_CMD_3 | |
$REZ_BUILD_LINK_CMD_4 | |
$REZ_BUILD_LINK_CMD_5 | |
$REZ_BUILD_INSTALL_PATH/bin/python -m pip install --upgrade pip | |
$REZ_BUILD_INSTALL_PATH/bin/python -m pip install --upgrade setuptools | |
""" | |
def pre_commands(): | |
env.PYTHONHOME.unset() | |
def commands(): | |
env.PATH.prepend("{root}/bin") | |
extension = {'osx': 'dylib', 'linux': 'so.1.0', 'win': 'dll'}[system.platform] | |
if building: | |
maj_min = this.pyver.strip('m') | |
maj = this.version.major | |
env.PYTHON_LIBRARY_VERSION = this.pyver | |
env.PYTHON_VERSION = maj_min | |
env.PYTHON_LDVERSION = this.pyver | |
# CMake hints | |
env.Python_ROOT = '{root}' | |
env.Python_FIND_STRATEGY = 'LOCATION' # prefer this python over python with higher ver number | |
env.Python_FIND_REGISTRY = 'NEVER' # prefer rez python over windows registry python | |
env.Python_FIND_FRAMEWORK = 'NEVER' # prefer rez python over osx framework python | |
env.Python_FIND_VIRTUALENV = 'STANDARD' # prefer rez python over virtualenv pythobn | |
env.Python_FIND_ABI = '"OFF" "ON" "ANY"' # debug, malloc, unicode | |
env.PYTHON_CMAKE_ARTIFACTS = ' '.join([ | |
'-DPython_INCLUDE_DIR={root}/include/python{this.pyver}', | |
'-DPython_EXECUTABLE={root}/bin/python{this.pyver}', | |
'-DPython_LIBRARY={root}/lib/libpython{this.pyver}.{extension}', | |
'-DPython{maj}_INCLUDE_DIR={root}/include/python{this.pyver}', | |
'-DPython{maj}_EXECUTABLE={root}/bin/python{this.pyver}', | |
'-DPython{maj}_LIBRARY={root}/lib/libpython{this.pyver}.{extension}', | |
'-DPython{maj}_NumPy_INCLUDE_DIR=$REZ_NUMPY_ROOT/python/numpy/core/include' if 'numpy' in resolve else '', | |
]) | |
env.PKG_CONFIG_PATH.prepend('{root}/include/pkgconfig') | |
env.LDFLAGS = '-L{root}/lib -Wl,-z,relro,-rpath={root}/lib $LDFLAGS' | |
for c in ['CFLAGS', 'CPPFLAGS', 'CXXFLAGS']: | |
setenv(c, '-I{root}/include $%s' % c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment