Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format all files #213

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .trunk/configs/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*]
indent_style = space
indent_size = 2
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +15,7 @@ implementation, please let me know and I can redirect people there.

– @siddharthab

-------
---

## Quickstart

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand All @@ -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 \
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/file_dependency_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
2 changes: 1 addition & 1 deletion tests/scripts/archlinux_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions tests/scripts/bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/centos_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exit 1
set -euo pipefail

images=(
"centos:7"
"centos:7"
)

git_root=$(git rev-parse --show-toplevel)
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/debian_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -euo pipefail

images=(
"debian:latest"
"debian:latest"
)

git_root=$(git rev-parse --show-toplevel)
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/fedora_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -euo pipefail

images=(
"fedora:latest"
"fedora:latest"
)

git_root=$(git rev-parse --show-toplevel)
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/linux_sysroot_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -euo pipefail

images=(
"ubuntu:22.04"
"ubuntu:22.04"
)

git_root=$(git rev-parse --show-toplevel)
Expand Down
3 changes: 1 addition & 2 deletions tests/scripts/run_external_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

16 changes: 10 additions & 6 deletions tests/scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/suse_leap_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/suse_tumbleweed_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/ubuntu_20_04_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -euo pipefail

images=(
"ubuntu:20.04"
"ubuntu:20.04"
)

git_root=$(git rev-parse --show-toplevel)
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/ubuntu_22_04_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -euo pipefail

images=(
"ubuntu:22.04"
"ubuntu:22.04"
)

git_root=$(git rev-parse --show-toplevel)
Expand Down
2 changes: 1 addition & 1 deletion toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions toolchain/cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
10 changes: 5 additions & 5 deletions toolchain/internal/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion toolchain/internal/llvm_distributions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading