Skip to content

Python fails to build on WASM: _testcapi/vectorcall_limited.c is built with Py_BUILD_CORE_BUILTIN #109723

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

Closed
vstinner opened this issue Sep 22, 2023 · 0 comments
Labels
build The build process and cross-build

Comments

@vstinner
Copy link
Member

vstinner commented Sep 22, 2023

My PR #109690 broke WASM buildbots.

Example with wasm32-emscripten node (dynamic linking) 3.x: https://buildbot.python.org/all/#/builders/1056/builds/3142

/opt/emsdk/upstream/emscripten/emcc  -DNDEBUG -g -O3 (...) -DPy_BUILD_CORE_BUILTIN -c ../../Modules/_testcapi/vectorcall_limited.c -o Modules/_testcapi/vectorcall_limited.o

In file included from ../../Modules/_testcapi/vectorcall_limited.c:2:
In file included from ../../Modules/_testcapi/parts.h:7:
In file included from ../../Include/Python.h:44:
../../Include/pyport.h:52:4: error: "Py_LIMITED_API is not compatible with Py_BUILD_CORE"
#  error "Py_LIMITED_API is not compatible with Py_BUILD_CORE"
   ^
1 error generated.

I'm not sure how -DPy_BUILD_CORE_BUILTIN landed in the command building Modules/_testcapi/vectorcall_limited.c.

I don't think that it's correct that vectorcall_limited.c which tests the limited C API on purpose it built with Py_BUILD_CORE.

On my Linux machine, Makefile contains:

Modules/_testcapi/vectorcall_limited.o: $(srcdir)/Modules/_testcapi/vectorcall_limited.c $(MODULE__TESTCAPI_DEPS) $(MODULE_DEPS_SHARED) $(PYTHON_HEADERS); $(CC) $(MODULE__TESTCAPI_CFLAGS) $(PY_STDMODULE_CFLAGS) $(CCSHARED) -c $(srcdir)/Modules/_testcapi/vectorcall_limited.c -o Modules/_testcapi/vectorcall_limited.o

So it gets two groups of compiler flags:

  • MODULE__TESTCAPI_CFLAGS: not defined (empty)
  • PY_STDMODULE_CFLAGS: -fno-strict-overflow -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -g -Og -Wall -O0 -std=c11 -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include

I don't see -DPy_BUILD_CORE_BUILTIN here.

I can reproduce the issue locally with this custom Modules/Setup.local:

*static*
_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/pyos.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c

make fails with:

In file included from ./Include/Python.h:44,
                 from ./Modules/_testcapi/parts.h:7,
                 from ./Modules/_testcapi/vectorcall_limited.c:2:
./Include/pyport.h:52:4: error: #error "Py_LIMITED_API is not compatible with Py_BUILD_CORE"
   52 | #  error "Py_LIMITED_API is not compatible with Py_BUILD_CORE"
      |    ^~~~~
make: *** [Makefile:2982: Modules/_testcapi/vectorcall_limited.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from ./Include/Python.h:44,
                 from ./Modules/_testcapi/parts.h:7,
                 from ./Modules/_testcapi/heaptype_relative.c:2:
./Include/pyport.h:52:4: error: #error "Py_LIMITED_API is not compatible with Py_BUILD_CORE"
   52 | #  error "Py_LIMITED_API is not compatible with Py_BUILD_CORE"
      |    ^~~~~
make: *** [Makefile:3001: Modules/_testcapi/heaptype_relative.o] Error 1

Modules/makesetup uses $(PY_STDMODULE_CFLAGS) if $doconfig is no, but uses $(PY_BUILTIN_MODULE_CFLAGS) otherwise. In the second case, $(PY_BUILTIN_MODULE_CFLAGS) adds -DPy_BUILD_CORE_BUILTIN to compiler command used to build _testcapi C files.

Linked PRs

@vstinner vstinner added the build The build process and cross-build label Sep 22, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Sep 22, 2023
Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE in
Modules/_testcapi/parts.h to make sure that _testcapi does not test
the internal C API by mistake. Move code which was only in
Modules/_testcapimodule.c before. Moreover, heaptype_relative.c and
vectorcall_limited.c use the limited C API which is incompatible with
the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 22, 2023
Make sure that the internal C API is not tested by mistake by
_testcapi.

Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in
Modules/_testcapi/parts.h: move code from _testcapimodule.c.

heaptype_relative.c and vectorcall_limited.c are using the limited C
API which is incompatible with the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 22, 2023
Make sure that the internal C API is not tested by mistake by
_testcapi.

Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in
Modules/_testcapi/parts.h: move code from _testcapimodule.c.

heaptype_relative.c and vectorcall_limited.c are using the limited C
API which is incompatible with the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 22, 2023
Make sure that the internal C API is not tested by mistake by
_testcapi.

Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in
Modules/_testcapi/parts.h: move code from _testcapimodule.c.

heaptype_relative.c and vectorcall_limited.c are using the limited C
API which is incompatible with the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.
vstinner added a commit that referenced this issue Sep 22, 2023
Make sure that the internal C API is not tested by mistake by
_testcapi.

Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in
Modules/_testcapi/parts.h: move code from _testcapimodule.c.

heaptype_relative.c and vectorcall_limited.c are using the limited C
API which is incompatible with the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.

Ajust "make check-c-globals" for these changes.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 25, 2023
Make sure that the Py_BUILD_CORE macro is not defined.
vstinner added a commit that referenced this issue Sep 25, 2023
Make sure that the Py_BUILD_CORE macro is not defined.
csm10495 pushed a commit to csm10495/cpython that referenced this issue Sep 28, 2023
Make sure that the internal C API is not tested by mistake by
_testcapi.

Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in
Modules/_testcapi/parts.h: move code from _testcapimodule.c.

heaptype_relative.c and vectorcall_limited.c are using the limited C
API which is incompatible with the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.

Ajust "make check-c-globals" for these changes.
csm10495 pushed a commit to csm10495/cpython that referenced this issue Sep 28, 2023
)

Make sure that the Py_BUILD_CORE macro is not defined.
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Make sure that the internal C API is not tested by mistake by
_testcapi.

Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in
Modules/_testcapi/parts.h: move code from _testcapimodule.c.

heaptype_relative.c and vectorcall_limited.c are using the limited C
API which is incompatible with the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.

Ajust "make check-c-globals" for these changes.
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
)

Make sure that the Py_BUILD_CORE macro is not defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build
Projects
None yet
Development

No branches or pull requests

1 participant