Skip to content

Commit

Permalink
python@3.9: adjust flags to avoid package installation breakage
Browse files Browse the repository at this point in the history
* Mac SDK include paths should be system include path.
* The brew include path should only be added for building Python,
  and shouldn't be re-used after (use FLAG_NODIST).

Closes #68528.

Signed-off-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
  • Loading branch information
Mitchell Hentges authored and carlocab committed Feb 3, 2021
1 parent 397f004 commit 784d292
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Formula/python@3.9.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,21 @@ def install
args << "--with-system-ffi"
end

cflags = ["-I#{HOMEBREW_PREFIX}/include"]
ldflags = ["-L#{HOMEBREW_PREFIX}/lib"]
cppflags = ["-I#{HOMEBREW_PREFIX}/include"]
# Python re-uses flags when building native modules.
# Since we don't want native modules prioritizing the brew
# include path, we move them to [C|LD]FLAGS_NODIST.
# Note: Changing CPPFLAGS causes issues with dbm, so we
# leave it as-is.
cflags = []
cflags_nodist = ["-I#{HOMEBREW_PREFIX}/include"]
ldflags = []
ldflags_nodist = ["-L#{HOMEBREW_PREFIX}/lib"]
cppflags = ["-I#{HOMEBREW_PREFIX}/include"]

if MacOS.sdk_path_if_needed
# Help Python's build system (setuptools/pip) to build things on SDK-based systems
# The setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
cflags << "-isysroot #{MacOS.sdk_path}" << "-I#{MacOS.sdk_path}/usr/include"
cflags << "-isysroot #{MacOS.sdk_path}"
ldflags << "-isysroot #{MacOS.sdk_path}"
end
# Avoid linking to libgcc https://mail.python.org/pipermail/python-dev/2012-February/116205.html
Expand Down Expand Up @@ -162,7 +169,9 @@ def install
end

args << "CFLAGS=#{cflags.join(" ")}" unless cflags.empty?
args << "CFLAGS_NODIST=#{cflags_nodist.join(" ")}" unless cflags_nodist.empty?
args << "LDFLAGS=#{ldflags.join(" ")}" unless ldflags.empty?
args << "LDFLAGS_NODIST=#{ldflags_nodist.join(" ")}" unless ldflags_nodist.empty?
args << "CPPFLAGS=#{cppflags.join(" ")}" unless cppflags.empty?

system "./configure", *args
Expand Down

0 comments on commit 784d292

Please sign in to comment.