Skip to content

Commit 4cca032

Browse files
committedFeb 28, 2021
Use versioned LLVM toolchain binaries
This allows SMACK to not interfere with existing installed compilers.
1 parent 395ef11 commit 4cca032

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed
 

‎bin/build.sh

+1-7
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,6 @@ if [ ${INSTALL_DEPENDENCIES} -eq 1 ] && [ "$TRAVIS" != "true" ] ; then
278278
sudo apt-get update
279279

280280
sudo apt-get install -y ${DEPENDENCIES}
281-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_SHORT_VERSION} 30
282-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_SHORT_VERSION} 30
283-
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${LLVM_SHORT_VERSION} 30
284-
sudo update-alternatives --install /usr/bin/llvm-link llvm-link /usr/bin/llvm-link-${LLVM_SHORT_VERSION} 30
285-
sudo update-alternatives --install /usr/bin/llvm-dis llvm-dis /usr/bin/llvm-dis-${LLVM_SHORT_VERSION} 30
286281
;;
287282

288283
*)
@@ -464,7 +459,6 @@ fi
464459
if [ ${INSTALL_DEV_DEPENDENCIES} -eq 1 ] ; then
465460
sudo apt-get install -y python3-pip clang-format-${LLVM_SHORT_VERSION}
466461
sudo pip3 install -U flake8
467-
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-${LLVM_SHORT_VERSION} 30
468462
if [ "${GITHUB_ACTIONS}" = "true" ] ; then
469463
exit 0
470464
fi
@@ -480,7 +474,7 @@ if [ ${BUILD_SMACK} -eq 1 ] ; then
480474

481475
mkdir -p ${SMACK_DIR}/build
482476
cd ${SMACK_DIR}/build
483-
cmake ${CMAKE_INSTALL_PREFIX} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug .. -G Ninja
477+
cmake ${CMAKE_INSTALL_PREFIX} -DCMAKE_BUILD_TYPE=Debug .. -G Ninja
484478
ninja
485479

486480
if [ -n "${CMAKE_INSTALL_PREFIX}" ] ; then

‎format/run-clang-format.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,19 @@ def print_trouble(prog, message, use_colors):
203203

204204

205205
def main():
206+
207+
with open(os.path.join(os.path.dirname(os.path.dirname(
208+
os.path.abspath(__file__))), 'bin', 'versions'), 'r') as f:
209+
for line in f.readlines():
210+
if line.startswith('LLVM_SHORT_VERSION='):
211+
llvm_version = line.strip()[len('LLVM_SHORT_VERSION='):].replace('"', '')
212+
206213
parser = argparse.ArgumentParser(description=__doc__)
207214
parser.add_argument(
208215
'--clang-format-executable',
209216
metavar='EXECUTABLE',
210-
help='path to the clang-format executable',
211-
default='clang-format')
217+
help='path to the clang-format executable (default: %(default)s)',
218+
default='clang-format-' + llvm_version)
212219
parser.add_argument(
213220
'--extensions',
214221
help='comma separated list of file extensions (default: {})'.format(

‎share/smack/frontend.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
from .utils import temporary_file, try_command, temporary_directory
66
from .versions import RUST_VERSION
7+
from .versions import LLVM_SHORT_VERSION
78

89
# Needed for cargo operations
910
try:
@@ -85,8 +86,19 @@ def smack_lib():
8586
return os.path.join(smack_root(), 'share', 'smack', 'lib')
8687

8788

89+
def llvm_exact_bin(name):
90+
return name + '-' + LLVM_SHORT_VERSION
91+
92+
8893
def default_clang_compile_command(args, lib=False):
89-
cmd = ['clang', '-c', '-emit-llvm', '-O0', '-g', '-gcolumn-info']
94+
cmd = [
95+
llvm_exact_bin('clang'),
96+
'-c',
97+
'-emit-llvm',
98+
'-O0',
99+
'-g',
100+
'-gcolumn-info'
101+
]
90102
# Starting from LLVM 5.0, we need the following two options
91103
# in order to enable optimization passes.
92104
# See: https://stackoverflow.com/a/46753969.
@@ -165,7 +177,7 @@ def fortran_compile_to_bc(input_file, compile_command, args):
165177
'-i',
166178
's/i32 1, !\"Debug Info Version\"/i32 2, !\"Debug Info Version\"/g',
167179
ll])
168-
try_command(['llvm-as', ll])
180+
try_command([llvm_exact_bin('llvm-as'), ll])
169181
try_command(['rm', ll])
170182
bc = '.'.join(ll.split('.')[:-1] + ['bc'])
171183
return bc
@@ -189,7 +201,7 @@ def clang_frontend(input_file, args):
189201
def clang_plusplus_frontend(input_file, args):
190202
"""Generate LLVM IR from C++ language source(s)."""
191203
compile_command = default_clang_compile_command(args)
192-
compile_command[0] = 'clang++'
204+
compile_command[0] = llvm_exact_bin('clang++')
193205
return compile_to_bc(input_file, compile_command, args)
194206

195207

@@ -263,9 +275,17 @@ def json_compilation_database_frontend(input_file, args):
263275
if 'objects' in cc:
264276
# TODO what to do when there are multiple linkings?
265277
bit_codes = [re.sub('[.]o$', '.bc', f) for f in cc['objects']]
266-
try_command(['llvm-link', '-o', args.bc_file] + bit_codes)
267-
try_command(['llvm-link', '-o', args.linked_bc_file,
268-
args.bc_file] + default_build_libs(args))
278+
try_command([
279+
llvm_exact_bin('llvm-link'),
280+
'-o',
281+
args.bc_file
282+
] + bit_codes)
283+
try_command([
284+
llvm_exact_bin('llvm-link'),
285+
'-o',
286+
args.linked_bc_file,
287+
args.bc_file
288+
] + default_build_libs(args))
269289

270290
else:
271291
command = cc['command']
@@ -316,7 +336,7 @@ def cargo_frontend(input_file, args):
316336
os.path.basename(input_file))[0],
317337
'.bc',
318338
args)
319-
try_command(['llvm-link'] + bcs + ['-o', bc_file])
339+
try_command([llvm_exact_bin('llvm-link')] + bcs + ['-o', bc_file])
320340
return bc_file
321341

322342

@@ -410,7 +430,7 @@ def cplusplus_build_libs(args):
410430
libs = ['smack.cpp']
411431

412432
compile_command = default_clang_compile_command(args, True)
413-
compile_command[0] = 'clang++'
433+
compile_command[0] = llvm_exact_bin('clang++')
414434

415435
for c in [os.path.join(smack_lib(), c) for c in libs]:
416436
bc = compile_to_bc(c, compile_command, args)
@@ -443,8 +463,8 @@ def link_bc_files(bitcodes, libs, args):
443463
for build_lib in libs:
444464
smack_libs += build_lib(args)
445465

446-
try_command(['llvm-link', '-o', args.bc_file] + bitcodes)
447-
try_command(['llvm-link', '-o', args.linked_bc_file,
466+
try_command([llvm_exact_bin('llvm-link'), '-o', args.bc_file] + bitcodes)
467+
try_command([llvm_exact_bin('llvm-link'), '-o', args.linked_bc_file,
448468
args.bc_file] + smack_libs)
449469

450470
# import here to avoid a circular import

0 commit comments

Comments
 (0)
Please sign in to comment.