Format all files (#213)

Formats all files as per `trunk fmt --all`.

Also adds .editorconfig for capturing indent style.
This commit is contained in:
Siddhartha Bagaria 2023-09-12 16:05:22 -07:00 committed by GitHub
parent 07541b9bde
commit c196bc1e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 133 additions and 120 deletions

View File

@ -0,0 +1,5 @@
root = true
[*]
indent_style = space
indent_size = 2

View File

@ -1,7 +1,6 @@
LLVM toolchain for Bazel [![Tests](https://github.com/grailbio/bazel-toolchain/actions/workflows/tests.yml/badge.svg)](https://github.com/grailbio/bazel-toolchain/actions/workflows/tests.yml)
=================
# LLVM toolchain for Bazel [![Tests](https://github.com/grailbio/bazel-toolchain/actions/workflows/tests.yml/badge.svg)](https://github.com/grailbio/bazel-toolchain/actions/workflows/tests.yml)
-------
---
The project is in a relatively stable state and in use for all code development
at GRAIL and other organizations. Having said that, I am unable to give time to
@ -16,7 +15,7 @@ implementation, please let me know and I can redirect people there.
@siddharthab
-------
---
## Quickstart
@ -71,6 +70,7 @@ llvm_register_toolchains()
```
And add the following section to your .bazelrc file:
```
# Not needed after https://github.com/bazelbuild/bazel/issues/7260 is closed
build --incompatible_enable_cc_toolchain_resolution
@ -118,7 +118,7 @@ llvm_toolchain(
#### Customizations
We currently offer limited customizability through attributes of the
[llvm_toolchain_\* rules](toolchain/rules.bzl). You can send us a PR to add
[llvm_toolchain\_\* rules](toolchain/rules.bzl). You can send us a PR to add
more configuration attributes.
A majority of the complexity of this project is to make it generic for multiple
@ -166,7 +166,7 @@ with the `--toolchain_resolution_debug` flag to see which toolchains were
selected by bazel for your target platform.
For specifying unregistered toolchains on the command line, please use the
`--extra_toolchains` flag. For example,
`--extra_toolchains` flag. For example,
`--extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux`.
We no longer support the `--crosstool_top=@llvm_toolchain//:toolchain` flag,
@ -219,6 +219,7 @@ The toolchain supports cross-compilation if you bring your own sysroot. When
cross-compiling, we link against the libstdc++ from the sysroot
(single-platform build behavior is to link against libc++ bundled with LLVM).
The following pairs have been tested to work for some hello-world binaries:
- {linux, x86_64} -> {linux, aarch64}
- {linux, aarch64} -> {linux, x86_64}
- {darwin, x86_64} -> {linux, x86_64}
@ -229,6 +230,7 @@ for single-platform builds, and one with sysroot for cross-compilation builds.
Then, when cross-compiling, explicitly specify the toolchain with the sysroot
and the target platform. For example, see the [WORKSPACE](tests/WORKSPACE) file and
the [test script](tests/scripts/run_xcompile_tests.sh) for cross-compilation.
```
bazel build \
--platforms=@com_grail_bazel_toolchain//platforms:linux-x86_64 \
@ -258,7 +260,7 @@ The following is a rough (untested) list of steps:
Sandboxing the toolchain introduces a significant overhead (100ms per action,
as of mid 2018). To overcome this, one can use
`--experimental_sandbox_base=/dev/shm`. However, not all environments might
`--experimental_sandbox_base=/dev/shm`. However, not all environments might
have enough shared memory available to load all the files in memory. If this is
a concern, you may set the attribute for using absolute paths, which will
substitute templated paths to the toolchain as absolute paths. When running

View File

@ -14,17 +14,17 @@
# limitations under the License.
fail() {
>&2 echo "$@"
echo >&2 "$@"
exit 1
}
clang_format_path=$1
libcpp_path=$2
[[ -a "${clang_format_path}" ]] || fail "bin/clang-format not found"
[[ -e ${clang_format_path} ]] || fail "bin/clang-format not found"
[[ -a "${libcpp_path}" ]] \
|| compgen -G "${libcpp_path}" >/dev/null \
|| fail "libc++.a not found"
[[ -e ${libcpp_path} ]] ||
compgen -G "${libcpp_path}" >/dev/null ||
fail "libc++.a not found"
echo "SUCCESS!"

View File

@ -16,7 +16,7 @@
set -euo pipefail
images=(
"archlinux:base-devel"
"archlinux:base-devel"
)
# See note next to the definition of this toolchain in the WORKSPACE file.

View File

@ -16,12 +16,12 @@ os="$(uname -s | tr "[:upper:]" "[:lower:]")"
readonly os
arch="$(uname -m)"
if [[ "${arch}" == "x86_64" ]]; then
if [[ ${arch} == "x86_64" ]]; then
arch="amd64"
elif [[ "${arch}" == "aarch64" ]] || [[ "${arch}" == "arm64" ]]; then
elif [[ ${arch} == "aarch64" ]] || [[ ${arch} == "arm64" ]]; then
arch="arm64"
else
>&2 echo "Unknown architecture: ${arch}"
echo >&2 "Unknown architecture: ${arch}"
fi
readonly arch

View File

@ -19,7 +19,7 @@ exit 1
set -euo pipefail
images=(
"centos:7"
"centos:7"
)
git_root=$(git rev-parse --show-toplevel)

View File

@ -16,7 +16,7 @@
set -euo pipefail
images=(
"debian:latest"
"debian:latest"
)
git_root=$(git rev-parse --show-toplevel)

View File

@ -16,7 +16,7 @@
set -euo pipefail
images=(
"fedora:latest"
"fedora:latest"
)
git_root=$(git rev-parse --show-toplevel)

View File

@ -16,7 +16,7 @@
set -euo pipefail
images=(
"ubuntu:22.04"
"ubuntu:22.04"
)
git_root=$(git rev-parse --show-toplevel)

View File

@ -23,7 +23,7 @@ cd "${scripts_dir}"
# Generate some files needed for the tests.
"${bazel}" query "${common_args[@]}" @io_bazel_rules_go//tests/core/cgo:dylib_test >/dev/null
if [[ "$USE_BZLMOD" == "true" ]]; then
if [[ $USE_BZLMOD == "true" ]]; then
"$("${bazel}" info output_base)/external/rules_go~0.41.0/tests/core/cgo/generate_imported_dylib.sh"
else
"$("${bazel}" info output_base)/external/io_bazel_rules_go/tests/core/cgo/generate_imported_dylib.sh"
@ -59,4 +59,3 @@ test_args=(
-@io_bazel_rules_go//tests/core/cgo:external_includes_test \
$("${bazel}" query 'attr(timeout, short, tests(@com_google_absl//absl/...))') \
-@com_google_absl//absl/time/internal/cctz:time_zone_format_test

View File

@ -19,12 +19,16 @@ toolchain_name=""
while getopts "t:h" opt; do
case "$opt" in
"t") toolchain_name="$OPTARG";;
"h") echo "Usage:"
echo "-t - Toolchain name to use for testing; default is llvm_toolchain"
exit 2
;;
"?") echo "invalid option: -$OPTARG"; exit 1;;
"t") toolchain_name="$OPTARG" ;;
"h")
echo "Usage:"
echo "-t - Toolchain name to use for testing; default is llvm_toolchain"
exit 2
;;
"?")
echo "invalid option: -$OPTARG"
exit 1
;;
esac
done

View File

@ -16,7 +16,7 @@
set -euox pipefail
images=(
"opensuse/leap:latest"
"opensuse/leap:latest"
)
# See note next to the definition of this toolchain in the WORKSPACE file.

View File

@ -16,7 +16,7 @@
set -euox pipefail
images=(
"opensuse/tumbleweed:latest"
"opensuse/tumbleweed:latest"
)
# See note next to the definition of this toolchain in the WORKSPACE file.

View File

@ -16,7 +16,7 @@
set -euo pipefail
images=(
"ubuntu:20.04"
"ubuntu:20.04"
)
git_root=$(git rev-parse --show-toplevel)

View File

@ -16,7 +16,7 @@
set -euo pipefail
images=(
"ubuntu:22.04"
"ubuntu:22.04"
)
git_root=$(git rev-parse --show-toplevel)

View File

@ -23,7 +23,7 @@ load(
_os_arch_pair = "os_arch_pair",
)
# Bazel 4.* doesn't support nested skylark functions, so we cannot simplify
# Bazel 4.* doesn't support nested starlark functions, so we cannot simplify
# _fmt_flags() by defining it as a nested function.
def _fmt_flags(flags, toolchain_path_prefix):
return [f.format(toolchain_path_prefix = toolchain_path_prefix) for f in flags]

View File

@ -33,7 +33,7 @@ set -eu
# Call the C++ compiler.
if [[ -f %{toolchain_path_prefix}bin/clang ]]; then
exec %{toolchain_path_prefix}bin/clang "$@"
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
elif [[ ${BASH_SOURCE[0]} == "/"* ]]; then
# Some consumers of `CcToolchainConfigInfo` (e.g. `cmake` from rules_foreign_cc)
# change CWD and call $CC (this script) with its absolute path.
# the execroot (i.e. `cmake` from `rules_foreign_cc`) and call CC . For cases like this,
@ -43,6 +43,6 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
clang="${execroot_path}/%{toolchain_path_prefix}bin/clang"
exec "${clang}" "${@}"
else
>&2 echo "ERROR: could not find clang; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."
echo >&2 "ERROR: could not find clang; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."
exit 5
fi

View File

@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load(
"//toolchain:aliases.bzl",
_aliased_libs = "aliased_libs",
_aliased_tools = "aliased_tools",
)
load(
"//toolchain/internal:common.bzl",
_arch = "arch",
@ -32,11 +37,6 @@ load(
_default_sysroot_path = "default_sysroot_path",
_sysroot_paths_dict = "sysroot_paths_dict",
)
load(
"//toolchain:aliases.bzl",
_aliased_libs = "aliased_libs",
_aliased_tools = "aliased_tools",
)
# When bzlmod is enabled, canonical repos names have @@ in them, while under
# workspace builds, there is never a @@ in labels.

View File

@ -373,7 +373,7 @@ def _get_llvm_version(rctx):
fail("Neither 'llvm_version' nor 'llvm_versions' given.")
(key, llvm_version) = _host_os_arch_dict_value(rctx, "llvm_versions")
if not llvm_version:
fail("LLVM version string missing for ({os}, {arch})", os=_os(rctx), arch=_arch(rctx))
fail("LLVM version string missing for ({os}, {arch})", os = _os(rctx), arch = _arch(rctx))
return llvm_version
def _distribution_urls(rctx):

View File

@ -35,33 +35,32 @@ RPATHS=
OUTPUT=
function parse_option() {
local -r opt="$1"
if [[ "${OUTPUT}" = "1" ]]; then
OUTPUT=$opt
elif [[ "$opt" =~ ^-l(.*)$ ]]; then
LIBS="${BASH_REMATCH[1]} $LIBS"
elif [[ "$opt" =~ ^-L(.*)$ ]]; then
LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS"
elif [[ "$opt" =~ ^\@loader_path/(.*)$ ]]; then
RPATHS="${BASH_REMATCH[1]} ${RPATHS}"
elif [[ "$opt" =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then
RPATHS="${BASH_REMATCH[1]} ${RPATHS}"
elif [[ "$opt" = "-o" ]]; then
# output is coming
OUTPUT=1
fi
local -r opt="$1"
if [[ ${OUTPUT} == "1" ]]; then
OUTPUT=$opt
elif [[ $opt =~ ^-l(.*)$ ]]; then
LIBS="${BASH_REMATCH[1]} $LIBS"
elif [[ $opt =~ ^-L(.*)$ ]]; then
LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS"
elif [[ $opt =~ ^\@loader_path/(.*)$ ]]; then
RPATHS="${BASH_REMATCH[1]} ${RPATHS}"
elif [[ $opt =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then
RPATHS="${BASH_REMATCH[1]} ${RPATHS}"
elif [[ $opt == "-o" ]]; then
# output is coming
OUTPUT=1
fi
}
# let parse the option list
for i in "$@"; do
if [[ "$i" = @* ]]; then
while IFS= read -r opt
do
parse_option "$opt"
done < "${i:1}" || exit 1
else
parse_option "$i"
fi
if [[ $i == @* ]]; then
while IFS= read -r opt; do
parse_option "$opt"
done <"${i:1}" || exit 1
else
parse_option "$i"
fi
done
# On macOS, we use ld as the linker for single-platform builds (i.e., when not
@ -87,7 +86,7 @@ fi
# Call the C++ compiler.
if [[ -f %{toolchain_path_prefix}bin/clang ]]; then
%{toolchain_path_prefix}bin/clang "$@"
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
elif [[ ${BASH_SOURCE[0]} == "/"* ]]; then
# Some consumers of `CcToolchainConfigInfo` (e.g. `cmake` from rules_foreign_cc)
# change CWD and call $CC (this script) with its absolute path.
# the execroot (i.e. `cmake` from `rules_foreign_cc`) and call CC . For cases like this,
@ -97,55 +96,55 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
clang="${execroot_path}/%{toolchain_path_prefix}bin/clang"
"${clang}" "${@}"
else
>&2 echo "ERROR: could not find clang; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."
echo >&2 "ERROR: could not find clang; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."
exit 5
fi
function get_library_path() {
for libdir in ${LIB_DIRS}; do
if [ -f ${libdir}/lib$1.so ]; then
echo "${libdir}/lib$1.so"
elif [ -f ${libdir}/lib$1.dylib ]; then
echo "${libdir}/lib$1.dylib"
fi
done
for libdir in ${LIB_DIRS}; do
if [ -f ${libdir}/lib$1.so ]; then
echo "${libdir}/lib$1.so"
elif [ -f ${libdir}/lib$1.dylib ]; then
echo "${libdir}/lib$1.dylib"
fi
done
}
# A convenient method to return the actual path even for non symlinks
# and multi-level symlinks.
function get_realpath() {
local previous="$1"
local next=$(readlink "${previous}")
while [ -n "${next}" ]; do
previous="${next}"
next=$(readlink "${previous}")
done
echo "${previous}"
local previous="$1"
local next=$(readlink "${previous}")
while [ -n "${next}" ]; do
previous="${next}"
next=$(readlink "${previous}")
done
echo "${previous}"
}
# Get the path of a lib inside a tool
function get_otool_path() {
# the lib path is the path of the original lib relative to the workspace
get_realpath $1 | sed 's|^.*/bazel-out/|bazel-out/|'
# the lib path is the path of the original lib relative to the workspace
get_realpath $1 | sed 's|^.*/bazel-out/|bazel-out/|'
}
# Do replacements in the output
for rpath in ${RPATHS}; do
for lib in ${LIBS}; do
unset libname
if [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.so" ]; then
libname="lib${lib}.so"
elif [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.dylib" ]; then
libname="lib${lib}.dylib"
fi
# ${libname-} --> return $libname if defined, or undefined otherwise. This is to make
# this set -e friendly
if [[ -n "${libname-}" ]]; then
libpath=$(get_library_path ${lib})
if [ -n "${libpath}" ]; then
${INSTALL_NAME_TOOL} -change $(get_otool_path "${libpath}") \
"@loader_path/${rpath}/${libname}" "${OUTPUT}"
fi
fi
done
for lib in ${LIBS}; do
unset libname
if [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.so" ]; then
libname="lib${lib}.so"
elif [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.dylib" ]; then
libname="lib${lib}.dylib"
fi
# ${libname-} --> return $libname if defined, or undefined otherwise. This is to make
# this set -e friendly
if [[ -n ${libname-} ]]; then
libpath=$(get_library_path ${lib})
if [ -n "${libpath}" ]; then
${INSTALL_NAME_TOOL} -change $(get_otool_path "${libpath}") \
"@loader_path/${rpath}/${libname}" "${OUTPUT}"
fi
fi
done
done

View File

@ -19,18 +19,22 @@ use_github_host=0
while getopts "v:gh" opt; do
case "$opt" in
"v") llvm_version="$OPTARG";;
"g") use_github_host=1;;
"h") echo "Usage:"
echo "-v - Version of clang+llvm to use"
echo "-g - Use github to download releases"
exit 2
;;
"?") echo "invalid option: -$OPTARG"; exit 1;;
"v") llvm_version="$OPTARG" ;;
"g") use_github_host=1 ;;
"h")
echo "Usage:"
echo "-v - Version of clang+llvm to use"
echo "-g - Use github to download releases"
exit 2
;;
"?")
echo "invalid option: -$OPTARG"
exit 1
;;
esac
done
if ! [[ "${llvm_version:-}" ]]; then
if ! [[ "${llvm_version-}" ]]; then
echo "Usage: ${BASH_SOURCE[0]} [-g] -v llvm_version"
exit 1
fi
@ -54,17 +58,17 @@ llvm_host() {
github_host() {
output_dir="${tmp_dir}"
(
cd "${output_dir}"
curl -s "https://api.github.com/repos/llvm/llvm-project/releases/tags/llvmorg-${llvm_version}" | \
jq .assets[].browser_download_url | \
tee ./urls.txt | \
grep 'clang%2Bllvm.*tar.xz"$' | \
tee ./filtered_urls.txt | \
xargs -n1 curl -L -O
cd "${output_dir}"
curl -s "https://api.github.com/repos/llvm/llvm-project/releases/tags/llvmorg-${llvm_version}" |
jq .assets[].browser_download_url |
tee ./urls.txt |
grep 'clang%2Bllvm.*tar.xz"$' |
tee ./filtered_urls.txt |
xargs -n1 curl -L -O
)
}
if (( use_github_host )); then
if ((use_github_host)); then
github_host
else
llvm_host
@ -73,8 +77,8 @@ fi
echo ""
echo "===="
echo "Checksums for clang+llvm distributions are:"
find "${output_dir}" -type f -name '*.xz' -exec shasum -a 256 {} \; | \
sed -e "s@${output_dir}/@@" | \
awk '{ printf "\"%s\": \"%s\",\n", $2, $1 }' | \
sed -e 's/%2[Bb]/+/' | \
find "${output_dir}" -type f -name '*.xz' -exec shasum -a 256 {} \; |
sed -e "s@${output_dir}/@@" |
awk '{ printf "\"%s\": \"%s\",\n", $2, $1 }' |
sed -e 's/%2[Bb]/+/' |
sort