-
Notifications
You must be signed in to change notification settings - Fork 46
/
manyclangs-cmake
executable file
·91 lines (75 loc) · 3.07 KB
/
manyclangs-cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2021 Arm Limited or its affiliates and Contributors. All rights reserved.
[[ "$TRACE" ]] && set -x
set -euo pipefail
LLVM_SRCDIR="${1-../llvm}"
LLVM_TGTDIR="${2-.}"
if [[ ! -d "$LLVM_SRCDIR" ]]
then
echo 'usage: manyclangs-cmake <path/to/llvm-project/llvm> <build_dir>
Configure
This script probably makes assumptions that the build directory
is inside the llvm-project directory.' 1>&2
exit 1
fi
# Abspath to specified LLVM source directory.
FILE_PREFIX="$(dirname "$(realpath "$LLVM_SRCDIR")")"
# Version number of clang used to build the pack. Chosen because it's what is
# easily available in the universe repository on Ubuntu 20.04 which is a recent
# but not-too-new distribution with long term support, and therefore easy for
# others to reproduce by running this script.
# Defaults to "-12".
BUILDER_CLANG_VERSION_SUFFIX=${BUILDER_CLANG_VERSION_SUFFIX--12}
COMPILER_FLAGS=(
# Flags which improve the compression ratio.
-ffunction-sections
-fdata-sections
-mno-outline
# Flags to make resulting build not depend on abspath of sources.
-no-canonical-prefixes
"-ffile-prefix-map=${FILE_PREFIX}="
"-fmacro-prefix-map=${FILE_PREFIX}="
# Don't embed the compiler ident into the objects; this allows using an
# LTO/PGO build of the compiler which is faster and produces identical
# binaries aside from the ident string.
-fno-ident
)
FLAGS=(
"-DCMAKE_EXPORT_COMPILE_COMMANDS=On"
# Rel + assertions build.
"-DCMAKE_BUILD_TYPE=Release"
"-DLLVM_ENABLE_ASSERTIONS=On"
"-DLLVM_ENABLE_PROJECTS=clang"
# VC revision is written into binaries with manyclangs-build. This is not
# used because it invalidates tablegen which causes a lot of rebuilding.
"-DLLVM_APPEND_VC_REV=Off"
# Compiler + linker.
"-DCMAKE_C_COMPILER=clang${BUILDER_CLANG_VERSION_SUFFIX}"
"-DCMAKE_CXX_COMPILER=clang++${BUILDER_CLANG_VERSION_SUFFIX}"
"-DCMAKE_C_FLAGS=${COMPILER_FLAGS[*]}"
"-DCMAKE_CXX_FLAGS=${COMPILER_FLAGS[*]}"
# Full path is required due to -no-canonical-prefixes
"-DLLVM_USE_LINKER=${LLVM_USE_LINKER-/usr/bin/ld.lld"${BUILDER_CLANG_VERSION_SUFFIX}"}"
# These are necessary for reproducibility in conjunction with
# CCACHE_BASEDIR, search for other comments referencing this variable.
"-DCMAKE_C_COMPILER_LAUNCHER=ccache"
"-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
# Bindings can slow down configuration-time, and we don't use them.
"-DLLVM_ENABLE_BINDINGS=Off"
# We don't care about warnings for this use-case.
"-DLLVM_ENABLE_WARNINGS=Off"
# Try to minimize dependencies, at the expense of minor features.
"-DLLVM_ENABLE_LIBXML2=Off"
"-DLLVM_ENABLE_ZLIB=Off"
"-DLLVM_ENABLE_Z3_SOLVER=Off"
# Faster builds(?)
"-DCLANG_TOOLING_BUILD_AST_INTROSPECTION=Off"
# Shrink ninja files.
"-DCLANG_INCLUDE_TESTS=Off"
"-DLLVM_BUILD_TESTS=Off"
"-DLLVM_INCLUDE_BENCHMARKS=Off"
"-DLLVM_INCLUDE_EXAMPLES=Off"
"-DLLVM_INCLUDE_TESTS=Off"
)
cmake -GNinja "${FLAGS[@]}" -S "$LLVM_SRCDIR" -B "$LLVM_TGTDIR"