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

python plugin fails to build on aarch64 (oracle linux) #1164

Closed
unxed opened this issue Jan 1, 2022 · 59 comments
Closed

python plugin fails to build on aarch64 (oracle linux) #1164

unxed opened this issue Jan 1, 2022 · 59 comments

Comments

@unxed
Copy link
Contributor

unxed commented Jan 1, 2022

[ 99%] Generating _pyfar.cpp
Traceback (most recent call last):
  File "/home/opc/far2l/python/src/pythongen.py", line 43, in <module>
    ffi.cdef(data, packed=True)
  File "/usr/lib64/python3.6/site-packages/cffi/api.py", line 107, in cdef
    self._cdef(csource, override=override, packed=packed)
  File "/usr/lib64/python3.6/site-packages/cffi/api.py", line 121, in _cdef
    self._parser.parse(csource, override=override, **options)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 315, in parse
    self._internal_parse(csource)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 338, in _internal_parse
    self._parse_decl(decl)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 437, in _parse_decl
    self._get_struct_union_enum_type('enum', node)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 706, in _get_struct_union_enum_typ
e
    tp = self._build_enum_type(explicit_name, type.values)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 845, in _build_enum_type
    nextenumvalue = self._parse_constant(enum.value)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 832, in _parse_constant
    "simple numeric constant" % exprnode.coord.line)
cffi.error.FFIError: :308: unsupported expression: expected a simple numeric constant
make[2]: *** [python/CMakeFiles/python.dir/build.make:74: python/_pyfar.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:1203: python/CMakeFiles/python.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
@elfmz
Copy link
Owner

elfmz commented Jan 1, 2022

ping @m32

@m32
Copy link
Contributor

m32 commented Jan 1, 2022

Cant reproduce this error, fresh build:
[ 97%] Built target NetRocks-WebDAV
[ 97%] Generating _pyfar.cpp
generating /devel/far2l/build/python/_pyfar.cpp
Scanning dependencies of target python
[ 98%] Building CXX object python/CMakeFiles/python.dir/src/python.cpp.o
[ 98%] Building CXX object python/CMakeFiles/python.dir/_pyfar.cpp.o
[ 98%] Linking CXX shared module ../install/Plugins/python/plug/python.far-plug-wide
[ 98%] Built target python

It must be around line 308, something like :
enum ... {
KEY_PRNTSCRN = 1<<0,
...
}

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

Line 308 of what file? May I gather some other debug info somehow?

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

First of all, try to build on completely fresh pulled repo (if it wasn't so)

@m32
Copy link
Contributor

m32 commented Jan 2, 2022

File "/home/opc/far2l/python/src/pythongen.py", line 43, in
pythongen line 43: it parses farwin.h, farcolor.hpp, farkeys.hpp and plugin.hpp identical to installffi from pluginmanager.py, when pythongen fails then pluginmanager will fail too, adding print(fqname) before open will show which file is parsed

File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 832, in _parse_constant
"simple numeric constant" % exprnode.coord.line)
cffi.error.FFIError: :308: unsupported expression: expected a simple numeric constant
308 is line number in parsed file

I have also build on fresh checkout - no errors

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

it is
/home/opc/far2l/python/configs/plug/far2l/farkeys.hpp
looks like "unsupported" is about expressions in enum values definitions.

temporary commented out such expressions, now it fails with

/home/opc/far2l/python/configs/plug/far2l/plugin.hpp
Traceback (most recent call last):
  File "/home/opc/far2l/python/src/pythongen.py", line 44, in <module>
    ffi.cdef(data, packed=True)
  File "/usr/lib64/python3.6/site-packages/cffi/api.py", line 107, in cdef
    self._cdef(csource, override=override, packed=packed)
  File "/usr/lib64/python3.6/site-packages/cffi/api.py", line 121, in _cdef
    self._parser.parse(csource, override=override, **options)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 315, in parse
    self._internal_parse(csource)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 338, in _internal_parse
    self._parse_decl(decl)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 437, in _parse_decl
    self._get_struct_union_enum_type('enum', node)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 706, in _get_struct_union_enum_typ
e
    tp = self._build_enum_type(explicit_name, type.values)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 845, in _build_enum_type
    nextenumvalue = self._parse_constant(enum.value)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 790, in _parse_constant
    return int(s, 16)
ValueError: invalid literal for int() with base 16: '0x000000ffUL'
make[2]: *** [python/CMakeFiles/python.dir/build.make:74: python/_pyfar.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:1203: python/CMakeFiles/python.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

$ cat /etc/oracle-release
Oracle Linux Server release 8.4
$ uname -m
aarch64

@m32
Copy link
Contributor

m32 commented Jan 2, 2022

0x000000ffUL is invalid in python, should be 0x000000ff

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

May remove that suffixes if it only reason of, dunno why they're there - they're useless in definition of enum's fields. However its then unclear why works for intel builds.

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

May remove that suffixes if it only reason of, dunno why they're there - they're useless in definition of enum's fields. However its then unclear why works for intel builds.

Worked! Thanks

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

So it looks like UL suffixes may safely be removed. But I don't know what to do with expressions in ENUMs

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

can you try to replace the with ul suffixes? (lowercased) may be it will work (and will be safer change)

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

ValueError: invalid literal for int() with base 16: '0x000000fful'

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

but why it works for intel? may be oracle linux has some older FFI of whatelse?

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

while suffixes may be removed, removing complex expressions from farkeys.hpp is harder.. BTW regarding suffixes it seems it really was a bug there and fixed - https://foss.heptapod.net/pypy/cffi/-/issues/407

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

how do i check cffi version used by far2l?

@m32
Copy link
Contributor

m32 commented Jan 2, 2022

run this command in python/bin folder:
pip freeze |grep cffi
on ubuntu cffi=1.15.0

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

$ ./pip freeze |grep cffi
You are using pip version 9.0.3, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
cffi==1.11.5

@m32
Copy link
Contributor

m32 commented Jan 2, 2022

KEY_CTRLSHIFTA = (KEY_CTRL | KEY_SHIFT) + 'A' - this is quite a complicated expression and cffi works fine.

https://pypi.org/project/cffi has 1.15.0 for cffi on aarch64 for python >= 3.6 and one of them should be downloaded when far2l is built

Which version of Python is on your machine?

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

$ python --version
Python 3.6.8
cd far2l/build/install/Plugins/python/plug/python/bin
./python --version
Python 3.6.8
./python3 --version
Python 3.6.8

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

...build/install/Plugins/python/plug/python/bin$ ./pip show cffi                                   ↑
Name: cffi
Version: 1.11.5
Summary: Foreign Function Interface for Python calling C code.
Home-page: http://cffi.readthedocs.org
Author: Armin Rigo, Maciej Fijalkowski
Author-email: python-cffi@googlegroups.com
License: MIT
Location: /usr/lib64/python3.6/site-packages
Requires: pycparser
You are using pip version 9.0.3, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

running

cd far2l/python/configs/plug/python/bin
./python -m pip install --upgrade pip
./python -m pip install --upgrade cffi

solved an issue with expressions in ENUMs for me

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

What about UL suffixes? still making problems?

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

What about UL suffixes? still making problems?

nope :)

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

so issue resolved? however due to looked at that code, i've made old planned change - refactored python plugin build, and now it doesn't create intermediate stuff in sources tree, but instead putting all that stuff into build directory. Also i've made preprocessing of far2l's header files also during build, instead of having 'hard-commited' copies on git.
It all looks working, but it would be nice if @m32 would look at this change just in case...

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

tried a fresh git checkout... still errors if trying to build without cffi update by running

./python -m pip install --upgrade pip
./python -m pip install --upgrade cffi

in far2l/build/python/python/bin folder

maybe we should keep this issue open for anyone who will encounter the same errors also?

@elfmz
Copy link
Owner

elfmz commented Jan 2, 2022

but i didnt fix it, for now it too complicated to eliminate that complex expressions, especially if this fixable just by updating python package

@unxed
Copy link
Contributor Author

unxed commented Jan 2, 2022

may python packages be updated somehow from build script?

@m32
Copy link
Contributor

m32 commented Jan 3, 2022

so issue resolved? however due to looked at that code, i've made old planned change - refactored python plugin build, and now it doesn't create intermediate stuff in sources tree, but instead putting all that stuff into build directory. Also i've made preprocessing of far2l's header files also during build, instead of having 'hard-commited' copies on git. It all looks working, but it would be nice if @m32 would look at this change just in case...

there is still a file renaming in pluginmanager.py
for fname in ("farwin.h", "farcolor.h", "farkeys.h", "farplug-wide.h"):

i did the same, with pycpp (preprocessor) i automatically change the headers to one far2l.hh file. I added one _FAR_PYTHON_GEN variable to the preprocessor definition, but I'm still testing it.
one of the changes is in farkeys.hppL KEY_BRACKET = '[' not liked by cffi

INT_PTR - is hard coded for 64-bit systems, after this change fartty works on raspberry

may python packages be updated somehow from build script?
yes, in another add_custom_command(TARGET python POST_BUILD COMMAND ...python -m pip install --upgrade ....)

@m32
Copy link
Contributor

m32 commented Jan 3, 2022

I did it by hand so i did it automagically :)

elfmz added a commit that referenced this issue Jan 4, 2022
#1164 - automagic generation of far2lcffi.py file
@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

but you broken 32 bits again:( or not?

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

32/64 - I haven't touched that yet, in pythongen.py there is if True: for this task

@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

you may check if target bitness is 64 at prebuild.sh stage by
echo $'#ifdef __LP64__\nTARGET64\n#endif' | $4 -E - | grep TARGET64
(and for that need to return passing "${CMAKE_C_COMPILER}" as $4 again)

@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

-E invokes compiler in preprocessor mode, i.e. it doesnt compile, just processes macroses. See how it works:

$ echo $'#ifdef __LP64__\nTARGET64\n#endif' | gcc -E - | grep TARGET64
TARGET64
$ echo $'#ifdef __LP64__\nTARGET64\n#endif' | gcc -m32 -E - | grep TARGET64
$

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

however, I prefer in python:
if ctypes.sizeof(ctypes.cint) == ctypes.sizeof(ctypes.void_p):
# 32 bit platform
pass
else:
# 64 bit platform
cpp.define("LP64")

this works on pi and my laptop

@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

build system not always == target, sometimes its a cross-compilations :)

@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

..albeit im not sure that python plugin build fully OK for cross-compilation in other aspects..

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

then we need python as cross compiler ? would be hard todo

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

I also compile python4android at home, only problems and it's not stable

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

How to find PATH_MAX and NAME_MAX in python - i have hardcoded defaults from sys/limits.h ?
Or maybe all the parameters of the platform should be calculated in the shell?

@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

in similar way, later i will add creating some incpy/target.h with that things obtained from gcc during configuration, but its tomorrow, its too late today already

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

done in python #1173

@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

still, i prefer to make it in cross-compile-friendly, so see 90b09cc

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

It's OK for me

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

Looks finished to me.
@unxed

@unxed
Copy link
Contributor Author

unxed commented Jan 4, 2022

still
cffi.error.FFIError: :307: unsupported expression: expected a simple numeric constant
on fresh build folder if pip & cffi are not upgraded by hands

if it is not considered a problem, may close

@m32
Copy link
Contributor

m32 commented Jan 4, 2022

Maybe your python package cache is corrupted?
rm -rf ~/.cache/pip

@unxed
Copy link
Contributor Author

unxed commented Jan 4, 2022

tried rm -rf ~/.cache/pip (and removed build/python after it), still errors

@elfmz
Copy link
Owner

elfmz commented Jan 4, 2022

check now plz

@unxed
Copy link
Contributor Author

unxed commented Jan 5, 2022

Cache entry deserialization failed, entry ignored
Collecting pip
  Using cached https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03
ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed pip-21.3.1
Requirement already satisfied: cffi in /usr/lib64/python3.6/site-packages (1.11.5)
Collecting debugpy
  Using cached debugpy-1.5.1-py2.py3-none-any.whl (4.1 MB)
Collecting pcpp
  Using cached pcpp-1.30-py2.py3-none-any.whl (91 kB)
Requirement already satisfied: pycparser in /usr/lib/python3.6/site-packages (from cffi) (2.14)
Installing collected packages: pcpp, debugpy
Successfully installed debugpy-1.5.1 pcpp-1.30
WARNING: yacc table file version is out of date
Traceback (most recent call last):
  File "/home/opc/far2l/python/src/pythongen.py", line 71, in <module>
    from far2lcffi import ffi, cffi
  File "/home/opc/far2l/build/python/incpy/far2lcffi.py", line 3362, in <module>
  File "/usr/lib64/python3.6/site-packages/cffi/api.py", line 107, in cdef
    self._cdef(csource, override=override, packed=packed)
  File "/usr/lib64/python3.6/site-packages/cffi/api.py", line 121, in _cdef
    self._parser.parse(csource, override=override, **options)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 315, in parse
    self._internal_parse(csource)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 338, in _internal_parse
    self._parse_decl(decl)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 437, in _parse_decl
    self._get_struct_union_enum_type('enum', node)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 706, in _get_struct_union_enum_ty
pe
    tp = self._build_enum_type(explicit_name, type.values)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 845, in _build_enum_type
    nextenumvalue = self._parse_constant(enum.value)
  File "/usr/lib64/python3.6/site-packages/cffi/cparser.py", line 790, in _parse_constant
    return int(s, 16)
ValueError: invalid literal for int() with base 16: '0x000000ffUL'
make[2]: *** [python/CMakeFiles/python.dir/build.make:80: python/incpy/far2lcffi.py] Error 1
make[1]: *** [CMakeFiles/Makefile2:1247: python/CMakeFiles/python.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

@unxed
Copy link
Contributor Author

unxed commented Jan 5, 2022

adding

 	"$DST/python/bin/python" -m pip install --upgrade cffi

just after

 	"$DST/python/bin/python" -m pip install --upgrade pip

fixes build

@elfmz
Copy link
Owner

elfmz commented Jan 5, 2022

now?

@unxed
Copy link
Contributor Author

unxed commented Jan 5, 2022

great! closing.

@unxed unxed closed this as completed Jan 5, 2022
@m32
Copy link
Contributor

m32 commented Jan 5, 2022

File "/usr/lib64/python3.6/site-packages/cffi/api.py", line 107, in cdef

It looks like you are not using virtualenv - python3-cffi is in system installed packages, which is outdated
sudo apt uninstall python3-cffi

@unxed
Copy link
Contributor Author

unxed commented Jan 5, 2022

Unfortunately I am not the only user of that aarch64 machine, so I am afraid to uninstall packages there

@m32
Copy link
Contributor

m32 commented Jan 5, 2022

Another option is virtualenv with no system packages:
$PYTHON -m venv "$DST/python"

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