Skip to content

Commit

Permalink
Feat/update v0.4.1 (#132)
Browse files Browse the repository at this point in the history
* (feat) secp256k1 v0.4.0

* (feat) CFFI for new support

* (fix) Could not figure out why egg_info adds absolute paths. Prune them

* (feat) Use TOML project definition. Version bump to 19.0.0

* (feat) Use TOML project definition. Version bump to 19.0.0

* (feat) tox with python 3.12

* (fix) copy-paste fumble

* (fix) missing EOL

* (fix) relaxed setuptools constraint

* (fix) issues with mkdocstring

* (ref) remove unnecessary dependence

* (ref) remove deprecated functions

* (fea) selectable download using pkg-config

* (fix) path to header for windows

* (fix) don't remember why zzz

* (fix) bypass download for windows?

* (fix) bypass download for windows. lint check

* (fix) use pkgconfig to resolve lib location in windows?

* (fix) odd ruff fail

* (dbg) trying to figure out the windows annoyance

* (dbg) trying to figure out the windows annoyance

* (fix) ffi.dlopen() needs full lib name under windows?

* (dbg) linking on windows requires to prepend with 'lib', how to do that?

* (fix) linking on windows requires to prepend with 'lib'

* (fix) catch PackageNotFoundError when detecting system libsecp256k1

* (fix) wrong PackageNotFoundError?

* (dbg) libname on windows

* (fix) build for linking shared libsecp256k1 on windows

* Apply suggestions from code review

* (ref) Move library to API (instead of ABI)

* (fix) There's an issue with import pkgconfig on windows ...

* (fix) There's an issue with import pkgconfig on windows ...

* (fix) Turning in circles around windows ...

* (fix) Turning in circles around windows ...

* (fix) The issue is when building with setup.py (not TOML)

* (fix) remove pkgconfig, usr pkg-config instead?

* (fix) fmt

* (fix) subprocess fails if command exists with 1

* (fix) back to guessing game :\

* (ref) Let's have a pkg name, UNKNOWN-0.0.0 is too mysterious

* (fea) Update to SECP256K1 v0.4.1

* (fea) which part of "IMPORTANT: Keep in sync" did I not understand?

* (fix) broke the build with system libs :,(

* (ref) forgot to re-enable windows selection for libname change. deprec distutils

* (ref) update workflow to python 3.12. cibuildwheels to 2.16.2

* (ref) update workflow to python 3.12. cibuildwheel fails due to urllib3/ssl

* (ref) update workflow to python 3.12. cibuildwheel fails due to urllib3/ssl. upgrade to ubuntu-22.04?

* (bld) urllib3>2?

* (fix) missing Distribution for system lib case?

* (fix) retrofit cibuildwheel to 2.11.2 for linux (urllib3/ssl issue)

* (fix) why is it not finding the lib?

* (fix) why is it not finding the lib?

* (fix) why is it not finding the lib?

* (dbg) why is it not finding the lib?

* (dbg) too fast to simplify, header not found!

* (fix) path to headers found?

* (fix) byte to string

* (fix) lint/fmt

* (dbg) back to squre one on conda recipe ... it downloads :/

* (ref) silly, I don't need to commit, just patch-debug the recipe

* (ref) silly, I don't need to commit, just patch-debug the recipe

* (ref) silly, I don't need to commit, just patch-debug the recipe

* (ref) correct differences between  pkg-config and pkgconfig

* (fix) Do we need env?

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Ofek Lev <[email protected]>
  • Loading branch information
MementoRC and ofek authored Jan 11, 2024
1 parent 2dfea67 commit ff39dd7
Show file tree
Hide file tree
Showing 18 changed files with 696 additions and 462 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:
cancel-in-progress: true

env:
COINCURVE_UPSTREAM_REF: acf5c55ae6a94e5ca847e07def40427547876101
COINCURVE_UPSTREAM_REF: 1ad5185cd42c0636104129fcc9f6a4bf9c67cc40
COINCURVE_IGNORE_SYSTEM_LIB: '1'
CIBW_BEFORE_ALL_MACOS: ./.github/scripts/install-macos-build-deps.sh
CIBW_ENVIRONMENT_PASS_LINUX: >
Expand All @@ -38,7 +38,7 @@ jobs:
runs-on: ubuntu-latest

env:
PYTHON_VERSION: '3.10'
PYTHON_VERSION: '3.12'

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
name: Build Linux wheels
needs:
- test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
Expand All @@ -99,7 +99,7 @@ jobs:
- uses: actions/checkout@v3

- name: Build wheels
uses: pypa/cibuildwheel@v2.11.2
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_MACOS: x86_64

Expand All @@ -119,7 +119,7 @@ jobs:
- uses: actions/checkout@v3

- name: Build wheels
uses: pypa/cibuildwheel@v2.11.2
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_MACOS: arm64
COINCURVE_CROSS_HOST: aarch64-apple-darwin
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
platforms: arm64

- name: Build wheels
uses: pypa/cibuildwheel@v2.11.2
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_LINUX: aarch64

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include coincurve/py.typed
include setup_support.py
recursive-include _cffi_build *.py *.h
prune /*
graft libsecp256k1
2 changes: 2 additions & 0 deletions _cffi_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def _mk_ffi(sources, name='_libsecp256k1', **kwargs):
Source('secp256k1_extrakeys.h', '#include <secp256k1_extrakeys.h>'),
Source('secp256k1_recovery.h', '#include <secp256k1_recovery.h>'),
Source('secp256k1_schnorrsig.h', '#include <secp256k1_schnorrsig.h>'),
Source('secp256k1_ellswift.h', '#include <secp256k1_ellswift.h>'),
Source('secp256k1_preallocated.h', '#include <secp256k1_preallocated.h>'),
]

ffi = _mk_ffi(modules, libraries=['secp256k1'])
84 changes: 84 additions & 0 deletions _cffi_build/build_shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import argparse
import logging
import os
from collections import namedtuple
from typing import List

from cffi import FFI

logging.basicConfig(level=logging.INFO)

here = os.path.dirname(os.path.abspath(__file__))

Source = namedtuple('Source', ('h', 'include'))


def gather_sources_from_directory(directory: str) -> List[Source]:
"""
Gather source files from a given directory.
:param directory: The directory where source files are located.
:return: A list of Source namedtuples.
"""
sources = []
for filename in os.listdir(directory):
if filename.endswith('.h'):
include_line = f'#include <{filename}>'
sources.append(Source(filename, include_line))
return sorted(sources)


define_static_lib = """
#if defined(_WIN32)
# define SECP256K1_STATIC 1
# define SECP256K1_API extern __declspec(dllexport)
#endif
"""

define_shared_lib = """
#if defined(_WIN32)
# define SECP256K1_API extern __declspec(dllimport)
#endif
"""


def mk_ffi(sources: List[Source],
static_lib: str = '0',
name: str = '_libsecp256k1') -> FFI:
"""
Create an FFI object.
:param sources: A list of Source namedtuples.
:param libraries: A list of libraries to link against.
:param static_lib: Whether to generate a static lib in Windows.
:param name: The name of the FFI object.
:return: An FFI object.
"""
_ffi = FFI()
code = [define_static_lib] if static_lib == '1' else [define_shared_lib]

for source in sources:
with open(os.path.join(here, source.h)) as h:
logging.info(f' Including {source.h}...')
c_header = h.read().replace('SECP256K1_API', '')
_ffi.cdef(c_header)

code.append(source.include)

code.append('#define PY_USE_BUNDLED')
_ffi.set_source(name, '\n'.join(code))

return _ffi


if __name__ == '__main__':
logging.info('Starting CFFI build process...')
parser = argparse.ArgumentParser(description='Generate C code using CFFI.')
parser.add_argument('c_file', help='Generated C code filename.')
parser.add_argument('static_lib', help='Generate static lib in Windows.', default=False)
args = parser.parse_args()

modules = gather_sources_from_directory(here)
ffi = mk_ffi(modules, args.static_lib)
ffi.emit_c_code(args.c_file)
logging.info(f' Generated C code: {args.c_file}')
Loading

0 comments on commit ff39dd7

Please sign in to comment.