mraa icon indicating copy to clipboard operation
mraa copied to clipboard

swig/python: fix compilation with newer CMake

Open alext-mkrs opened this issue 2 months ago • 0 comments

Looks like the target/wrapper name generation logic changed over time (as documented briefly in the SWIG docs) ~~and while I haven't found the exact root cause to put my finger on it, apparently there's now a mismatch somewhere related to auto-adding in one place/not adding in some other place an underscore to the target name~~ and there's another implicit underscore being added that then interferes with the Python private name mangling rules (thanks for @sbeaugrand for mentinoning it in #1152, I've skimmed through the issue too quickly initially and I think you're spot on there).

A workaround is to set the CMake policy CMP0078 to OLD, but that's of course not going to last.

Tested with mock and x86_64 architecture builds and their tests (that use the Python binding). Without it they fail with errors like the below, with the change they import/pass ok.

1/37 Test: py_general
Command: "/usr/sbin/python3" "/mraa/src/tests/mock/general_checks.py"
Directory: /mraa/src/build/tests/mock
"py_general" start time: Dec 07 22:26 CET
Output:
----------------------------------------------------------
Traceback (most recent call last):
  File "/mraa/src/tests/mock/general_checks.py", line 10, in <module>
    import mraa as m
  File "/mraa/src/build/src/python/python3/mraa.py", line 63, in <module>
    class uint8Array(object):
    ...<18 lines>...
            return __mraa.uint8Array_frompointer(t)
  File "/mraa/src/build/src/python/python3/mraa.py", line 69, in uint8Array
    __swig_destroy__ = __mraa.delete_uint8Array
                       ^^^^^^
NameError: name '_uint8Array__mraa' is not defined
<end of output>
Test time =   0.06 sec
----------------------------------------------------------

Fixes #1042. Fixes #1152.

alext-mkrs avatar Dec 07 '25 21:12 alext-mkrs