Skip to contentSkip to conversation

Yocto Python Issue

DISCUSSION Darcy Watkins 2 participants 2 messages Mar 6, 2014 – Mar 16, 2015

lore
Share & tools
lore
#0 lore raw

Hi,

This is followup to...

https://lists.yoctoproject.org/pipermail/yocto/2014-February/018209.html

...for others dealing with 'cross-python' like issues.

This is the python equivalent to cross compiling. I found a number of resources related to python cross-compiling and even a pycon talk where the presenter covers the hurdles involved to get distutil to “cross” build as well.

http://stackoverflow.com/questions/19120938/cross-compiling-python-2-7-4
http://www.droboports.com/app-repository/python-2-7-5
http://www.youtube.com/watch?v=nhr-YErfW8k
http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html

Fortunately the Yocto/OpenEmbedded folk have these sorted out - you just have to look in the right place.

My resolution was to ensure that the correct native python is used. There is the host's native python that is used to run the tools of the build system (including 'bitbake' itself).

Then there is a python-native that gets symlinked as 'nativepython' into the native sysroot. This 'nativepython' is setup sort of as a crosscompiler python if you want to compile .py to .pyo/.pyc and put the compiled files on your target.

Finally, there is the python that runs on the target system.

---

My headache was due to using the host's native python (actually ADT bundled python on CentOS) when I needed to use 'nativepython'. With a small amount of shoehorn work, I was readily able to get make rules and recipes to swig wrap some libraries as python extensions and to build using nativepython.

There are a couple of variables you have to ensure get passed/exported through your make to be available to 'nativepython' to point it to the right sysroot locations of your target.

BUILD_SYS=${BUILD_SYS}
HOST_SYS=${HOST_SYS}
STAGING_LIBDIR=${STAGING_LIBDIR}
STAGING_INCDIR=${STAGING_INCDIR}

If you are using swig-native, you also need to use "-I" to get your target sysroot include directories to it as well.

Signature · 12 lines
Regards,

Darcy

---

Darcy Watkins
Senior Software Developer
In Motion Technology, Inc.
350-625 Agnes St. New Westminster, BC
Canada, V3M 5Y4
[P1]
#1 lore raw

Darcy,

Thank you for this post, it just saved me more hours of headache. I was struggling to understand the purpose of EXTRANATIVEPATH, and pythonnative.bbclass with perlnative.bbclass. Well, there are a few other things when grep EXTRANATIVEPATH for, but I think I am happy to hear the reason for this to exist, which your post and Richard Purdie's commit message [1] are starting to explain.

[1]:
http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?h=5157c85776bb8bd7315ef42e6e622aae27ebc79e

If anyone has more to say on the motivation for these things to exist, please do let us know. To me this seemed like a terrible hack of sorts at first, now I can (sort of) see the some reason for it.

Cheers,
—
Ilya Dmitrichenko

Quoted 73 lines · Darcy Watkins

Hi,

This is followup to...

https://lists.yoctoproject.org/pipermail/yocto/2014-February/018209.html

...for others dealing with 'cross-python' like issues.

This is the python equivalent to cross compiling. I found a number of resources related to python cross-compiling and even a pycon talk where the presenter covers the hurdles involved to get distutil to “cross” build as well.

http://stackoverflow.com/questions/19120938/cross-compiling-python-2-7-4
http://www.droboports.com/app-repository/python-2-7-5
http://www.youtube.com/watch?v=nhr-YErfW8k
http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html

Fortunately the Yocto/OpenEmbedded folk have these sorted out - you just have to look in the right place.

My resolution was to ensure that the correct native python is used. There is the host's native python that is used to run the tools of the build system (including 'bitbake' itself).

Then there is a python-native that gets symlinked as 'nativepython' into the native sysroot. This 'nativepython' is setup sort of as a crosscompiler python if you want to compile .py to .pyo/.pyc and put the compiled files on your target.

Finally, there is the python that runs on the target system.

---

My headache was due to using the host's native python (actually ADT bundled python on CentOS) when I needed to use 'nativepython'. With a small amount of shoehorn work, I was readily able to get make rules and recipes to swig wrap some libraries as python extensions and to build using nativepython.

There are a couple of variables you have to ensure get passed/exported through your make to be available to 'nativepython' to point it to the right sysroot locations of your target.

BUILD_SYS=${BUILD_SYS}
HOST_SYS=${HOST_SYS}
STAGING_LIBDIR=${STAGING_LIBDIR}
STAGING_INCDIR=${STAGING_INCDIR}

If you are using swig-native, you also need to use "-I" to get your target sysroot include directories to it as well.

--

Regards,

Darcy

---

Darcy Watkins
Senior Software Developer
In Motion Technology, Inc.
350-625 Agnes St. New Westminster, BC
Canada, V3M 5Y4
[P1]

_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto