Skip to content

Commit

Permalink
bazel: custom llvm installation
Browse files Browse the repository at this point in the history
Added ability to use custom LLVM installation

Signed-off-by: Michał Maślanka <[email protected]>
  • Loading branch information
mmaslankaprv committed Jun 12, 2024
1 parent e95d97e commit a214114
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ common --registry=https://bcr.bazel.build
build:libc++ --cxxopt=-stdlib=libc++
build:libc++ --linkopt -lc++

build:llvm --config=libc++

# =================================
# Sanitizer
# =================================
Expand All @@ -36,6 +38,8 @@ build:sanitizer --copt -O1

build:sanitizer-libc++ --config=sanitizer
build:sanitizer-libc++ --config=libc++

build:sanitizer-llvm --config=sanitizer-libc++
# =================================
# Security
# =================================
Expand Down Expand Up @@ -74,3 +78,5 @@ build:release --copt -mllvm
build:release --copt -inline-threshold=2500

try-import %workspace%/user.bazelrc
# import overrides for custom llvm installation
try-import %workspace%/llvm.bazelrc
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,4 @@ vbuild/

# bazel
user.bazelrc
llvm.bazelrc
33 changes: 33 additions & 0 deletions bazel/setup_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# copied from Envoy project(https://github.com/envoyproxy/envoy/blob/main/bazel/setup_clang.sh)

#!/usr/bin/env bash

set -e

BAZELRC_FILE="${BAZELRC_FILE:-./llvm.bazelrc}"

LLVM_PREFIX=$1

if [[ ! -e "${LLVM_PREFIX}/bin/llvm-config" ]]; then
echo "Error: cannot find local llvm-config in ${LLVM_PREFIX}."
exit 1
fi

PATH="$("${LLVM_PREFIX}"/bin/llvm-config --bindir):${PATH}"
export PATH

LLVM_VERSION="$(llvm-config --version)"
LLVM_LIBDIR="$(llvm-config --libdir)"
LLVM_TARGET="$(llvm-config --host-target)"

RT_LIBRARY_PATH="${LLVM_LIBDIR}/clang/${LLVM_VERSION}/lib/${LLVM_TARGET}"

echo "# Generated file, do not edit. If you want to disable custom llvm, just delete this file.
build:llvm --action_env='PATH=${PATH}' --host_action_env='PATH=${PATH}'
build:llvm --action_env='LLVM_CONFIG=${LLVM_PREFIX}/bin/llvm-config' --host_action_env='LLVM_CONFIG=${LLVM_PREFIX}/bin/llvm-config'
build:llvm --repo_env='LLVM_CONFIG=${LLVM_PREFIX}/bin/llvm-config'
build:llvm --linkopt='-L$(llvm-config --libdir)'
build:llvm --linkopt='-Wl,-rpath,$(llvm-config --libdir)'
build:llvm-sanitizers --linkopt='-L${RT_LIBRARY_PATH}'
" >"${BAZELRC_FILE}"

0 comments on commit a214114

Please sign in to comment.