hpy
hpy copied to clipboard
Do not compile helpers with extension by default.
Right now, we are adding source files argparse.c
, buildvalue.c
, and helpers.c
to the source file list of the HPy extension to be built and then they are compiled together with the extension's sources.
We do so because the goal is that the helpers binary code should be in the HPy extension's library. While this works in most cases, we recently discovered a problem with that strategy on Mac (using LLVM toolchain). The extension was written in C++ and added:
extra_compile_args=['-std=c++11', '-stdlib=libc++']
extra_link_args=['-stdlib=libc++']
The extension failed to build argparse.c
with following error:
gcc -Wno-unused-result -Wsign-compare -g -O0 -Wall -DHPY -DHPY_UNIVERSAL_ABI -I. -I/path/to/lib/python3.8/site-packages/hpy/devel/include -I/path/to/include -I/Users/fa/work/repos/Python-3.8.5/Include -I/Users/fa/work/repos/Python-3.8.5 -c /path/to/lib/python3.8/site-packages/hpy/devel/src/runtime/argparse.c -o build/temp.macosx-12.0-x86_64-3.8-pydebug/path/to/lib/python3.8/site-packages/hpy/devel/src/runtime/argparse.o -std=c++11 -stdlib=libc++
error: invalid argument '-std=c++11' not allowed with 'C'
error: command 'gcc' failed with exit status 1
IMO, the underlying issue is that we are building these sources with the flags of the target. I think we should build them in the same way as we do with the rest of HPy. So, I suggest that we build an archive for the helpers and statically link them into the extension.
Optionally, if someone really wants to compile the helpers with the extension, we can provide an option to do so.