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

Difficult to cross-compile (e.g. Yocto) #104

Closed
cmcqueen opened this issue Sep 1, 2017 · 8 comments
Closed

Difficult to cross-compile (e.g. Yocto) #104

cmcqueen opened this issue Sep 1, 2017 · 8 comments

Comments

@cmcqueen
Copy link
Contributor

cmcqueen commented Sep 1, 2017

  • uvloop version: 0.8.0
  • Python version: 3.5.2
  • Platform: Cross-compile build using Yocto for BeagleBone Black (ARM)
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: N/A

I am trying to make a Yocto bitbake recipe to build uvloop. At the build_ext step it gives an error for the libuv ./configure call, saying for cross-compilation it needs the --host parameter specified.

It might be possible to use the --use-system-libuv option, but at the moment Yocto doesn't support custom options for the build_ext step.

I applied the following patch to work around this:

From 56604f7720089da7d9afd43825fc29f006a0e4bf Mon Sep 17 00:00:00 2001
From: Craig McQueen <craig.mcqueen@innerrange.com>
Date: Thu, 31 Aug 2017 16:31:17 +1000
Subject: [PATCH] Allow for cross-compile of libuv

If HOST_SYS environment variable is defined, then call ./configure with
--host parameter set to HOST_SYS value.
---
 setup.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index ae9a65a..ad474e8 100644
--- a/setup.py
+++ b/setup.py
@@ -226,8 +226,12 @@ class uvloop_build_ext(build_ext):
              'Makefile.am', 'Makefile.in'],
             cwd=LIBUV_BUILD_DIR, env=env, check=True)
 
+        if 'HOST_SYS' in env:
+            cmd = ['./configure', '--host=' + env['HOST_SYS']]
+        else:
+            cmd = ['./configure']
         subprocess.run(
-            ['./configure'],
+            cmd,
             cwd=LIBUV_BUILD_DIR, env=env, check=True)
 
         j_flag = '-j{}'.format(os.cpu_count() or 1)
-- 
2.14.1

But then I had another problem, which is when I tried to import uvloop, I got an error regarding an unresolved symbol pthread_atfork. I used the following patch to resolve this:

From abb18a622d5c3c341fd64da46b243d2734cbe2c8 Mon Sep 17 00:00:00 2001
From: Craig McQueen <craig.mcqueen@innerrange.com>
Date: Thu, 31 Aug 2017 17:25:13 +1000
Subject: [PATCH] Specify pthread library dependency for uvloop.loop extension

---
 setup.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/setup.py b/setup.py
index ad474e8..3eed39e 100644
--- a/setup.py
+++ b/setup.py
@@ -293,6 +293,9 @@ setup(
             sources=[
                 "uvloop/loop.pyx",
             ],
+            libraries=[
+                "pthread",
+            ],
             extra_compile_args=CFLAGS
         ),
     ],
-- 
2.14.1
@cmcqueen
Copy link
Contributor Author

cmcqueen commented Sep 1, 2017

My Yocto bitbake recipe python3-uvloop_0.8.0.bb is as follows:

DESCRIPTION = "Fast implementation of asyncio event loop on top of libuv"
HOMEPAGE = "https://pypi.python.org/pypi/uvloop"
SECTION = "devel/python"
LICENSE = "MIT & Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE-MIT;md5=3bd0b2e751776b370b2151ac508af939 \
                    file://LICENSE-APACHE;md5=dc498442db12459256eff4dcbc80c32f"

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

SRCNAME = "uvloop"

SRC_URI = "https://files.pythonhosted.org/packages/source/u/${SRCNAME}/${SRCNAME}-${PV}.tar.gz"

SRC_URI[md5sum] = "279163a7b8f39dc15007cf76e3a92c02"
SRC_URI[sha256sum] = "2c22f1f0b6e00e99f5ee635993e5f26418e740bd26f1214cf78c70f237eec06b"

SRC_URI += "file://0001-Allow-for-cross-compile-of-libuv.patch"
SRC_URI += "file://0001-Specify-pthread-library-dependency-for-uvloop.loop-e.patch"

S = "${WORKDIR}/${SRCNAME}-${PV}"

DEPENDS = "${PYTHON_PN}-cython-native"

BBCLASSEXTEND = "native"

inherit setuptools3

do_compile_prepend() {
    export HOST_SYS=${HOST_SYS}
}

do_install_prepend() {
    export HOST_SYS=${HOST_SYS}
}

I'm currently using Yocto morty branch.

@cmcqueen
Copy link
Contributor Author

cmcqueen commented Sep 1, 2017

I'm not sure if those patches are suitable for incorporating into the mainline code. If you think they are, I could submit a pull request.

@1st1
Copy link
Member

1st1 commented Nov 10, 2017

357cb60 should fix the "unresolved symbol pthread_atfork" problem.

@1st1
Copy link
Member

1st1 commented Nov 10, 2017

Please submit a PR to add HOST_SYS env option. Although I'd rename it to LIBUV_CONFIGURE_HOST.

@1st1
Copy link
Member

1st1 commented Nov 13, 2017

Will be in the next uvloop release (0.9.0) soon.

@1st1 1st1 closed this as completed Nov 13, 2017
@1st1
Copy link
Member

1st1 commented Nov 27, 2017

Please try uvloop v0.9.0.

@cmcqueen
Copy link
Contributor Author

cmcqueen commented Dec 7, 2017

I've tried uvloop v0.9.0, and it fixes the two issues nicely. Thanks very much!

@MSezai
Copy link

MSezai commented Aug 22, 2024

Is there a solution for uvloop_0.20.0.bb ?

when I try to run this in kirkstone:

SUMMARY = "Fast implementation of asyncio event loop on top of libuv"
HOMEPAGE = "http://github.com/MagicStack/uvloop"
LICENSE = "MIT & Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE-MIT;md5=489c8bc34154e4b59f5c58e664f7d70f
file://LICENSE-APACHE;md5=bb92739ddad0a2811957bd98bdb90474"

PYPI_PACKAGE = "uvloop"

inherit pypi setuptools3

SRC_URI[md5sum] = "c3395ddc1746e2bf4b2987d88c4707e8"
SRC_URI[sha256sum] = "4603ca714a754fc8d9b197e325db25b2ea045385e8a3ad05d3463de725fdf469"

I get the error:

checking whether we are cross compiling... configure: error: in /home/dev/yocto/build/tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/python3-uvloop/0.20.0-r0/uvloop-0.20.0/build/libuv-x86_64': | configure: error: cannot run C compiled programs. | If you meant to cross compile, use --host'.

File "/home/dev/yocto/build/tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/python3-uvloop/0.20.0-r0/recipe-sysroot-native/usr/lib/python3.10/subprocess.py", line 526, in run
| raise CalledProcessError(retcode, process.args,
| subprocess.CalledProcessError: Command '['./configure']' returned non-zero exit status 77.
| ERROR: 'python3 setup.py bdist_wheel ' execution failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants