Git Product home page Git Product logo

install-clang's Introduction

install-clang

This script installs self-contained standalone 9.0 versions of clang, LLVM, libc++, compiler-rt, libc++abi, lldb, and lld, on macOS and Linux, including linking clang and LLVM against libc++ themselves as well. The script keeps all of the installation within a given target prefix (e.g., /opt/clang), and hence separate from any already installed compilers, libraries, and include files. In particular, you can later uninstall everything easily by just deleting, e.g., /opt/clang. Furthermore, as long as the prefix path is writable, the installation doesn't need root privileges.

If you have used older version of this script before, see News below for changes.

Usage

To see the available options, use -h:

> ./install-clang -h
Usage: install-clang [<options>] <install-prefix>

Available options:
    -A         enables assertions in LLVM libraries
    -b         build type (Release, Debug, RelWithDebInfo) [default: Release]
    -c         skip cloning repositories, assume they are in place
    -C         clean up after build by deleting the LLVM/clang source/build directories
    -h|-?      display this help
    -j <n>     build with <n> threads in parallel [default: 4]
    -m         use git/master instead of preconfigured versions
    -s <stage> begin build from <stage> [0, 1, 2]
    -S         build, and link against, shared libraries (this is the default on macOS)
    -u         update an existing build in <prefix> instead of installing new

Environment variables:
    CC         path to the C compiler for bootstrapping
    CXX        path to the C++ compiler for bootstrapping

For example, to build Clang on a machine with multiple cores and install it in /opt/clang, you can use:

> ./install-clang -j 16 /opt/clang

Once finished, just prefix your PATH with <prefix>/bin and you're ready to use the new binaries:

> clang++ --std=c++11 --stdlib=libc++ test.cc -o a.out && ./a.out
Hello, Clang!

By default, install-clang currently installs the 9.0 release branch of https://github.com/llvm (the "mono repository"). Adding -m on the command line instructs the script to use the current git master version instead. The script downloads the source code from GitHub and compiles the pieces as needed. Other OSs than macOS and Linux are not currently supported.

The script also has an update option -u that allows for catching up with upstream repository changes without doing the complete compile/install-from-scratch cycle again. Note, however, that unless coupled with -m, this flag has no immediate effect since the git versions to use are hardcoded to the Clang/LLVM release version.

Doing a self-contained Clang installation is a bit more messy than one would hope because the projects make assumptions about specific system-wide installation paths to use. The install-clang script captures some trial-and-error I (and others) went through to get an independent setup working. It compiles Clang up to three times, bootstrapping things with the system compiler as it goes. It also patches some of the Clang/LLVM projects to incorporate the installation prefix into configuration and search paths, and also fixes/tweaks a few other things as well.

Docker

install-clang comes with a Dockerfile to build a Docker image, based on Ubuntu, with Clang then in /opt/clang:

# make docker-build && make docker-run
[... get a beer ...]
root@f39b941f177c:/# clang --version
clang version 8.0.0
Target: x86_64--linux-gnu
Thread model: posix
root@f39b941f177c:/# which clang
/opt/clang/bin/clang

A prebuilt image is available at https://hub.docker.com/r/rsmmr/clang/ .

News

Version for Clang 9 (master)

  • Switch to using the LLVM "mono repo" and adapt script's build process.

  • Build libunwind, and link against it.

  • macOS: Allow usage of libc++'s filesystem on non-10.15 systems.

  • macOS: Add -rpath <prefix>/lib to linker arguments (we already did this for Linux).

Version for Clang 8 (git branch release_80)

The install-clang script for Clang 8.0 comes with these changes compared to the 6.0 version:

  • Fix computed RPATH when the clang binary has been symlinked from elsehwere (#18).

  • We now honor preset environment variables CFLAGS, CXXFLAGS, and LDFLAGS to find dependencies.

  • On macOS, we now set clang's DEFAULT_SYSROOT to the current macOS SDK.

  • We backport clang-format's new options SpaceAfterLogicalNot and SpacesInConditionalStatement from git.

  • We build, and link against, static libraries by default (just as LLVM does), except on macOS. Option -S switches back to shared libraries.

  • Removed any customziation for FreeBSD; support had been untested in a long time.

Version for Clang 6 (git branch release_60)

The install-clang script for Clang 6.0 comes with these changes compared to the 3.5 version:

  • The default build type is now Release. It used to be RelWithDebInfo.

  • lldb and lld seem to built correctly on both Linux and Darwin now and both are enabled by default.

  • FreeBSD support is untested and hence disabled for now. Will be reactivated once confirmed that it's working.

  • On macOS, we no longer build for i386.

  • The Docker image is now based on Ubuntu Xenial and puts everything into /opt/clang.

Version for Clang 3.5 (git tag release_35)

The install-clang script for Clang 3.5 comes with a few changes compared to earlier version:

  • The script now supports FreeBSD as well. (Contributed by Matthias Vallentin).

  • The script now generally shared libraries for LLVM and clang, rather than static ones.

  • As libc++abi now works well on Linux as well, we use it generally and no longer support libcxxrt.

  • There are now command line options to select build mode and assertions explicitly.

  • There's no 3rd phase anymore building assertion-enabled LLVM libraries, as changing compilation options isn't useful with shared libraries.

  • In return, there's a phase 0 now if the system compiler isn't a clang; libc++abi needs clang that for its initial compilation already.

  • There's now a Dockerfile to build an image with Clang/LLVM in /opt/clang.

install-clang's People

Contributors

jsiwek avatar mavam avatar raphaelcohn avatar rsmmr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

install-clang's Issues

Build fails due to sanitizer compilation error

Hi, thx for this tool!
Unfortunately I am unable to install due to a compilation error :

[ 18%] Building CXX object projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_common_libcdep.cc.o
/home/carlos/clang/src/llvm/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:1131:1: error: 'assertion_failed__1131' declared as an array with a negative size
CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
/home/carlos/clang/src/llvm/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h:1437:3: note: expanded from macro 'CHECK_SIZE_AND_OFFSET'
  COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *) NULL)->MEMBER) == \
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/carlos/clang/src/llvm/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:336:30: note: expanded from macro 'COMPILER_CHECK'
#define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/carlos/clang/src/llvm/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:342:57: note: expanded from macro 'IMPL_COMPILER_ASSERT'
    typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
                                                        ^~~~~~~~~~~~~~~
1 error generated.  

Carlos

Runtime dynamic linker error when executing compiled program

I need to add the path to libc++.so.1 (/opt/clang/lib) to LD_LIBRARY_PATH to fix this runtime error.

./a.out: error while loading shared libraries: libc++.so.1: cannot open shared object file: No such file or directory

Adding that path to the ldconfig is a better solution I think, and it could be put directly in your Dockerfile. Here's what I'm doing in mine.

RUN echo "/opt/clang/lib" > /etc/ld.so.conf.d/clang.conf
RUN ldconfig

This might be a problem because one of my build script which I didn't want to change, had clang path hardcoded to /usr/bin/clang, and so I created a link there first in my docker file before compiling:

RUN ln -s /opt/clang/bin/clang++ /usr/bin/clang++

Thanks for making this btw !

Patch needed for llvm/projects/CMakeLists.txt

Looks like there is an order-of-build files issue. After the attached change, install-clang builds correctly.

diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt
index 2f025bd..915a35c 100644
--- a/projects/CMakeLists.txt
+++ b/projects/CMakeLists.txt
@@ -13,6 +13,8 @@ foreach(entry ${entries})
   endif()
 endforeach(entry)

+add_llvm_external_project(libcxxabi)
+
 # Also add in libc++ and compiler-rt trees if present (and we have
 # a sufficiently recent version of CMake where required).
 if(${LLVM_BUILD_RUNTIME})
@@ -27,4 +29,3 @@ if(${LLVM_BUILD_RUNTIME})
 endif()

 add_llvm_external_project(dragonegg)
-add_llvm_external_project(libcxxabi)

panel.h not found

Not sure if this belongs here. Seems to work fine until the very end where I get:

[ 74%] Building CXX object tools/lldb/source/Core/CMakeFiles/lldbCore.dir/IOHandler.cpp.o
/opt/llvm/src/llvm/tools/lldb/source/Core/IOHandler.cpp:14:10: fatal error: 'panel.h' file not found
#include <panel.h>
         ^~~~~~~~~
1 error generated.
make[2]: *** [tools/lldb/source/Core/CMakeFiles/lldbCore.dir/build.make:447: tools/lldb/source/Core/CMakeFiles/lldbCore.dir/IOHandler.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:65074: tools/lldb/source/Core/CMakeFiles/lldbCore.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
===
=== Failed building LLVM/clang at stage 2
===

panel.h is present:

$ locate panel.h
/usr/include/ncurses/panel.h
/usr/include/ncursesw/panel.h
$ /opt/llvm/bin/clang++ --version
clang version 8.0.1 (https://github.com/llvm-mirror/clang.git 29cb26a72b28cbb5ba43e67aecb3a8cf2b01fee0) (https://github.com/llvm-mirror/llvm.git 18e41dc964f916504ec90dba523826ac74d235c4)
Target: x86_64-suse-linux
Thread model: posix
InstalledDir: /opt/llvm/bin

Thanks for this tool!

Linking sometimes fails after update, because of outdated Makefile.llvmbuild

I use install-clang to build up-to-date llvm/clang toolchains from master/trunk and I recently stumbled on the same error described in this mailing-list message:

http://comments.gmane.org/gmane.comp.compilers.llvm.devel/59285

The fix proposed there resolved the issue for me and the wording "Usually, [...] fixes this kind of problem for me." indicates that this sort of problem is common, when updating the codebase.

So I propose to add "rm Makefile.llvmbuild" to install-clang.sh as a precaution when the "update" action is chosen by the user.

Incompatible format of rpath passed to ld on OSX

I've just observed that the way rpath is added to the arguments passed from clang down to ld produces an error on OSX, because the entire argument gets enclosed in double quotes.

Changing:

+  CmdArgs.push_back(Args.MakeArgString("-rpath=" + D.InstalledDir + "/../lib"));

Into:

+  CmdArgs.push_back("-rpath");
+  CmdArgs.push_back(Args.MakeArgString(D.InstalledDir + "/../lib"));

In patches/tools-clang-libpath.patch resolves this error.

unsupported '-fsanitize=thread' / 'i386-pc-linux-gnu'

Dear Madam or Sir,

install-clang fails over the missing '-fsanitize=thread'.
As far as I understood, this is exprected for my platform.
I personally could live without '-fsanitize=thread', but unfortunately the build process is stopped.

Do You have a hint in which CMakefileList (or the like) I can deactivate '-fsanitize=thread'? So I could proceed even without it?

(Is 32 bit really that exotic today?)
(By the way; I started on a FAT partition, this seems to be exotic also. I continued with ext2)

See logs below

Regards
Ralf Hain

/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-stamp/libcxx_tsan-configure-err.log

[100%] Performing configure step for 'libcxx_tsan'
CMake Error at /media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-stamp/libcxx_tsan-configure.cmake:16 (message):
Command failed: 1

'/usr/bin/cmake' '-DCMAKE_C_COMPILER=/media/xubuntu/tr/llvm/src/llvm/build-stage1/./bin/clang' '-DCMAKE_CXX_COMPILER=/media/xubuntu/tr/llvm/src/llvm/build-stage1/./bin/clang' '-DCMAKE_C_FLAGS= -fsanitize=thread' '-DCMAKE_CXX_FLAGS= -fsanitize=thread' '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_INSTALL_PREFIX:PATH=/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan' '-GUnix Makefiles' '/media/xubuntu/tr/llvm/src/llvm/projects/libcxx'

See also

/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-stamp/libcxx_tsan-configure-*.log

make[2]: *** [projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-stamp/libcxx_tsan-configure] Fehler 1
make[1]: *** [projects/compiler-rt/lib/tsan/CMakeFiles/libcxx_tsan.dir/all] Fehler 2
make[1]: *** Warte auf noch nicht beendete Prozesse...
Linking CXX executable ../../bin/llvm-readobj
[100%] Built target llvm-readobj
make: *** [all] Fehler 2
===
=== Faild building LLVM/clang at stage 1
===
------------------------------
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "/media/xubuntu/tr/llvm/src/llvm/build-stage1/./bin/clang"
is not able to compile a simple test program.

It fails with the following output:

Change Dir: /media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-build/CMakeFiles/CMakeTmp

Run Build Command:/usr/bin/make "cmTryCompileExec508344078/fast"

make[3]: Betrete Verzeichnis
'/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-build/CMakeFiles/CMakeTmp'

/usr/bin/make -f CMakeFiles/cmTryCompileExec508344078.dir/build.make
CMakeFiles/cmTryCompileExec508344078.dir/build

make[4]: Betrete Verzeichnis
'/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-build/CMakeFiles/CMakeTmp'

/usr/bin/cmake -E cmake_progress_report
/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-build/CMakeFiles/CMakeTmp/CMakeFiles
1

Building CXX object
CMakeFiles/cmTryCompileExec508344078.dir/testCXXCompiler.cxx.o

/media/xubuntu/tr/llvm/src/llvm/build-stage1/./bin/clang -fsanitize=thread
-o CMakeFiles/cmTryCompileExec508344078.dir/testCXXCompiler.cxx.o -c
/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

clang-3.5: error: unsupported option '-fsanitize=thread' for target
'i386-pc-linux-gnu'

make[4]: Verlasse Verzeichnis
'/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-build/CMakeFiles/CMakeTmp'

make[4]: ***
[CMakeFiles/cmTryCompileExec508344078.dir/testCXXCompiler.cxx.o] Fehler 1
make[3]: Verlasse Verzeichnis
'/media/xubuntu/tr/llvm/src/llvm/build-stage1/projects/compiler-rt/lib/tsan/libcxx_tsan/src/libcxx_tsan-build/CMakeFiles/CMakeTmp'

make[3]: *** [cmTryCompileExec508344078/fast] Fehler 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:7 (project)

Failed patch application causes install script to fail

I have noticed that when running the install-clang script that when running with the default version (release_35), I am getting a broken build due to the patch https://github.com/rsmmr/install-clang/blob/master/patches/fix-external-project-order.patch. This patch does not apply cleanly to release_35 and actually causes the file to have the failed git merge remnants in it. As soon as I manually fixed it the build was able to continue. This specific patch seems to only apply to release_36. Looking at the code it seems that there isn't any code currently to handle failed patches in the install-clang script. It seems like that would fix this problem from happening again.

As a note this is happening for me on Centos 6.7.

docker build failed: cannot find -lcxxabi_shared

I'm doing make docker-build, and it failed at about 30%:

[ 30%] Linking CXX shared library ../../../lib/libc++.so
/usr/bin/ld: cannot find -lcxxabi_shared
collect2: error: ld returned 1 exit status
projects/libcxx/src/CMakeFiles/cxx_shared.dir/build.make:1004: recipe for target 'lib/libc++.so.1.0' failed
make[2]: *** [lib/libc++.so.1.0] Error 1
CMakeFiles/Makefile2:10069: recipe for target 'projects/libcxx/src/CMakeFiles/cxx_shared.dir/all' failed
make[1]: *** [projects/libcxx/src/CMakeFiles/cxx_shared.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

...

Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
===
=== Failed building LLVM/clang at stage 0
===
The command '/bin/sh -c /opt/install-clang/install-clang -j 6 -C /opt/clang' returned a non-zero code: 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.