Skip to content

Commit

Permalink
llvm: install libc++ into lib/"c++".
Browse files Browse the repository at this point in the history
  • Loading branch information
carlocab authored and BrewTestBot committed Sep 19, 2022
1 parent b8635d1 commit d3999fc
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Formula/llvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ def install
if OS.mac?
args << "-DLLVM_BUILD_LLVM_C_DYLIB=ON"
args << "-DLLVM_ENABLE_LIBCXX=ON"
args << "-DLIBCXX_INSTALL_LIBRARY_DIR=#{lib}/c++"
args << "-DLIBCXXABI_INSTALL_LIBRARY_DIR=#{lib}/c++"
args << "-DDEFAULT_SYSROOT=#{macos_sdk}" if macos_sdk
runtimes_cmake_args << "-DCMAKE_INSTALL_RPATH=#{rpath}"
runtimes_cmake_args << "-DCMAKE_INSTALL_RPATH=#{loader_path}"

# Prevent CMake from defaulting to `lld` when it's found next to `clang`.
# This can be removed after CMake 3.25. See:
Expand All @@ -150,6 +152,10 @@ def install
[args, runtimes_cmake_args, builtins_cmake_args].each do |arg_array|
arg_array << "-DCMAKE_LINKER=ld"
end

# Disable builds for OSes not supported by the CLT SDK.
clt_sdk_support_flags = %w[I WATCH TV].map { |os| "-DCOMPILER_RT_ENABLE_#{os}OS=OFF" }
builtins_cmake_args += clt_sdk_support_flags
else
ENV.append_to_cflags "-fpermissive -Wno-free-nonheap-object"

Expand Down Expand Up @@ -225,6 +231,7 @@ def install
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7671
extra_args << "-DLLVM_USE_LINKER=ld"
extra_args << "-DCMAKE_LINKER=ld"
extra_args += clt_sdk_support_flags
else
# Make sure CMake doesn't try to pass C++-only flags to C compiler.
extra_args << "-DCMAKE_C_COMPILER=#{ENV.cc}"
Expand Down Expand Up @@ -424,10 +431,12 @@ def install
end

def caveats
<<~EOS
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L#{opt_lib} -Wl,-rpath,#{opt_lib}"
EOS
on_macos do
<<~EOS
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L#{opt_lib}/c++ -Wl,-rpath,#{opt_lib}/c++"
EOS
end
end

test do
Expand Down Expand Up @@ -527,12 +536,13 @@ def caveats

# link against installed libc++
# related to https://github.com/Homebrew/legacy-homebrew/issues/47149
cxx_libdir = OS.mac? ? opt_lib/"c++" : opt_lib
system "#{bin}/clang++", "-v",
"-isystem", "#{opt_include}/c++/v1",
"-std=c++11", "-stdlib=libc++", "test.cpp", "-o", "testlibc++",
"-rtlib=compiler-rt", "-L#{opt_lib}", "-Wl,-rpath,#{opt_lib}"
"-rtlib=compiler-rt", "-L#{cxx_libdir}", "-Wl,-rpath,#{cxx_libdir}"
assert_includes (testpath/"testlibc++").dynamically_linked_libraries,
(opt_lib/shared_library("libc++", "1")).to_s
(cxx_libdir/shared_library("libc++", "1")).to_s
(testpath/"testlibc++").dynamically_linked_libraries.each do |lib|
refute_match(/libstdc\+\+/, lib)
refute_match(/libgcc/, lib)
Expand Down

0 comments on commit d3999fc

Please sign in to comment.