shims: enforce usage of Swift-bundled Clang on Linux

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Bo Anderson 2021-09-02 16:31:12 +01:00
parent f14fcc810e
commit 414935fb39
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1 @@
../../super/swift

View File

@ -79,6 +79,8 @@ class Cmd
"#{ENV["HOMEBREW_PREFIX"]}/opt/llvm/bin/#{Regexp.last_match(1)}"
when /\w\+\+(-\d+(\.\d)?)?$/
case ENV["HOMEBREW_CC"]
when "swift_clang"
"#{ENV["HOMEBREW_PREFIX"]}/opt/swift/libexec/bin/clang++"
when /clang/
"clang++"
when /llvm-gcc/
@ -91,6 +93,8 @@ class Cmd
# HOMEBREW_CC regardless of what name under which the tool was invoked.
if ENV["HOMEBREW_CC"] == "llvm_clang"
"#{ENV["HOMEBREW_PREFIX"]}/opt/llvm/bin/clang"
elsif ENV["HOMEBREW_CC"] == "swift_clang"
"#{ENV["HOMEBREW_PREFIX"]}/opt/swift/libexec/bin/clang"
else
ENV["HOMEBREW_CC"]
end

View File

@ -0,0 +1,15 @@
#!/bin/bash
# Ensure we use Swift's clang when performing Swift builds.
export CC="clang"
export CXX="clang++"
# swift_clang isn't a shim but is used to ensure the cc shim
# points to the compiler inside the swift keg
export HOMEBREW_CC="swift_clang"
export HOMEBREW_CXX="swift_clang++"
# HOMEBREW_OPT is set by extend/ENV/super.rb
# shellcheck disable=SC2154
exec "${HOMEBREW_OPT}/swift/bin/swift" "$@"