Unix port: ffilib.py: libc.so.6 is no longer the latest version
While using os.popen() from unix-ffi libraries on FreeBSD 14.1-RELEASE-p5 amd64, I encountered this error:
...
File "os/__init__.py", line 32, in <module>
File "ffilib.py", line 43, in libc
File "ffilib.py", line 39, in open
File "ffilib.py", line 33, in open
OSError: [Errno 2] ENOENT
On further investigation, I found that libc major version has been upgraded to 7, and ffilib.py is only looking for versions up to 6.
$ ls /lib/libc.so*
/lib/libc.so.7
https://github.com/micropython/micropython-lib/blob/e4cf09527bce7569f5db742cf6ae9db68d50c6a9/unix-ffi/ffilib/ffilib.py#L42
Changing the 6 to 7 fixed the issue.
Only making a note here since the readme for unix-ffi says: "This directory is unmaintained." and I would like to have a reference come up in searches when someone encounters the error.
unix: Improve support for FreeBSD.
Summary
This PR addresses a few minor issues related to MicroPython on the FreeBSD platform:
- FFI tests tried to open a now missing libc library version (
libc.so.6is no longer there, now it's calledlibc.so.7) - The system-wide entry in
sys.pathfor the standard library pointed to/usr/lib/micropyhon, but on FreeBSD anything outside the base system files has to reside elsewhere; the usual root under/usrfor third party packages is/usr/local sys.platformnow reports it's running on FreeBSD instead of Linux- The interpreter banner recognises FreeBSD as a separate platform and sets the correct libc name
platform.platformnow reports FreeBSD as the operating system- The EDEADLK result code returned on failed lock acquisition is handled, aliased to EBUSY at the moment
- The
extmod/select_poll_fdtest is skipped on FreeBSD
<hr>
This is technically the continuation of https://github.com/micropython/micropython-lib/pull/1099, as it fixes FFI support on recent FreeBSD versions in micropython/micropython-lib.
Testing
The test suite was executed in a FreeBSD 15.0-RELEASE x64 virtual machine, with no FFI-related test failures. thread/thread_heap_lock, and thread/thread_lock5 were failing before these changes as well. I haven't yet looked into those two tests.
Trade-offs and Alternatives
The changes in this PR should affect MicroPython's behaviour exclusively when built on FreeBSD. FFI and sys.path changes might also apply to OpenBSD, NetBSD, and their derivatives, but they weren't tested on those OSes.
Generative AI
I did not use generative AI tools when creating this PR.
Indeed (as this also applies to 15.0-RELEASE). That's also something that needs to be changed in MicroPython's own test suite, along with other minor things like moving part of the default sys.path from
/usr/lib/micropythonto/usr/local/lib/micropython, and recognising FreeBSD as its own thing rather than classify that as Linux.I believe some of these changes are already part of the patches in the ports tree, but last time I checked they still package a relatively old version. It won't hurt to have them in the source tree themselves.
This is fixed in
_libcbut still needs to be fixed inffilib.Right! I can fix that right now but then I'd have to fix it again if https://github.com/micropython/micropython/pull/18979 gets merged. In ffilib there's a check for
sys.platformand that PR will make it returnfreebsd, invalidating any small-scale change I'd make. I can also make it look for eitherlinuxorfreebsdfor the lookup to occur but then it'll take up bytes for nothing if that PR won't make the cut.I don't mind submitting multiple PRs over time, but maybe you may want to schedule the changes differently.
Yes, I see that now.
We are on the cusp of a release so can't make big changes. I think all this can be postponed until after the release.