indygreg / python-build-standalone

Produce redistributable builds of Python
BSD 3-Clause "New" or "Revised" License
1.71k stars 107 forks source link

[darwin] pre-built artifacts reference SDK path from the build host #144

Open f355 opened 1 year ago

f355 commented 1 year ago

In darwin artifacts downloaded from the release page, the file lib/python3.10/_sysconfigdata__darwin_darwin.py contains the following flag:

-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk

If the machine has only Command Line Tools installed, then trying to install any pip package that has C code in it fails with the following error:

  running build_ext
  creating build/temp.macosx-11.0-arm64-3.10
  creating build/temp.macosx-11.0-arm64-3.10/src
  Compiling with an SDK that doesn't seem to exist: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk
  Please check your Xcode installation

...

  clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk' [-Wmissing-sysroot]
  In file included from src/MD2.c:28:
  src/common.h:34:10: fatal error: 'stdio.h' file not found
  #include <stdio.h>
           ^~~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pycryptodomex

The situation gets worse with upgrading XCode to 14.1 as it no longer includes MacOSX12.3.sdk, at least in the Release Candidate 2.

f355 commented 1 year ago

I was able to work around this by running ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk, but that makes me feel dirty.

indygreg commented 1 year ago

It is a known problem that build-time paths leak into the distribution.

See https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html#references-to-build-time-paths.

I wish I had a better solution for you, but I don't at this time. This is a complex problem with no easy solutions. The best I can recommend is for you to manually patch the bad _sysconfigdata_*.py file post extraction. This is something I hope we can make turnkey one day.

f355 commented 1 year ago

oh well. thank you anyway!