Created
September 26, 2016 21:58
-
-
Save andrey-malets/2666b7c643e7faf90ea99572838b7902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -ex | |
PLATFORM=${PLATFORM:?no platform, available: mac, linux} | |
CLANG_PATH=${CLANG_PATH:?no clang path, need some compiler} | |
CLEANUP=${CLEANUP:-true} | |
CWD=$( (cd $(dirname "$0") && pwd) ) | |
DC=$CWD | |
LLVM="$CWD/../llvm" | |
LLVM_BIN="$CWD/../llvm-bin" | |
CLANG="$CWD/../clang" | |
CLANG_BIN="$CWD/../clang-bin" | |
CLANG_CC="$CLANG_PATH/clang" | |
CLANG_CXX="$CLANG_PATH/clang++" | |
CLANG_VERSION="$($CLANG_CC --version | head -n1)" | |
LIBCXX_PATH="$DC/out/Test.gn" | |
INCLUDE_FILTER=(-name '*.def' -print0 -or | |
-name '*.h' -print0 -or | |
-name '*.inc' -print0) | |
LIB_FILTER=(-name '*.a' -print0) | |
DEST="$DC/build/llvm/$PLATFORM" | |
configure_dc_compiler() { | |
cat > "$1" <<EOF | |
path: "$CLANG_CC" | |
version: "$CLANG_VERSION" | |
EOF | |
} | |
make_dest_dirs() { | |
find "$@" -type d -print0 | xargs -0 -I{} mkdir -p "$DEST/{}" | |
} | |
to_dest() { | |
xargs -0 -I{} cp {} "$DEST/{}" | |
} | |
( | |
pushd "$DC" | |
"$CLEANUP" && git clean -xffd "out" | |
git checkout build | |
PATH="$CLANG_PATH:$PATH" ./build/configure | |
PATH="$CLANG_PATH:$PATH" ninja -C out/Test.gn c++ | |
popd | |
) | |
( | |
pushd "$LLVM" | |
"$CLEANUP" && git checkout . | |
"$CLEANUP" && git apply - << EOP | |
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index 8d80866..29d905d 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -684,6 +684,10 @@ if(APPLE AND DARWIN_LTO_LIBRARY) | |
"\${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,\${DARWIN_LTO_LIBRARY}") | |
endif() | |
+SET(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -fPIC -nostdinc++") | |
+SET(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -I \ | |
$DC/src/third_party/libcxxabi/exported/include") | |
+SET(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -I \ | |
$DC/src/third_party/libcxx/exported/include") | |
+ | |
# Work around a broken bfd ld behavior. When linking a binary with a | |
# foo.so library, it will try to find any library that foo.so uses and | |
# check its symbols. This is wasteful (the check was done when foo.so | |
@@ -694,6 +698,15 @@ if (UNIX AND NOT APPLE AND NOT \${CMAKE_SYSTEM_NAME} MATCHES "SunOS|AIX") | |
"\${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined") | |
endif() | |
+SET(CMAKE_MODULE_LINKER_FLAGS "\${CMAKE_MODULE_LINKER_FLAGS} \\ | |
+ -L $LIBCXX_PATH -stdlib=libc++ -lc -nodefaultlibs") | |
+SET(CMAKE_SHARED_LINKER_FLAGS "\${CMAKE_SHARED_LINKER_FLAGS} \\ | |
+ -L $LIBCXX_PATH -stdlib=libc++ -lc++abi") | |
+SET(CMAKE_EXE_LINKER_FLAGS "\${CMAKE_EXE_LINKER_FLAGS} \\ | |
+ -L $LIBCXX_PATH -stdlib=libc++ -lc++abi") | |
+SET(CMAKE_EXE_LINKER_FLAGS "\${CMAKE_EXE_LINKER_FLAGS} \\ | |
+ -Wl,-rpath,\"$LIBCXX_PATH\"") | |
+ | |
set(CMAKE_INCLUDE_CURRENT_DIR ON) | |
include_directories( \${LLVM_INCLUDE_DIR} \${LLVM_MAIN_INCLUDE_DIR}) | |
EOP | |
true | |
) | |
( | |
pushd "$CLANG" | |
"$CLEANUP" && git checkout . | |
"$CLEANUP" && git apply - << EOP | |
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index 53e5f33..a4696d3 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -298,6 +298,19 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE) | |
endif() | |
endif () | |
+SET(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -fPIC -nostdinc++") | |
+SET(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -I \ | |
$DC/src/third_party/libcxxabi/exported/include") | |
+SET(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -I \ | |
$DC/src/third_party/libcxx/exported/include") | |
+ | |
+SET(CMAKE_MODULE_LINKER_FLAGS "\${CMAKE_MODULE_LINKER_FLAGS} \\ | |
+ -L $LIBCXX_PATH -stdlib=libc++ -lc -nodefaultlibs") | |
+SET(CMAKE_SHARED_LINKER_FLAGS "\${CMAKE_SHARED_LINKER_FLAGS} \\ | |
+ -L $LIBCXX_PATH -stdlib=libc++ -lc++abi") | |
+SET(CMAKE_EXE_LINKER_FLAGS "\${CMAKE_EXE_LINKER_FLAGS} \\ | |
+ -L $LIBCXX_PATH -stdlib=libc++ -lc++abi") | |
+SET(CMAKE_EXE_LINKER_FLAGS "\${CMAKE_EXE_LINKER_FLAGS} \\ | |
+ -Wl,-rpath,\"$LIBCXX_PATH\"") | |
+ | |
# Determine HOST_LINK_VERSION on Darwin. | |
set(HOST_LINK_VERSION) | |
if (APPLE) | |
EOP | |
true | |
) | |
( | |
"$CLEANUP" && rm -rf "$LLVM_BIN" | |
"$CLEANUP" && mkdir "$LLVM_BIN" | |
pushd "$LLVM_BIN" | |
configure_dc_compiler .distclang | |
CC=/usr/bin/dist-clang/clang CXX=/usr/bin/dist-clang/clang++ \ | |
cmake "$LLVM" -DCMAKE_BUILD_TYPE=RELEASE | |
make -j60 | |
) | |
( | |
"$CLEANUP" && rm -rf "$CLANG_BIN" | |
"$CLEANUP" && mkdir "$CLANG_BIN" | |
pushd "$CLANG_BIN" | |
configure_dc_compiler .distclang | |
CC=/usr/bin/dist-clang/clang CXX=/usr/bin/dist-clang/clang++ \ | |
PATH="$LLVM_BIN/bin:$PATH" \ | |
cmake "$CLANG" -DCMAKE_BUILD_TYPE=RELEASE | |
make -j60 | |
) | |
rm -rf "$DEST/"{include,lib} | |
( | |
pushd "$LLVM" | |
make_dest_dirs include | |
find include "${INCLUDE_FILTER[@]}" | to_dest | |
) | |
( | |
pushd "$LLVM_BIN" | |
make_dest_dirs include lib | |
find include "${INCLUDE_FILTER[@]}" | to_dest | |
./bin/llvm-config --libnames | tr '\n' ' ' | | |
xargs -d' ' -I {} cp lib/{} "$DEST/lib/{}" | |
) | |
( | |
pushd "$CLANG" | |
make_dest_dirs include | |
find include "${INCLUDE_FILTER[@]}" | to_dest | |
) | |
( | |
pushd "$CLANG_BIN" | |
make_dest_dirs lib | |
find include "${INCLUDE_FILTER[@]}" | to_dest | |
find lib "${LIB_FILTER[@]}" | to_dest | |
) | |
( | |
pushd "$DC" | |
pushd "build/llvm" | |
PATH="$LLVM_BIN/bin:$PATH" python llvm.py | |
cat >> llvm.gni << EOF | |
if (host_os == "linux") { | |
llvm_system_libs += [ "dl" ] | |
} | |
EOF | |
popd | |
PATH="$CLANG_PATH:$PATH" ninja -C out/Test.gn Tests | |
./build/run_gtest_tests | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment