Building clang on OSX

I'm attempting to build clang/compiler-rt/lld/libc++ on OSX using ninja.
I get the errors below from lld when running unit tests. It appears
that clang doesn't know or isn't providing the necessary link paths for
system libraries to lld.

I haven't be able to find many guides about building clang on OSX. The
ones I have found use Xcode but for various reasons I would rather not
have to do that. Is Xcode the only way to build clang on OSX? If not,
is there a CMake variable or other setting that tells clang or lld where
the system libraries are?

Thanks for any help!

                      -David

FAIL: Builtins :: TestCases/Darwin/os_version_check_test_no_core_foundation.c (1 of 2)
******************** TEST 'Builtins :: TestCases/Darwin/os_version_check_test_no_core_foundation.c' FAILED ********************
Script:

Try passing -isysroot $(xcrun -show-sdk-path) to -DCMAKE_C_FLAGS and DCMAKE_CXX_FLAGS.

Nico Weber <thakis@chromium.org> writes:

Try passing `-isysroot $(xcrun -show-sdk-path)` to -DCMAKE_C_FLAGS and DCMAKE_CXX_FLAGS.

Unfortunately, that did not work. It's not the compiler building clang
that can't find the libraries, it's the built clang that's having
trouble. Is there some CMake variable to give the built clang a set of
default options to use?

                         -David

LLD for Mach-O has bitrotted significantly and isn't really functional anymore (beyond the most basic programs). I'd recommend sticking with ld64 as the linker.

    Nico Weber <thakis@chromium.org> writes:
    
    > Try passing `-isysroot $(xcrun -show-sdk-path)` to -DCMAKE_C_FLAGS and DCMAKE_CXX_FLAGS.
    
    Unfortunately, that did not work. It's not the compiler building clang
    that can't find the libraries, it's the built clang that's having
    trouble. Is there some CMake variable to give the built clang a set of
    default options to use?
    
                             -David

Moreover, new Apple SDKs don’t include libraries anymore, and uses tbd files instead. That’s probably why lld can’t find System library.