-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Cross-compiling of Python modules with and without distutils #9822
Conversation
Here's the list of packages I've had success with. The Waf-based ones will fail for you as I have extra hacks to deal with that. app-backup/rdiff-backup After making some tweaks and doing a full rebuild of the above, I have found that dev-python/sip now fails. I think it's a bad interaction between @mgorny's new patch and mine. I shall investigate. The rest is still good though. |
# Example value: | ||
# @CODE | ||
# /usr/bin/python2.7 | ||
# /var/tmp/portage/dev-python/pyblake2-1.2.3/temp/python2.7/bin/python2.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will break stuff. One of the points of PYTHON being the real path is that people actually hardcode the path given. If you change it, then I think we'll end up with having scripts referencing #!/var/tmp/portage/dev-python/pyblake2-1.2.3/temp/python2.7/bin/python2.7
installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true that I did not consider this but I believe our python-exec stuff prevents this from happening with shebangs. I grepped my entire test cross system and did not find a single instance of a path like that in any non-binary file. I suppose it could hypothetically appear in other places but I'll build the whole of dev-python to find them if that's what it takes. Unless you have a better idea? Having PYTHON point to the wrapper is not necessary for most packages, generally just the ones that don't use distutils, so we could tackle those individually but it would still be quite tedious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not dev-python/
I'm worried about, it's everything outside dev-python/
. Especially cheapo build systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll widen the search then. 😜 If cheapo build systems are installing scripts that are not handled by python-exec then that's probably a mistake in itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python-exec doesn't affect the shebangs in scripts themselves. They're preserved as-is and respected, in /usr/lib/python-exec/*
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this makes me think of adding a QA check to Portage to make sure thingies don't install stuff with generic shebangs there)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and please test it on regular system as well ;-). I'm not really opposed to those changes (though I haven't reviewed them completely) but I'm afraid this is going to cause silent retroactive breakage of stuff.
6cedcf1
to
6401119
Compare
Fixed dev-python/sip. Still looking into the other issue. |
After realising just how many Python packages there are, I tried to be smarter and grep'd for ebuilds where this might break. I did find some interesting cases, including several that are already broken because they use While the odd ebuild may need fixing with (or without!) this change, I tried to mitigate most cases by dealing with it in |
Would you mind adding cython to the list? |
cython isn't in the |
I meant to ask for |
That is very much outside the scope of this pull request. |
k, thanks for clarification. |
eclass/python-utils-r1.eclass
Outdated
ln -s "${sysrootlib}/${EPYTHON}"/_sysconfigdata*.py "${workdir}"/lib/_sysconfigdata.py || die | ||
|
||
# Use distutils/sysconfig from SYSROOT as parts of it have | ||
# GENTOO_LIBDIR baked in at Python build time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is GENTOO_LIBDIR the only issue here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those particular files, yes, I have just diff'd them to check. Does that mean we can avoid the wrapper issue? Not quite. You still have to override the file pointed at by _PYTHON_SYSCONFIGDATA_NAME
. This variable cannot be a full path so PYTHONPATH
is still needed. It only applies to Python 3 as 2 is hardcoded to load _sysconfigdata.py
. It also needs to be set via a wrapper because as soon as you set it within the Portage environment, Portage itself keels over. Maybe we could patch in support for a full path but I'm not sure how we'd prevent it from screwing with Portage.
I need to rebase this because your patch was reverted in the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so if we got rid of GENTOO_LIBDIR altogether will it reduce the needed patch or not at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the following call to ln.
676149c
to
cf4374b
Compare
I think this is good to go now. It hasn't changed much since my last big push a couple of months ago but I've made I did have a very long think about whether there was another way to deal with the |
It occurs to me that this is slightly broken for prefix users although the existing version is broken too. |
302ef15
to
3d32c32
Compare
Apologies @stefson, I only now realise that I was totally confused about cython, thinking it was some kind of alternative Python implementation. No idea why. I'm pleased to report that it already cross-compiles with these changes. |
I applied this pullrequest as a patch against the portage tree, which is at
|
Ebuild manifests are not included in the git repository but get added to the rsync repository later so patching like that would lead to this problem. A quick workaround is to use |
We already had python-config and python[23]-config but this additional one is needed now that ${PYTHON} points to our wrapper path because some project such as gobject-introspection call python-config using ${PYTHON}-config. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
This will deal with cases where the shebang is defined using ${PYTHON} or the location of python in the PATH. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Shebangs may need fixing on prefix systems or when cross-building but not at other times. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
dev-lang/python sometimes used to install the epython module into the wrong libdir (e.g. lib vs lib64). The earlier eclass changes actually break the build entirely as sysconfigdata is now sourced from within SYSROOT, where it may not even be installed yet. This therefore needs to be handled as a special case where sysconfigdata is sourced from within ED instead. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
We assumed Python to be located at /usr/$(get_libdir) in recent changes to this eclass but this has changed from Python 3.7. We now follow upstream, installing most files to /usr/lib, with only certain files, such as the pkg-config files, going into /usr/$(get_libdir). Signed-off-by: James Le Cuirot <chewi@gentoo.org>
This previously happened before checking but now exporting PYTHON involves creating the wrappers, which requires the requested Python to be installed. We could also drop all the calls to python_wrapper_setup as this is now already done when exporting PYTHON but it doesn't hurt to be explicit. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
python-any-r1 is not to be used in packages requiring Python at runtime. It may not even be installed. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
python-any-r1 does this for us but python_export does not. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Following the changes in python-utils-r1.eclass, Python is now needed in both BDEPEND and DEPEND. As distutils does not call our eclass helpers, we need to pass the correct include and library directories in setup.cfg. Unfortunately it is still hardcoded to add -I/usr/include/pythonX.X and -L/usr/lib but these appear after the SYSROOT paths so the build succeeds anyway. If a missing header or library were to cause it to fall back to the build host paths then it would most likely fail but it does not matter as it would have failed either way. Closes: https://bugs.gentoo.org/648652 Signed-off-by: James Le Cuirot <chewi@gentoo.org>
It is useful on its own when the build system calls setup.py for us, from a Makefile, for example. ${BUILD_DIR} is unlikely to be set in this instance so it falls back to ${PWD}. Signed-off-by: James Le Cuirot <chewi@gentoo.org>
The build system uses Python to detect the CPPFLAGS and LIBS but SYSROOT is not prepended. Signed-off-by: James Le Cuirot <chewi@gentoo.org> Package-Manager: Portage-2.3.49, Repoman-2.3.10
This fixes cross-compiling. Signed-off-by: James Le Cuirot <chewi@gentoo.org> Package-Manager: Portage-2.3.49, Repoman-2.3.10
It was broken under Python 3 (python3.6 vs python3.6m) and the new Python eclass fixes mean it's not needed any more. Package-Manager: Portage-2.3.53, Repoman-2.3.12 Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Pull request CI reportReport generated at: 2019-04-21 11:38 UTC No issues found |
@chewi Do these changes also fix wrong includes for python module builds? I really appreciate, that this Pull Request would fix the problem, that cross-emerge installs some |
I don't recall seeing the version problem specifically but it's a good idea to keep Python versions, among other things, in sync. I imagine these changes would fix that problem though. I'm still going to try and get these changes in but there's something I need to do first. |
I was talking about the problem that includes were used from the build system, instead of the built system. There were no Python version problems. Sorry if I was misleading. |
When I run When I run
An issue which is also mentioned here: I tried reverting the This happens when cross compiling a 32bit environment on a 64bit environment. Update: I got cat > "${workdir}/lib/sitecustomize.py" <<-_EOF_ || die
import sys
import site
sys.path, sys_path = sys.path[:1], sys.path[1:]
site.addsitedir('${pysysroot}/usr/lib/${EPYTHON}/site-packages')
sys.path.extend(sys_path)
sys.base_prefix = '${pysysroot}/usr'
sys.prefix = '${pysysroot}/usr'
_EOF_ and the following on top of
It still does not work for vim with python support. It seems that this is because it uses |
@deorder, I get the impression you haven't actually tried my work here. To be clear, despite the age of this pull request, it hasn't been merged yet. Changes have been requested and related parts of PMS need to be clarified first. Although this work tackles many of the common issues, the |
I am using everything that is included in this pull request. Using your modifications I was able to cross-compile a RPi3 64bit environment without issues where before it did not. When I build a RPi2 32bit environment however I get the |
Okay I found another method that works without modifying any eclass file. You can find it at: You can use it with my overlay at: Also have a look at the example profiles. Using this I was able to cross-compile a stage3 for the following targets: |
If you have an AMD threadripper - you can just rebuild everything using qemu. I am working on these images here. But I have to build I am going just to ignore new python cross compile eclass feature (for now) and return back to monkey patching of python itself. I am building cross image inside "host" native image, so I can do anything with this "host" python. Please do not forget about this pull request, people are watching. Thank you. |
Don't worry, I haven't. I was looking at it last week. @mgorny said it was too complicated and he was right because trying to fix the bits that have broken in the meantime is making my head spin. I have a rough idea for a simpler approach. |
I've just created more less reliable workaround for now. Python 3.6 already includes right workaround:
I am patching this native container, it will be removed.
After that
See full example here. |
Any news? |
Not forgotten but no news, sorry. |
This is obsolete now, mainly thanks to the wonderful gpep517. Meson currently still builds native extensions with the wrong filename, but I've almost fixed that. |
This probably won't be merged all in one go like this but it's mainly to get some initial feedback. I'm pretty happy with it now but I'm open to suggestions.