-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test cases: Unwanted RPATH overwrite and Failing to patch internal no…
…n-py extensions (#134) * Adding minimal test wheel based on PR #134 * Separate tests for each change in PR #134 #134 * non-py extension does not show in auditwheel show (ignoring assert) * Confirming tests on macOS * pytest in travis is weirdly triggering a manual test * Sorry! Forgot to install zlib-devel
- Loading branch information
1 parent
5945b3b
commit 6079b82
Showing
7 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Python 3 extension with non-Python library dependency | ||
|
||
This example was inspired from https://gist.github.com/physacco/2e1b52415f3a964ad2a542a99bebed8f | ||
|
||
This test extension builds two libraries: `_nonpy_rpath.*.so` and `lib_cryptexample.*.so`, where the `*` is a string composed of Python ABI versions and platform tags. | ||
|
||
The extension `lib_cryptexample.*.so` should be repaired by auditwheel because it is a needed library, even though it is not a Python extension. | ||
|
||
[Issue #136](https://github.com/pypa/auditwheel/issues/136) documents the underlying problem that this test case is designed to solve. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "testcrypt.h" | ||
#include <crypt.h> | ||
|
||
std::string crypt_something() { | ||
return std::string(crypt("will error out", NULL)); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
std::string crypt_something(void); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#define PY_SSIZE_T_CLEAN | ||
#include <Python.h> | ||
#include "extensions/testcrypt.h" | ||
|
||
// Module method definitions | ||
static PyObject* crypt_something(PyObject *self, PyObject *args) { | ||
return PyUnicode_FromString(crypt_something().c_str()); | ||
} | ||
|
||
/* Module initialization */ | ||
PyMODINIT_FUNC PyInit__nonpy_rpath(void) | ||
{ | ||
static PyMethodDef module_methods[] = { | ||
{"crypt_something", (PyCFunction)crypt_something, METH_NOARGS, "crypt_something."}, | ||
{NULL} /* Sentinel */ | ||
}; | ||
static struct PyModuleDef moduledef = { | ||
PyModuleDef_HEAD_INIT, | ||
"_nonpy_rpath", | ||
"_nonpy_rpath module", | ||
-1, | ||
module_methods, | ||
}; | ||
return PyModule_Create(&moduledef); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from ._nonpy_rpath import crypt_something | ||
|
||
__all__ = ["crypt_something"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import setuptools.command.build_ext | ||
from setuptools import setup, find_packages, Distribution | ||
from setuptools.extension import Extension, Library | ||
import os | ||
|
||
# despite its name, setuptools.command.build_ext.link_shared_object won't | ||
# link a shared object on Linux, but a static library and patches distutils | ||
# for this ... We're patching this back now. | ||
|
||
|
||
def always_link_shared_object( | ||
self, | ||
objects, | ||
output_libname, | ||
output_dir=None, | ||
libraries=None, | ||
library_dirs=None, | ||
runtime_library_dirs=None, | ||
export_symbols=None, | ||
debug=0, | ||
extra_preargs=None, | ||
extra_postargs=None, | ||
build_temp=None, | ||
target_lang=None, | ||
): | ||
self.link( | ||
self.SHARED_LIBRARY, | ||
objects, | ||
output_libname, | ||
output_dir, | ||
libraries, | ||
library_dirs, | ||
runtime_library_dirs, | ||
export_symbols, | ||
debug, | ||
extra_preargs, | ||
extra_postargs, | ||
build_temp, | ||
target_lang, | ||
) | ||
|
||
|
||
setuptools.command.build_ext.libtype = "shared" | ||
setuptools.command.build_ext.link_shared_object = always_link_shared_object | ||
|
||
libtype = setuptools.command.build_ext.libtype | ||
build_ext_cmd = Distribution().get_command_obj("build_ext") | ||
build_ext_cmd.initialize_options() | ||
build_ext_cmd.setup_shlib_compiler() | ||
|
||
|
||
def libname(name): | ||
""" gets 'name' and returns something like libname.cpython-37m-darwin.so""" | ||
filename = build_ext_cmd.get_ext_filename(name) | ||
fn, ext = os.path.splitext(filename) | ||
return build_ext_cmd.shlib_compiler.library_filename(fn, libtype) | ||
|
||
|
||
pkg_name = "nonpy_rpath" | ||
crypt_name = "_cryptexample" | ||
crypt_soname = libname(crypt_name) | ||
|
||
build_cmd = Distribution().get_command_obj("build") | ||
build_cmd.finalize_options() | ||
build_platlib = build_cmd.build_platlib | ||
|
||
|
||
def link_args(soname=None): | ||
args = [] | ||
if soname: | ||
args += ["-Wl,-soname," + soname] | ||
loader_path = "$ORIGIN" | ||
args += ["-Wl,-rpath," + loader_path] | ||
return args | ||
|
||
|
||
nonpy_rpath_module = Extension( | ||
pkg_name + "._nonpy_rpath", | ||
language="c++", | ||
sources=["nonpy_rpath.cpp"], | ||
extra_link_args=link_args(), | ||
extra_objects=[build_platlib + "/nonpy_rpath/" + crypt_soname], | ||
) | ||
crypt_example = Library( | ||
pkg_name + "." + crypt_name, | ||
language="c++", | ||
extra_compile_args=["-lcrypt"], | ||
extra_link_args=link_args(crypt_soname) + ["-lcrypt"], | ||
sources=["extensions/testcrypt.cpp"], | ||
) | ||
|
||
setup( | ||
name="nonpy_rpath", | ||
version="0.1.0", | ||
packages=find_packages(), | ||
description="Test package for nonpy_rpath", | ||
ext_modules=[crypt_example, nonpy_rpath_module], | ||
) |
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