This is an archive of the discontinued LLVM Phabricator instance.

[COMPILER-RT] Fix CMake build for Apple/Darwin without Xcode and for universal build
Needs ReviewPublic

Authored by jonthn on Apr 9 2015, 1:31 PM.

Details

Summary

Currently it's not possible to build compiler-rt when there is no Xcode installed and only with CLT (Command Line Tools)

See https://llvm.org/bugs/show_bug.cgi?id=23162

Moreover this patch also fix detection of possible architectures to be built fo sanitizer libraries

Diff Detail

Event Timeline

jonthn updated this revision to Diff 23529.Apr 9 2015, 1:31 PM
jonthn retitled this revision from to Fix CMake 'compiler-rt' for Apple/Darwin without Xcode and/or for a universal build .
jonthn updated this object.
jonthn edited the test plan for this revision. (Show Details)
jonthn set the repository for this revision to rL LLVM.
jonthn retitled this revision from Fix CMake 'compiler-rt' for Apple/Darwin without Xcode and/or for a universal build to [COMPILER-RT] Fix CMake build for Apple/Darwin without Xcode and for universal build .Apr 19 2015, 4:23 AM
jonthn added a subscriber: Unknown Object (MLST).

I'll let Kuba look into it.

cmake/config-ix.cmake
164

shouldn't this be set/unset in test_target_arch?

kubamracek edited edge metadata.Apr 21 2015, 2:13 AM

I just tried building without this patch on a OS X 10.10 system, without Xcode, just CLTools installed, and compiler-rt builds fine for me. Can you tell what is your OS version, CLTools version, CMake configure line, and the exact error message that you are getting?

It seems to me that when xcrun or xcodebuild returns an error message, it goes to stderr which is suppressed with ERROR_FILE /dev/null and the result string really is an empty string in case of an error.

It's on OSX 10.7 (but I also thought that a redirection to /dev/null would have done the trick).

Information of the system :

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.7.5
BuildVersion:   11G63


$ pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
package-id: com.apple.pkg.DeveloperToolsCLI
version: 4.6.0.0.1.1365549073

An example of the error I get

[ 15%] Built target compiler-rt-headers
Scanning dependencies of target lsan
[ 15%] Built target lsan
Scanning dependencies of target RTUbsan_standalone.iossim
[ 15%] Building CXX object projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan_standalone.iossim.dir/ubsan_init_standalone.cc.o
clang-3.4: error: no such file or directory: 'returned'
clang-3.4: error: no such file or directory: 'unexpected'
clang-3.4: error: no such file or directory: 'error.'
clang-3.4: warning: /usr/bin/xcode-select: 'linker' input unused
clang-3.4: warning: no such sysroot directory: 'Error:'
make[2]: *** [projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan_standalone.iossim.dir/ubsan_init_standalone.cc.o] Error 1
make[1]: *** [projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan_standalone.iossim.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

The command that fails during CMake :

$ xcodebuild -version -sdk iphonesimulator.internal Path 2>/dev/null
Error: /usr/bin/xcode-select returned unexpected error.

which gives in the final Makefile :

./lib/asan/CMakeFiles/clang_rt.asan_iossim_dynamic.dir/flags.make:CXX_FLAGS = -I/Users/user/A/llvm/build/../projects/libcxx/include/ -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -std=c++11 -Wall -std=c++11 -O3 -DNDEBUG -arch x86_64 -fPIC -I/Users/user/A/llvm/build/projects/compiler-rt/lib/asan -I/Users/user/A/llvm/projects/compiler-rt/lib/asan -I/Users/user/A/llvm/build/include -I/Users/user/A/llvm/include -I/Users/user/A/llvm/projects/compiler-rt/lib/asan/..     -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fno-rtti -ftls-model=initial-exec -stdlib=libc++ -mios-simulator-version-min=7.0 -isysroot Error: /usr/bin/xcode-select returned unexpected error.

Finally the CMake command I use :

cmake -DCMAKE_INSTALL_PREFIX=/tmp/A -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_LIBCXX=ON -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_CXX_FLAGS=-I$(pwd)/../projects/libcxx/include/ -DCMAKE_SHARED_LINKER_FLAGS=-L$(pwd)/lib/ -DCMAKE_OSX_ARCHITECTURES="x86_64;i386"

Did you have time to check/decide how to handle this case ?

Or do you need more information ?

I was able to reproduce the CMake failure on 10.7, but I keep running into an unrelated issue (https://llvm.org/bugs/show_bug.cgi?id=23539) that prevents me from building compiler-rt successfully on 10.7. The first part of the change (CMakeLists.txt) looks good to me, but could you add a comment explaining that "we unset the ${var} if the return status is non-zero" or something similar?

For the second part (cmake/config-ix.cmake), is there a way to have the if(APPLE)... parts inside test_target_arch, as Alexey suggested?

Ok. I'll make the change and provide a new patch and I'll try to make the change in test_target_arch.

Regarding your problem building on 10.7 I usually build at the same time a new libcxx to avoid this problem.

jonthn updated this revision to Diff 26988.Jun 2 2015, 11:13 AM
jonthn edited edge metadata.
jonthn removed rL LLVM as the repository for this revision.
  • Add comments
  • Move all the selection of -arch flag in test_target_arch