Skip to content

Commit

Permalink
Replaces secp256k1 by coincurve
Browse files Browse the repository at this point in the history
secp256k1 is being replaced by coincurve, its most active fork,
refs #139 and refs #140
  • Loading branch information
AndreMiras committed Jul 28, 2018
1 parent 10af2d8 commit 69f2f24
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 2 deletions.
7 changes: 5 additions & 2 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package.name = pywallet
package.domain = com.github.andremiras

# (str) Source code where the main.py live
source.dir = src/
source.dir = src

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,md
Expand Down Expand Up @@ -63,6 +63,8 @@ requirements =
pyelliptic==1.5.7,
cffi,
libsecp256k1==355a38f,
asn1crypto==0.24.0,
coincurve==7.1.0,
qrcode,
contextlib2,
raven,
Expand All @@ -72,6 +74,7 @@ requirements =
pil,
https://github.com/AndreMiras/garden.zbarcam/archive/20171220.zip
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../kivy
Expand Down Expand Up @@ -235,7 +238,7 @@ android.arch = armeabi-v7a
# (str) The directory in which python-for-android should look for your own build recipes (if any)
#p4a.local_recipes =
p4a.local_recipes = ./src/python-for-android/recipes/
p4a.local_recipes = %(source.dir)s/python-for-android/recipes/
# (str) Filename to the hook for p4a
#p4a.hook =
Expand Down
48 changes: 48 additions & 0 deletions src/python-for-android/recipes/coincurve/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from pythonforandroid.recipe import PythonRecipe, CompiledComponentsPythonRecipe, CythonRecipe


class CoincurveRecipe(CompiledComponentsPythonRecipe):
version = '7.1.0'
url = 'https://github.com/ofek/coincurve/archive/{version}.tar.gz'
call_hostpython_via_targetpython = False
depends = [('python2', 'python3crystax'), 'setuptools',
'libffi', 'cffi', 'libsecp256k1']
patches = [
"cross_compile.patch", "drop_setup_requires.patch",
"find_lib.patch", "no-download.patch"]

def get_recipe_env(self, arch=None, with_flags_in_cc=True):
env = super(CoincurveRecipe, self).get_recipe_env(arch, with_flags_in_cc)
# sets linker to use the correct gcc (cross compiler)
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
# -Wl,-rpath -Wl,
libsecp256k1 = self.get_recipe('libsecp256k1', self.ctx)
libsecp256k1_dir = libsecp256k1.get_build_dir(arch.arch)
# env['LDSHARED'] = (
# env['CC'] +
# ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-rpath -Wl,' +
# os.path.join(libsecp256k1_dir, '.libs'))
env['LDFLAGS'] += ' -L{}'.format(os.path.join(libsecp256k1_dir, '.libs'))
# assert False, env['LDSHARED']
env['CFLAGS'] += ' -I' + os.path.join(libsecp256k1_dir, 'include')
# only keeps major.minor (discards patch)
python_version = self.ctx.python_recipe.version[0:3]
# required additional library and path for Crystax
if self.ctx.ndk == 'crystax':
ndk_dir_python = os.path.join(self.ctx.ndk_dir, 'sources/python/', python_version)
env['LDFLAGS'] += ' -L{}'.format(os.path.join(ndk_dir_python, 'libs', arch.arch))
env['LDFLAGS'] += ' -lpython{}m'.format(python_version)
# until `pythonforandroid/archs.py` gets merged upstream:
# https://github.com/kivy/python-for-android/pull/1250/files#diff-569e13021e33ced8b54385f55b49cbe6
env['CFLAGS'] += ' -I{}/include/python/'.format(ndk_dir_python)
else:
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python{}'.format(python_version)
env['LDFLAGS'] += " -lpython{}".format(python_version)
env['LDFLAGS'] += " -lsecp256k1"
return env


recipe = CoincurveRecipe()

Binary file not shown.
12 changes: 12 additions & 0 deletions src/python-for-android/recipes/coincurve/cross_compile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/setup.py b/setup.py
index c224fb2..bf925bd 100644
--- a/setup.py
+++ b/setup.py
@@ -182,6 +182,7 @@ class build_clib(_build_clib):
'--disable-dependency-tracking',
'--with-pic',
'--enable-module-recovery',
+ "--host=%s" % os.environ['TOOLCHAIN_PREFIX'],
'--disable-jni',
'--prefix',
os.path.abspath(self.build_clib),
12 changes: 12 additions & 0 deletions src/python-for-android/recipes/coincurve/drop_setup_requires.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/setup.py b/setup.py
index c224fb2..466e789 100644
--- a/setup.py
+++ b/setup.py
@@ -250,7 +250,6 @@ else:
def has_c_libraries(self):
return not has_system_lib()
setup_kwargs = dict(
- setup_requires=['cffi>=1.3.0', 'pytest-runner>=2.6.2'],
ext_package='coincurve',
cffi_modules=['_cffi_build/build.py:ffi'],
cmdclass={
13 changes: 13 additions & 0 deletions src/python-for-android/recipes/coincurve/find_lib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/setup_support.py b/setup_support.py
index e7a4f2e..72f0c4d 100644
--- a/setup_support.py
+++ b/setup_support.py
@@ -68,6 +69,8 @@ def build_flags(library, type_, path):


def _find_lib():
+ # we're picking up the recipe one
+ return True
from cffi import FFI
ffi = FFI()
try:
13 changes: 13 additions & 0 deletions src/python-for-android/recipes/coincurve/no-download.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/setup.py b/setup.py
index c224fb2..d5f6d1a 100644
--- a/setup.py
+++ b/setup.py
@@ -51,6 +51,8 @@ if [int(i) for i in setuptools_version.split('.', 2)[:2]] < [3, 3]:


def download_library(command):
+ # we will use the custom libsecp256k1 recipe
+ return
if command.dry_run:
return
libdir = absolute('libsecp256k1')

0 comments on commit 69f2f24

Please sign in to comment.