Building LLVM/Clang on Bash on Ubuntu on Windows


Bash on Ubuntu on Windows 上で Bazel を試してみたい。 ウォーミングアップに LLVM/Clang のビルドを実施してみる。




~/win/ubuntu/refs$ sudo apt-get install gcc g++ make cmake subversion

LLVM/Clang のビルド


~/win/ubuntu/refs$ ls llvm
bindings        CODE_OWNERS.TXT  docs      lib    RELEASE_TESTERS.TXT  test       utils
cmake           configure        examples  LICENSE.TXT    projects      resources            tools
CMakeLists.txt  CREDITS.TXT      include   LLVMBuild.txt  README.txt    runtimes             unittests

~/win/ubuntu/refs$ mkdir build

~/win/ubuntu/refs$ cd build

~/win/ubuntu/refs/build$ cmake -G "Unix Makefiles" ../llvm
CMake Error at CMakeLists.txt:3 (cmake_minimum_required):
  CMake 3.4.3 or higher is required.  You are running version

-- Configuring incomplete, errors occurred!```

~/win/ubuntu/refs/build$ cd ..

CMake が古いじゃないか

~/win/ubuntu/refs$ mkdir cmake 

~/win/ubuntu/refs$ cd cmake

~/win/ubuntu/refs/cmake$ wget

~/win/ubuntu/refs/cmake$ tar xzf cmake-3.6.1.tar.gz

~/win/ubuntu/refs/cmake$ cd cmake-3.6.1/

~/win/ubuntu/refs/cmake/cmake-3.6.1$ ./bootstrap --prefix=/home/ichi/bin
CMake 3.6.1, Copyright 2000-2016 Kitware, Inc.
CMake has bootstrapped.  Now run make.

~/win/ubuntu/refs/cmake/cmake-3.6.1$ make -j 8 --prefix=/home/ichi/bin
[  0%] Building C object Utilities/cmcompress/CMakeFiles/cmcompress.dir/cmcompress.c.o
[100%] Built target ctest

~/win/ubuntu/refs/cmake/cmake-3.6.1$ make install
[  3%] Built target cmsys
-- Installing: /home/ichi/share/cmake-3.6/completions/ctest

~/win/ubuntu/refs/cmake/cmake-3.6.1$ cd ../../build

~/win/ubuntu/refs/build$ cmake -G "Unix Makefiles" ../llvm

~/win/ubuntu/refs/build$ cmake -G "Unix Makefiles" ../llvm
-- The C compiler identification is GNU 4.8.4
-- Build files have been written to: /home/ichi/win/ubuntu/refs/build

~/win/ubuntu/refs/build$ make -j8
Scanning dependencies of target LLVMSupport
[100%] Built target c-index-test
~/win/ubuntu/refs/build$ sudo make install

~/win/ubuntu/refs/build$ clang
clang-4.0: error: no input files

~/win/ubuntu/refs/build$ cd ~/tmp

~/tmp$ cat > a.cpp
constexpr int fact(int n)
    if (n <= 0)
        return 1;
        return n * fact(n-1);

static_assert(fact(10) == 3628800, ""); // OK
static_assert(fact(1) == 0, "");        // error

int main()
    return 0;

~/tmp$ clang --std=c++14 a.cpp
a.cpp:10:1: error: static_assert failed ""
static_assert(fact(1) == 0, "");        // error
^             ~~~~~~~~~~~~
1 error generated.