pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.53k stars 1.19k forks source link

[BUG] can't link c++ so if python is compiled with ccache since 72.2.0 #4748

Open trim21 opened 2 days ago

trim21 commented 2 days ago

setuptools version

setuptools >= 72.2.0

Python version

python 3.10

OS

debian 12

Additional environment information

No response

Description

I have a python compiled by pyenv with ccache, and since 72.2.0, setuptools can't link so as expected.

(bencode2) trim21@omv ~/proj/bencode2 $ python setup.py build_ext -i --force
running build_ext
building 'bencode2.__bencode' extension
ccache /usr/bin/c++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -march=native -mtune=native -fPIC -DFMT_HEADER_ONLY= -I./src/bencode2 -I./vendor/fmt/include -I./vendor/small_vector/source/include -I/home/trim21/proj/bencode2/.venv/lib/python3.10/site-packages/pybind11/include -I/home/trim21/proj/bencode2/.venv/include -I/home/trim21/.pyenv/versions/3.10.15/include/python3.10 -c ./src/bencode2/bencode.cpp -o build/temp.linux-x86_64-cpython-310/./src/bencode2/bencode.o -fvisibility=hidden -g0 -std=c++17
ccache /usr/bin/c++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -march=native -mtune=native /usr/bin/c++ -shared build/temp.linux-x86_64-cpython-310/./src/bencode2/bencode.o -L/home/trim21/.pyenv/versions/3.10.15/lib -o build/lib.linux-x86_64-cpython-310/bencode2/__bencode.cpython-310-x86_64-linux-gnu.so
/usr/bin/ld: cannot use executable file '/usr/bin/c++' as input to a link
collect2: error: ld returned 1 exit status
error: command '/usr/bin/ccache' failed with exit code 1
(bencode2) trim21@omv ~/proj/bencode2 $ python -m sysconfig|grep ccache
        BLDSHARED = "ccache /usr/bin/cc -shared -L/home/trim21/.pyenv/versions/3.10.15/lib -Wl,-rpath,/home/trim21/.pyenv/versions/3.10.15/lib -L/home/trim21/.pyenv/versions/3.10.15/lib -Wl,-rpath,/home/trim21/.pyenv/versions/3.10.15/lib"
        CC = "ccache /usr/bin/cc"
        CONFIG_ARGS = "'--prefix=/home/trim21/.pyenv/versions/3.10.15' '--libdir=/home/trim21/.pyenv/versions/3.10.15/lib' '--enable-shared' 'CC=ccache /usr/bin/cc' 'CFLAGS= -march=native -mtune=native' 'LDFLAGS=-L/home/trim21/.pyenv/versions/3.10.15/lib -Wl,-rpath,/home/trim21/.pyenv/versions/3.10.15/lib' 'LIBS=-L/home/trim21/.pyenv/versions/3.10.15/lib -Wl,-rpath,/home/trim21/.pyenv/versions/3.10.15/lib' 'CPPFLAGS=-I/home/trim21/.pyenv/versions/3.10.15/include'"
        CXX = "ccache /usr/bin/c++"
        LDCXXSHARED = "ccache /usr/bin/c++ -shared"
        LDSHARED = "ccache /usr/bin/cc -shared -L/home/trim21/.pyenv/versions/3.10.15/lib -Wl,-rpath,/home/trim21/.pyenv/versions/3.10.15/lib -L/home/trim21/.pyenv/versions/3.10.15/lib -Wl,-rpath,/home/trim21/.pyenv/versions/3.10.15/lib"
        LINKCC = "ccache /usr/bin/cc"
        MAINCC = "ccache /usr/bin/cc"

Expected behavior

it should build so as expected

How to Reproduce

you will need to install pyenv, compile python with https://github.com/pyenv/pyenv-ccache

then use this python to build binary module,

for example

git clone https://github.com/trim21/bencode-py
cd bencode-py
pyenv local 3.10
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python setup.py build_ext -i --force

Output

(bencode2) trim21@omv ~/proj/bencode2 $ python setup.py build_ext -i --force -g
running build_ext
building 'bencode2.__bencode' extension
ccache /usr/bin/c++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -march=native -mtune=native -fPIC -g -DFMT_HEADER_ONLY= -I./src/bencode2 -I./vendor/fmt/include -I./vendor/small_vector/source/include -I/home/trim21/proj/bencode2/.venv/lib/python3.10/site-packages/pybind11/include -I/home/trim21/proj/bencode2/.venv/include -I/home/trim21/.pyenv/versions/3.10.15/include/python3.10 -c ./src/bencode2/bencode.cpp -o build/temp.linux-x86_64-cpython-310/./src/bencode2/bencode.o -fvisibility=hidden -g0 -std=c++17
ccache /usr/bin/c++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -march=native -mtune=native /usr/bin/c++ -shared -g build/temp.linux-x86_64-cpython-310/./src/bencode2/bencode.o -L/home/trim21/.pyenv/versions/3.10.15/lib -o build/lib.linux-x86_64-cpython-310/bencode2/__bencode.cpython-310-x86_64-linux-gnu.so
/usr/bin/ld: cannot use executable file '/usr/bin/c++' as input to a link
collect2: error: ld returned 1 exit status
error: command '/usr/bin/ccache' failed with exit code 1
trim21 commented 2 days ago

some testing:

54936c73b is good

64f10c582 is bad

this is caused by https://github.com/pypa/setuptools/pull/4539