-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup_bazel
executable file
·76 lines (66 loc) · 1.81 KB
/
setup_bazel
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
#!/usr/bin/env python3
import os
import subprocess
from sys import platform
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
def run_cmd(cmd):
try:
output = subprocess.check_output(
cmd.split(" "), stderr=subprocess.STDOUT
).decode()
except subprocess.CalledProcessError as e:
output = e.output.decode()
raise RuntimeError(output)
return output.rstrip()
def main():
# create .bazelrc
bazelrc_path = os.path.join(ROOT_DIR, ".bazelrc")
with open(bazelrc_path, "w") as f:
# TODO: add ubsan + msan builds also
f.write(
"""
build --cxxopt="-std=c++14"
build --cxxopt="-Wall"
build:san --strip=never
build:san --copt -fsanitize=address
build:san --copt -fsanitize=undefined
build:san --copt -DADDRESS_SANITIZER
build:san --copt -O2
build:san --copt -g
build:san --copt -fno-omit-frame-pointer
build:san --linkopt -fsanitize=address
build:san --linkopt -fsanitize=alignment
"""
)
# MacOS
if platform == "darwin":
# get omp path
omp_prefix = run_cmd("brew --prefix libomp")
omp_lib = os.path.join(omp_prefix, "lib")
f.write(
f"""
# Tell Bazel not to use the full Xcode toolchain on Mac OS
build --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
build --cxxopt -Xclang
build --cxxopt -fopenmp
build --linkopt -L{omp_lib}
build --linkopt -lomp
build:gcc --action_env=CC=gcc-11
build:gcc --action_env=CXX=g++-11"""
)
else:
# Linux
f.write(
"""
# Linux Clang
build --cxxopt -fopenmp
build --linkopt -fopenmp
build:clang --action_env=CC=clang
build:clang --action_env=CXX=clang++
# Linux GCC (default)
build --action_env=CC=gcc
build --action_env=CXX=g++
"""
)
if __name__ == "__main__":
main()