Skip to content

Commit

Permalink
(fix) remove pkgconfig, usr pkg-config instead?
Browse files Browse the repository at this point in the history
  • Loading branch information
MementoRC committed Dec 26, 2023
1 parent a2a0f8d commit f80097e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61", "cffi>=1.3.0", "pkgconfig"]
requires = ["setuptools>=61", "cffi>=1.3.0"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,11 @@ def build_extensions(self):
# ABI?: py_limited_api=True,
)

pkgconfig.configure_extension(extension, secp256k1_package, static=False)
package_info = pkgconfig.parse(secp256k1_package, static=False)
extension.extra_compile_args = [str(subprocess.check_output(['pkg-config', '--cflags-only-I', 'libsecp256k1']))] # noqa S603
extension.extra_link_args = [
str(subprocess.check_output(['pkg-config', '--libs-only-L', 'libsecp256k1'])), # noqa S603
str(subprocess.check_output(['pkg-config', '--libs-only-l', 'libsecp256k1'])), # noqa S603
]

# Apparently, the linker on Windows interprets -lxxx as xxx.lib, not libxxx.lib
for i, v in enumerate(extension.__dict__.get('extra_link_args')):
Expand All @@ -317,7 +320,7 @@ def build_extensions(self):
license='MIT OR Apache-2.0',

python_requires='>=3.7',
install_requires=['asn1crypto', 'cffi>=1.3.0', 'pkgconfig'],
install_requires=['asn1crypto', 'cffi>=1.3.0'],

packages=find_packages(exclude=('_cffi_build', '_cffi_build.*', 'libsecp256k1', 'tests')),
package_data=package_data,
Expand Down Expand Up @@ -357,5 +360,5 @@ def build_extensions(self):
'Topic :: Software Development :: Libraries',
'Topic :: Security :: Cryptography',
],
**setup_kwargs
**setup_kwargs
)
16 changes: 10 additions & 6 deletions setup_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def build_flags(library, type_, path):


def _find_lib():
pkgconfig = __import__('pkgconfig')

if 'COINCURVE_IGNORE_SYSTEM_LIB' in os.environ:
return False

Expand All @@ -72,16 +70,22 @@ def _find_lib():
sources=[os.path.join('coincurve', '_libsecp256k1.c')],
)

pkgconfig.configure_extension(extension, 'libsecp256k1', static=False)
package_info = pkgconfig.parse('libsecp256k1', static=False)
if subprocess.check_output(['pkg-config', '--exists', 'libsecp256k1']): # noqa S603
return False

extension.extra_compile_args = [str(subprocess.check_output(['pkg-config', '--cflags-only-I', 'libsecp256k1']))] # noqa S603
extension.extra_link_args = [
str(subprocess.check_output(['pkg-config', '--libs-only-L', 'libsecp256k1'])), # noqa S603
str(subprocess.check_output(['pkg-config', '--libs-only-l', 'libsecp256k1'])), # noqa S603
]

if os.name == 'nt' or sys.platform == 'win32':
ffi.dlopen('libsecp256k1-2')
else:
ffi.dlopen('secp256k1')

return os.path.exists(os.path.join(package_info['include_dirs'][0], 'secp256k1_ecdh.h'))
except (OSError, pkgconfig.pkgconfig.PackageNotFoundError):
return os.path.exists(os.path.join(extension.extra_compile_args[0][2:], 'secp256k1_ecdh.h'))
except OSError:
if 'LIB_DIR' in os.environ:
for path in glob.glob(os.path.join(os.environ['LIB_DIR'], '*secp256k1*')):
with suppress(OSError):
Expand Down

0 comments on commit f80097e

Please sign in to comment.