Skip to content

fix: honor CC/AR and handle missing toolchain when building from sdist - #266

Merged
manugarg merged 2 commits into
mainfrom
setup-py-honor-cc
Oct 3, 2026
Merged

manugarg merged 2 commits into
mainfrom
setup-py-honor-cc

Conversation

@manugarg

@manugarg manugarg commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Fixes the source-build half of #263.

Problem

build_c_objects() in src/pymod/setup.py took the compiler and archiver straight from Python's sysconfig. On a cross-compiled Python (the reporter uses SynoCommunity's python314), that is the build machine's toolchain, which doesn't exist where pip runs. The build died with a raw FileNotFoundError for /github/workspace/toolchain/.../x86_64-pc-linux-gnu-gcc, and setting CC didn't help because it was ignored.

Changes

  • CC / AR from the environment are used first.
  • A sysconfig tool that isn't runnable is skipped in favour of cc / ar. The fallback is exported to the environment so setuptools compiles and links the extension with the same tool.
  • If no toolchain is found, the build exits with a message saying what was tried and how to override it.
  • The version lookup no longer crashes when git isn't installed (found while testing; it ran git rev-parse unguarded).

Testing

Built an sdist and ran pip wheel on it with sysconfig patched (via sitecustomize) to the reporter's compiler path:

Scenario Result
1.5.2 sdist from PyPI, patched sysconfig fails with the same FileNotFoundError as #263
normal environment builds
patched sysconfig, cc on PATH builds with cc; wheel imports and find_proxy works
patched sysconfig, CC=gcc AR=ar builds
CC=/nonexistent/gcc CC is set to '/nonexistent/gcc', but '/nonexistent/gcc' was not found.
patched sysconfig, no compiler on PATH Building pacparser from source needs a C toolchain, but ... was not found.
toolchain present, no git on PATH builds

NO_INTERNET=1 make -C src pymod and tests/test_sdist_metadata.py pass. Not tested on an actual Synology box.

setup.py took the compiler and archiver straight from Python's sysconfig.
On a cross-compiled Python (e.g. SynoCommunity's) that is the build
machine's toolchain, which doesn't exist where pip runs, and there was no
way to override it (#263).

Use the CC/AR environment variables first, skip a sysconfig tool that
isn't runnable, and fail with a clear message if no toolchain is found.

Also don't crash in the version lookup when git isn't installed.
- Resolve the compiler whenever a build command runs, not only when the
  C objects are missing, so a re-run with the objects already present
  still gets a working compiler exported for setuptools.
- Only look up ar when libquickjs.a actually has to be created.
- Don't raise IndexError on a whitespace-only CC/AR.
@sonarqubecloud

sonarqubecloud Bot commented Oct 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@manugarg
manugarg merged commit 0af33e9 into main Oct 3, 2026
29 of 30 checks passed
@manugarg
manugarg deleted the setup-py-honor-cc branch October 3, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant