Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Transition to CMake #152

Merged
merged 54 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
28714e6
(ref) use logging module. add CMake from _build_clib
MementoRC Mar 9, 2024
841a3af
(feat) add shared and static linker
MementoRC Mar 9, 2024
014c574
(feat) add helper fct for pkg-config
MementoRC Mar 9, 2024
cf316c0
(feat) add Extension build. use for non-Window
MementoRC Mar 10, 2024
59c64ac
(fix) gcc failure
MementoRC Mar 10, 2024
978f738
(fix) correct build_shared.py for static/shared (need to rename file …
MementoRC Mar 11, 2024
7236098
(fea) add pkg-config helpers
MementoRC Mar 11, 2024
ef73b34
(fea) wrap within main() to avoid double-run of build steps
MementoRC Mar 11, 2024
6153647
(ref) fine-tune workflow
MementoRC Mar 11, 2024
ca593a7
(fix) remove non-existing python-dev
MementoRC Mar 11, 2024
f7e97e6
(fix) no relative path to load external shared lib on unix
MementoRC Mar 12, 2024
0b41425
(cos) add comments about specifying DYLD_LIBRARY_PATH
MementoRC Mar 12, 2024
064c12b
(cos) clean-up make reference
MementoRC Mar 13, 2024
bcf1bf7
FEAT: Refactor to src-layout (#153)
MementoRC Mar 13, 2024
0079c19
(ref) use logging module. add CMake from _build_clib
MementoRC Mar 9, 2024
952ec65
Merge branch 'master' into feat/add-cmake-extension
MementoRC Mar 14, 2024
39c8cb1
(fix) src-layout editable dirs are in /tmp: first-pass. remove duplic…
MementoRC Mar 14, 2024
dccbcc0
(ref) remove previous clib/ext. add native builds for windows
MementoRC Mar 14, 2024
b34284c
(ref) Windows add 'Releases'. use a more robust method to find pkgcon…
MementoRC Mar 14, 2024
6b4868e
(ref) use next
MementoRC Mar 14, 2024
2a35b9b
(dbg) 32/64 shared missing something (though ARM64 pass)
MementoRC Mar 14, 2024
f23676e
(dbg) install shared in build.lib for shared
MementoRC Mar 14, 2024
5e2159b
(ref) remove unused x-compile script for windows
MementoRC Mar 15, 2024
21dcc29
(ref) COINCURVE_CROSS_HOST not needed for macos arm
MementoRC Mar 15, 2024
b4ee691
(ref) remove unused build.py (will rename build_shared)
MementoRC Mar 15, 2024
078e4c9
(ref) rename build_shared to build (it builds both static/shared)
MementoRC Mar 15, 2024
cae1983
(ref) used wrong class for build_ext
MementoRC Mar 15, 2024
0ebe4d1
(fix) wrong version of checkout
MementoRC Mar 15, 2024
e0617b7
(ref) replace log with logging
MementoRC Mar 15, 2024
d1b643a
(ref) remove unused build_ext class
MementoRC Mar 15, 2024
7430eb4
(ref) remove BUILDING_FOR_WINDOWS
MementoRC Mar 15, 2024
cae96d9
(ref) remove detect_dll
MementoRC Mar 15, 2024
4c94d91
(cos) cleanup import
MementoRC Mar 15, 2024
078b0ec
(ref) refactor Distribution and Extension
MementoRC Mar 15, 2024
5c9a245
(ref) refactor Distribution and Extension
MementoRC Mar 15, 2024
9756f53
(ref) streamline build workflow. complement publish
MementoRC Mar 15, 2024
a4a7cf3
(fix) typos in naming convention
MementoRC Mar 15, 2024
cf5e958
(ref) simplify _find_lib
MementoRC Mar 16, 2024
d3ae466
(ref) remove unused windows_libsecp256k1.py
MementoRC Mar 17, 2024
66f3bca
(ref) integrate setup_tools package
MementoRC Mar 17, 2024
605a792
(fix) logic for pkgconfig file
MementoRC Mar 18, 2024
82528ee
(fix) remove setup_support.
MementoRC Mar 18, 2024
28f1fb2
(fix) implement update_pkg_config
MementoRC Mar 18, 2024
7dbdc07
Merge remote-tracking branch 'upstream/master' into feat/add-cmake-ex…
MementoRC Mar 18, 2024
fc579dc
(fix) lint
MementoRC Mar 18, 2024
4e34807
Merge remote-tracking branch 'origin/master' into feat/add-cmake-exte…
MementoRC Mar 18, 2024
3fe50be
(fix) wrong arch str for windows
MementoRC Mar 18, 2024
93fa4e2
(fix) straggling artifact v3. include download fix
MementoRC Mar 18, 2024
2f2ab83
(ref) straggling 2.16.5
MementoRC Mar 18, 2024
ea8ca97
(fix) read autocomplete before tab, AI doesn't have a clue
MementoRC Mar 18, 2024
c1917e1
(fix) update_pkgconfig fails when path is None
MementoRC Mar 19, 2024
152d08e
Merge remote-tracking branch 'upstream/master' into feat/add-cmake-ex…
MementoRC Mar 19, 2024
2fa5438
Merge remote-tracking branch 'upstream/master' into feat/add-cmake-ex…
MementoRC Mar 19, 2024
5288cb8
Merge remote-tracking branch 'upstream/master' into feat/add-cmake-ex…
MementoRC Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .github/scripts/build-windows-wheels.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .github/scripts/install-macos-build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ brew update
brew outdated openssl || brew upgrade openssl

# Install packages needed to build lib-secp256k1
for pkg in automake libtool pkg-config; do
for pkg in pkg-config; do
brew list $pkg > /dev/null || brew install $pkg
brew outdated --quiet $pkg || brew upgrade $pkg
done
102 changes: 87 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ concurrency:
env:
COINCURVE_UPSTREAM_REF: 1ad5185cd42c0636104129fcc9f6a4bf9c67cc40
COINCURVE_IGNORE_SYSTEM_LIB: '1'
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8"
CIBW_BEFORE_ALL_MACOS: ./.github/scripts/install-macos-build-deps.sh
# Only 'SHARED' is recognized, any other string means 'not SHARED'
COINCURVE_SECP256K1_BUILD: 'STATIC'
CIBW_ENVIRONMENT_PASS_LINUX: >
COINCURVE_UPSTREAM_REF
COINCURVE_IGNORE_SYSTEM_LIB
COINCURVE_SECP256K1_BUILD
CIBW_PROJECT_REQUIRES_PYTHON: '>=3.8'
CIBW_BEFORE_ALL_MACOS: ./.github/scripts/install-macos-build-deps.sh
CIBW_TEST_REQUIRES: pytest pytest-benchmark
CIBW_TEST_COMMAND: >
python -c
Expand Down Expand Up @@ -113,29 +116,98 @@ jobs:
if-no-files-found: error

macos-wheels-arm:
name: Build macOS wheels for ARM
name: Build macOS wheels for ARM (Native)
needs:
- test
runs-on: macos-latest
runs-on: macos-14

steps:
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.17
env:
CIBW_ARCHS_MACOS: arm64
COINCURVE_CROSS_HOST: aarch64-apple-darwin
CFLAGS: -target arm64-apple-macos11

- uses: actions/upload-artifact@v4
with:
name: artifact-macos-wheels-arm
path: wheelhouse/*.whl
if-no-files-found: error

windows-wheels-and-sdist:
name: Build Windows wheels and source distribution
windows-wheels-x86_64:
name: Build Windows wheels AMD64
needs:
- test
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Build wheels
uses: pypa/cibuildwheel@v2.17
env:
CIBW_ARCHS_WINDOWS: 'AMD64'
CIBW_BEFORE_ALL: choco install -y --no-progress --no-color cmake>=3.28 pkgconfiglite

- uses: actions/upload-artifact@v4
with:
name: artifact-windows-wheels-x86_64
path: wheelhouse/*.whl
if-no-files-found: error

windows-wheels-x86:
name: Build Windows wheels x86
needs:
- test
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Build wheels
uses: pypa/cibuildwheel@v2.17
env:
COINCURVE_CROSS_HOST: 'x86'
CIBW_ARCHS_WINDOWS: 'x86'
CIBW_BEFORE_ALL: choco install -y --no-progress --no-color cmake>=3.28 pkgconfiglite

- uses: actions/upload-artifact@v4
with:
name: artifact-windows-wheels-x86
path: wheelhouse/*.whl
if-no-files-found: error

windows-wheels-arm:
name: Build Windows wheels for ARM64
needs:
- test
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.17
env:
COINCURVE_CROSS_HOST: 'arm64'
CIBW_ARCHS_WINDOWS: 'ARM64'
CIBW_BEFORE_ALL: choco install -y --no-progress --no-color cmake>=3.28 pkgconfiglite

- uses: actions/upload-artifact@v4
with:
name: artifact-windows-wheels-arm
path: wheelhouse/*.whl
if-no-files-found: error

sdist:
name: Build source distribution
needs:
- test
runs-on: ubuntu-latest
Expand All @@ -149,12 +221,9 @@ jobs:
- name: Build source distribution
run: python -m build --sdist

- name: Build Windows wheels
run: ./.github/scripts/build-windows-wheels.sh

- uses: actions/upload-artifact@v4
with:
name: artifact-windows-wheels-and-sdist
name: artifact-sdist
path: dist/*
if-no-files-found: error

Expand Down Expand Up @@ -193,7 +262,10 @@ jobs:
- linux-wheels-standard
- macos-wheels-x86_64
- macos-wheels-arm
- windows-wheels-and-sdist
- windows-wheels-x86_64
- windows-wheels-x86
- windows-wheels-arm
- sdist
- linux-wheels-arm
runs-on: ubuntu-latest
if: >
Expand Down
69 changes: 55 additions & 14 deletions _cffi_build/build.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,77 @@
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 _mk_ffi(sources, name='_libsecp256k1', **kwargs):
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) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
# define SECP256K1_STATIC 1
#endif
"""


def mk_ffi(sources: List[Source],
static_lib: bool = False,
name: str = '_libsecp256k1') -> FFI:
"""
Create an FFI object.

:param sources: A list of Source namedtuples.
: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 = []
code = [define_static_lib] if static_lib else []

logging.info(f' Static {static_lib}...')
for source in sources:
with open(os.path.join(here, source.h)) as h:
_ffi.cdef(h.read())
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), **kwargs)
_ffi.set_source(name, '\n'.join(code))

return _ffi


modules = [
Source('secp256k1.h', '#include <secp256k1.h>'),
Source('secp256k1_ecdh.h', '#include <secp256k1_ecdh.h>'),
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>'),
]
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='0', type=str)
args = parser.parse_args()

ffi = _mk_ffi(modules, libraries=['secp256k1'])
modules = gather_sources_from_directory(here)
ffi = mk_ffi(modules, args.static_lib == '1')
ffi.emit_c_code(args.c_file)
logging.info(f' Generated C code: {args.c_file}')
84 changes: 0 additions & 84 deletions _cffi_build/build_shared.py

This file was deleted.

Loading
Loading