8000 Add Ethereum related recipes (#1068) · ikewang/python-for-android@2dcd3cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 2dcd3cf

Browse files
AndreMirasKeyWeeUsr
authored andcommitted
Add Ethereum related recipes (kivy#1068)
* Ethereum related recipes * ethash * libsecp256k1 * pycryptodome * pyethereum * pysha3 * scrypt * secp256k1 See https://github.com/ethereum * Added explicit version For pycryptodome, pyethereum and pysha3
1 parent 06f981f commit 2dcd3cf

File tree

12 files changed

+212
-0
lines changed

12 files changed

+212
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonforandroid.recipe import PythonRecipe
2+
3+
4+
class EthashRecipe(PythonRecipe):
5+
6+
url = 'https://github.com/ethereum/ethash/archive/master.zip'
7+
8+
depends = ['python2', 'setuptools']
9+
10+
11+
recipe = EthashRecipe()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from pythonforandroid.toolchain import shprint, current_directory
2+
from pythonforandroid.recipe import Recipe
3+
from multiprocessing import cpu_count
4+
from os.path import exists
5+
import sh
6+
7+
8+
class LibSecp256k1Recipe(Recipe):
9+
10+
url = 'https://github.com/bitcoin-core/secp256k1/archive/master.zip'
11+
12+
def build_arch(self, arch):
13+
super(LibSecp256k1Recipe, self).build_arch(arch)
14+
env = self.get_recipe_env(arch)
15+
with current_directory(self.get_build_dir(arch.arch)):
16+
if not exists('configure'):
17+
shprint(sh.Command('./autogen.sh'), _env=env)
18+
shprint(
19+
sh.Command('./configure'),
20+
'--host=' + arch.toolchain_prefix,
21+
'--prefix=' + self.ctx.get_python_install_dir(),
22+
'--enable-shared',
23+
'--enable-module-recovery',
24+
'--enable-experimental',
25+
'--enable-module-ecdh',
26+
_env=env)
27+
shprint(sh.make, '-j' + str(cpu_count()), _env=env)
28+
libs = ['.libs/libsecp256k1.so']
29+
self.install_libs(arch, *libs)
30+
31+
32+
recipe = LibSecp256k1Recipe()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonforandroid.recipe import PythonRecipe
2+
3+
4+
class PycryptodomeRecipe(PythonRecipe):
5+
version = 'v3.4.6'
6+
url = 'https://github.com/Legrandin/pycryptodome/archive/{version}.tar.gz'
7+
8+
depends = ['python2', 'setuptools']
9+
10+
11+
recipe = PycryptodomeRecipe()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pythonforandroid.recipe import PythonRecipe
2+
3+
4+
class PyethereumRecipe(PythonRecipe):
5+
version = 'v1.6.1'
6+
url = 'https://github.com/ethereum/pyethereum/archive/{version}.tar.gz'
7+
8+
depends = [
9+
'python2', 'setuptools', 'pycryptodome', 'pysha3', 'ethash', 'scrypt'
10+
]
11+
12+
call_hostpython_via_targetpython = False
13+
14+
15+
recipe = PyethereumRecipe()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonforandroid.recipe import PythonRecipe
2+
3+
4+
class Pysha3Recipe(PythonRecipe):
5+
version = '1.0.2'
6+
url = 'https://github.com/tiran/pysha3/archive/{version}.tar.gz'
7+
8+
depends = ['python2', 'setuptools']
9+
10+
11+
recipe = Pysha3Recipe()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from pythonforandroid.toolchain import CythonRecipe
2+
from os.path import join
3+
4+
5+
class ScryptRecipe(CythonRecipe):
6+
7+
url = 'https://bitbucket.org/mhallin/py-scrypt/get/default.zip'
8+
9+
depends = ['python2', 'setuptools', 'openssl']
10+
11+
call_hostpython_via_targetpython = False
12+
13+
patches = ["remove_librt.patch"]
14+
15+
def get_recipe_env(self, arch, with_flags_in_cc=True):
16+
"""
17+
Adds openssl recipe to include and library path.
18+
"""
19+
env = super(ScryptRecipe, self).get_recipe_env(arch, with_flags_in_cc)
20+
openssl_build_dir = self.get_recipe(
21+
'openssl', self.ctx).get_build_dir(arch.arch)
22+
print("openssl_build_dir:", openssl_build_dir)
23+
env['CC'] = '%s -I%s' % (env['CC'], join(openssl_build_dir, 'include'))
24+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
25+
self.ctx.get_libs_dir(arch.arch) +
26+
'-L{}'.format(self.ctx.libs_dir)) + ' -L{}'.format(
27+
openssl_build_dir)
28+
return env
29+
30+
31+
recipe = ScryptRecipe()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff -r 91d194b6a6bd setup.py
2+
--- a/setup.py Sat Sep 17 15:29:49 2016 +0200
3+
+++ b/setup.py Mon May 29 07:30:24 2017 +0000
4+
@@ -13,7 +13,6 @@
5+
6+
if sys.platform.startswith('linux'):
7+
define_macros = [('HAVE_CLOCK_GETTIME', '1'),
8+
- ('HAVE_LIBRT', '1'),
9+
('HAVE_POSIX_MEMALIGN', '1'),
10+
('HAVE_STRUCT_SYSINFO', '1'),
11+
('HAVE_STRUCT_SYSINFO_MEM_UNIT', '1'),
12+
@@ -21,7 +20,7 @@
13+
('HAVE_SYSINFO', '1'),
14+
('HAVE_SYS_SYSINFO_H', '1'),
15+
('_FILE_OFFSET_BITS', '64')]
16+
- libraries = ['crypto', 'rt']
17+
+ libraries = ['crypto']
18+
CFLAGS.append('-O2')
19+
elif sys.platform.startswith('win32'):
20+
define_macros = [('inline', '__inline')]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from os.path import join
2+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
3+
4+
5+
class Secp256k1Recipe(CompiledComponentsPythonRecipe):
6+
7+
url = 'https://github.com/ludbb/secp256k1-py/archive/master.zip'
8+
9+
call_hostpython_via_targetpython = False
10+
11+
depends = [
12+
'openssl', 'hostpython2', 'python2', 'setuptools',
13+
'libffi', 'cffi', 'libsecp256k1']
14+
15+
patches = ["cross_compile.patch", "pkg-config.patch", "find_lib.patch"]
16+
17+
def get_recipe_env(self, arch=None):
18+
env = super(Secp256k1Recipe, self).get_recipe_env(arch)
19+
libsecp256k1 = self.get_recipe('libsecp256k1', self.ctx)
20+
libsecp256k1_dir = libsecp256k1.get_build_dir(arch.arch)
21+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
22+
env['CFLAGS'] = ' -I' + join(libsecp256k1_dir, 'include')
23+
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
24+
env['LDSHARED'] = env['CC'] + \
25+
' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
26+
env['LDFLAGS'] += ' -L{}'.format(libsecp256k1_dir)
27+
# TODO: hardcoded Python version
28+
env['LDFLAGS'] += " -landroid -lpython2.7 -lsecp256k1"
29+
return env
30+
31+
32+
recipe = Secp256k1Recipe()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/setup.py b/setup.py
2+
index bba4bce..b86b369 100644
3+
--- a/setup.py
4+
+++ b/setup.py
5+
@@ -191,6 +192,7 @@ class build_clib(_build_clib):
6+
"--disable-dependency-tracking",
7+
"--with-pic",
8+
"--enable-module-recovery",
9+
+ "--host=%s" % os.environ['TOOLCHAIN_PREFIX'],
10+
"--prefix",
11+
os.path.abspath(self.build_clib),
12+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/setup.py b/setup.py
2+
index bba4bce..bfffbbc 100644
3+
--- a/setup.py
4+
+++ b/setup.py
5+
@@ -263,7 +263,6 @@ setup(
6+
author_email='lud@tutanota.com',
7+
license='MIT',
8+
9+
- setup_requires=['cffi>=1.3.0', 'pytest-runner==2.6.2'],
10+
install_requires=['cffi>=1.3.0'],
11+
tests_require=['pytest==2.8.7'],
12+

0 commit comments

Comments
 (0)
0