Brian Silverman | 7d89e28 | 2021-11-17 17:36:54 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2021 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # OS X relpath is not really working. This is a wrapper script around gcc |
| 18 | # to simulate relpath behavior. |
| 19 | # |
| 20 | # This wrapper uses install_name_tool to replace all paths in the binary |
| 21 | # (bazel-out/.../path/to/original/library.so) by the paths relative to |
| 22 | # the binary. It parses the command line to behave as rpath is supposed |
| 23 | # to work. |
| 24 | # |
| 25 | # See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac |
| 26 | # on how to set those paths for Mach-O binaries. |
| 27 | # |
| 28 | set -eu |
| 29 | |
| 30 | # See note in toolchain/internal/configure.bzl where we define |
| 31 | # `wrapper_bin_prefix` for why this wrapper is needed. |
| 32 | |
| 33 | # Call the C++ compiler. |
| 34 | if [[ -f %{toolchain_path_prefix}bin/clang ]]; then |
| 35 | exec %{toolchain_path_prefix}bin/clang "$@" |
| 36 | elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then |
| 37 | # Some consumers of `CcToolchainConfigInfo` (e.g. `cmake` from rules_foreign_cc) |
| 38 | # change CWD and call $CC (this script) with its absolute path. |
| 39 | # the execroot (i.e. `cmake` from `rules_foreign_cc`) and call CC . For cases like this, |
| 40 | # we'll try to find `clang` relative to this script. |
| 41 | # This script is at _execroot_/external/_repo_name_/bin/clang_wrapper.sh |
| 42 | execroot_path="${BASH_SOURCE[0]%/*/*/*/*}" |
| 43 | clang="${execroot_path}/%{toolchain_path_prefix}bin/clang" |
| 44 | exec "${clang}" "${@}" |
| 45 | else |
| 46 | >&2 echo "ERROR: could not find clang; PWD=\"$(pwd)\"; PATH=\"${PATH}\"." |
| 47 | exit 5 |
| 48 | fi |