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

Building Python 3.11 fails to build on FreeBSD 12: static_assert() is not defined by <assert.h> #91782

Closed
vstinner opened this issue Apr 21, 2022 · 2 comments
Labels
OS-freebsd type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

Python 3.11 no longer builds on FreeBSD 12 since the commit 7cdaf87 that I made yesterday.

My change: #91730

I checked with buildbots that Python still builds successfully on FreeBSD. It did on the two FreeBSD buildbot workers. Problem: one FreeBSD worker failed to download code with Git and the build was marked as successful :-(

Successful build+test on FreeBSD:

git failed on the second job!

fatal: bad object refs/heads/refs/pull/28569
error: https://github.com/python/cpython.git did not send all necessary objects
(...)
fatal: failed to run reflog
error: task 'gc' failed
program finished with exit code 1

And now Python fails to build on "AMD64 FreeBSD Non-Debug 3.x" which runs FreeBSD 12.3: https://buildbot.python.org/all/#/builders/172/builds/1911

test.pythoninfo:

os.uname: posix.uname_result(sysname='FreeBSD', nodename='123-RELEASE-p2-amd64-9e36', release='12.3-RELEASE-p1', version='FreeBSD 12.3-RELEASE-p1 GENERIC', machine='amd64')

The problem is that `/usr/include/sys/cdefs.hsets the ISO C standard to something older than-std=c11`` command line.

Reproducer, the 4 defines are copied from Python pyconfig.h:

#define _POSIX_C_SOURCE 200809L
#define _XOPEN_SOURCE 700
#define _XOPEN_SOURCE_EXTENDED 1
#define __BSD_VISIBLE 1
#include <assert.h>

int main()
{
    static_assert(1 == 1, "ok");
    static_assert(1 == 0, "bug");
    return 0;
}
  • _XOPEN_SOURCE=700 sets _POSIX_C_SOURCE to 200809
  • _POSIX_C_SOURCE=200809 sets __ISO_C_VISIBLE to 1999
  • <assert.h> does not define static_assert() if __ISO_C_VISIBLE is less than 2011 which is the case here!

In <sys/cdefs.h>, I don't see any value of _XOPEN_SOURCE or _POSIX_C_SOURCE which could give a C standard higher than 2008. It seems like _XOPEN_SOURCE and _POSIX_C_SOURCE should not be defined to get ISO C11 (which defines static_assert()).

But the Python build system is complex, and I'm not comfortable to remove _XOPEN_SOURCE and _POSIX_C_SOURCE from pyconfig.h on all BSD platforms. I don't know if it would drop support for old FreeBSD version or if it would break other BSD variants like OpenBSD and NetBSD.


An alternative would be to use _Static_assert(). It should work, but I like static_assert() syntax, and we may use other C11 features
tomorrow.

Another alternative is to define static_assert() in Python if it's not defined... but I dislike working around issues with system headers :-(

@vstinner vstinner added type-bug An unexpected behavior, bug, or error OS-freebsd labels Apr 21, 2022
@vstinner
Copy link
Member Author

vstinner added a commit that referenced this issue Apr 21, 2022
On FreeBSD, if the static_assert() macro is not defined, define it in
Python until <sys/cdefs.h> supports C11:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255290
@vstinner
Copy link
Member Author

Fixed by #91787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-freebsd type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant