Squashed 'third_party/bazel-toolchain/' content from commit a912bb381
Change-Id: Ie1ff8ed3b3948cca1d1b6227097c95e5a048de86
git-subtree-dir: third_party/bazel-toolchain
git-subtree-split: a912bb381b36437be0eeb22de11f0ea198450b4e
Signed-off-by: Brian Silverman <bsilver16834@gmail.com>
diff --git a/tests/scripts/archlinux_test.sh b/tests/scripts/archlinux_test.sh
new file mode 100755
index 0000000..e2a735b
--- /dev/null
+++ b/tests/scripts/archlinux_test.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+images=(
+"archlinux:base-devel"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Install dependencies
+pacman -Syu --noconfirm --quiet python
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/bazel.sh b/tests/scripts/bazel.sh
new file mode 100644
index 0000000..87d7cf1
--- /dev/null
+++ b/tests/scripts/bazel.sh
@@ -0,0 +1,30 @@
+os="$(uname -s | tr "[:upper:]" "[:lower:]")"
+readonly os
+
+arch="$(uname -m)"
+if [[ "${arch}" == "x86_64" ]]; then
+ arch="amd64"
+elif [[ "${arch}" == "aarch64" ]]; then
+ arch="arm64"
+else
+ >&2 echo "Unknown architecture: ${arch}"
+fi
+readonly arch
+
+# Use bazelisk to catch migration problems.
+readonly bazelisk_version="v1.10.1"
+readonly url="https://github.com/bazelbuild/bazelisk/releases/download/${bazelisk_version}/bazelisk-${os}-${arch}"
+bazel="${TMPDIR:-/tmp}/bazelisk"
+readonly bazel
+
+readonly common_test_args=(
+ --incompatible_enable_cc_toolchain_resolution
+ --symlink_prefix=/
+ --color=yes
+ --show_progress_rate_limit=30
+ --keep_going
+ --test_output=errors
+)
+
+curl -L -sSf -o "${bazel}" "${url}"
+chmod a+x "${bazel}"
diff --git a/tests/scripts/centos_test.sh b/tests/scripts/centos_test.sh
new file mode 100755
index 0000000..1df0167
--- /dev/null
+++ b/tests/scripts/centos_test.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+echo "This test is disabled because our supported versions of LLVM do not work with CentOS."
+exit 1
+
+set -euo pipefail
+
+images=(
+"centos:7"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Install dependencies
+yum install -y -q gcc
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/debian_test.sh b/tests/scripts/debian_test.sh
new file mode 100755
index 0000000..9f280c9
--- /dev/null
+++ b/tests/scripts/debian_test.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+images=(
+"debian:latest"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Common setup
+export DEBIAN_FRONTEND=noninteractive
+apt-get -qq update
+apt-get -qq -y install apt-utils curl pkg-config zip g++ zlib1g-dev unzip python gnupg2 libtinfo5 >/dev/null
+# The above command gives some verbose output that can not be silenced easily.
+# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=288778
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/fedora_test.sh b/tests/scripts/fedora_test.sh
new file mode 100755
index 0000000..39897cc
--- /dev/null
+++ b/tests/scripts/fedora_test.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+images=(
+"fedora:latest"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Install dependencies
+dnf install -qy dnf-plugins-core
+dnf install -qy python gcc ncurses-compat-libs
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/linux_sysroot_test.sh b/tests/scripts/linux_sysroot_test.sh
new file mode 100755
index 0000000..2b030cb
--- /dev/null
+++ b/tests/scripts/linux_sysroot_test.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+images=(
+"ubuntu:20.04"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Common setup
+export DEBIAN_FRONTEND=noninteractive
+apt-get -qq update
+apt-get -qq -y install apt-utils curl pkg-config zip g++ zlib1g-dev unzip python >/dev/null
+# The above command gives some verbose output that can not be silenced easily.
+# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=288778
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh -t '@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux'
+"""
+done
diff --git a/tests/scripts/run_external_tests.sh b/tests/scripts/run_external_tests.sh
new file mode 100755
index 0000000..e36ff78
--- /dev/null
+++ b/tests/scripts/run_external_tests.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+source "$(dirname "${BASH_SOURCE[0]}")/bazel.sh"
+"${bazel}" version
+
+# Generate some files needed for the tests.
+"${bazel}" fetch @io_bazel_rules_go//tests/core/cgo:all
+"$("${bazel}" info output_base)/external/io_bazel_rules_go/tests/core/cgo/generate_imported_dylib.sh"
+
+# We exclude the following targets:
+# - cc_libs_test from rules_go because it assumes that stdlibc++ has been dynamically linked, but we
+# link it statically on linux.
+# - opts_test from rules_go because its include path assumes that the main repo is rules_go (see
+# https://github.com/bazelbuild/rules_go/issues/2955).
+"${bazel}" --bazelrc=/dev/null test "${common_test_args[@]}" \
+ //tests/foreign:pcre \
+ @git2//:all \
+ @openssl//:libssl \
+ $("${bazel}" query 'attr(timeout, short, tests(@com_google_absl//absl/...))') \
+ $("${bazel}" query 'tests(@io_bazel_rules_go//tests/core/cgo:all) except set(@io_bazel_rules_go//tests/core/cgo:cc_libs_test @io_bazel_rules_go//tests/core/cgo:opts_test)')
diff --git a/tests/scripts/run_tests.sh b/tests/scripts/run_tests.sh
new file mode 100755
index 0000000..b411a08
--- /dev/null
+++ b/tests/scripts/run_tests.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+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;;
+ esac
+done
+
+source "$(dirname "${BASH_SOURCE[0]}")/bazel.sh"
+"${bazel}" version
+
+set -x
+test_args=(
+ --extra_toolchains="${toolchain_name}"
+ --copt=-v
+ --linkopt=-Wl,-t
+)
+if [[ "${TEST_MIGRATION:-}" ]]; then
+ # We can not use bazelisk to test migration because bazelisk does not allow
+ # us to selectively ignore a migration flag.
+ test_args+=("--all_incompatible_changes")
+ # This flag is not quite ready -- https://github.com/bazelbuild/bazel/issues/7347
+ test_args+=("--incompatible_disallow_struct_provider_syntax=false")
+ # the rules_rust repo included in the WORKSPACE is currently incompatible with
+ # '--incompatible_no_rule_outputs_param=true', setting this to false for now.
+ test_args+=("--incompatible_no_rule_outputs_param=false")
+fi
+"${bazel}" --bazelrc=/dev/null test "${common_test_args[@]}" "${test_args[@]}" //tests:all
diff --git a/tests/scripts/run_xcompile_tests.sh b/tests/scripts/run_xcompile_tests.sh
new file mode 100755
index 0000000..b0a7cfb
--- /dev/null
+++ b/tests/scripts/run_xcompile_tests.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+# Copyright 2021 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+source "$(dirname "${BASH_SOURCE[0]}")/bazel.sh"
+"${bazel}" version
+
+binpath="$("${bazel}" info bazel-bin)/tests/stdlib_test"
+
+check_with_image() {
+ if "${CI:-false}"; then
+ # macOS GitHub Action Runners do not have docker installed on them.
+ return
+ fi
+ local image="$1"
+ docker run --rm --mount "type=bind,source=${binpath},target=/stdlib_test" "${image}" /stdlib_test
+}
+
+echo ""
+echo "Testing static linked user libraries and dynamic linked system libraries"
+build_args=(
+ --incompatible_enable_cc_toolchain_resolution
+ --platforms=//platforms:linux-x86_64
+ --extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux
+ --symlink_prefix=/
+ --color=yes
+ --show_progress_rate_limit=30
+)
+"${bazel}" --bazelrc=/dev/null build "${build_args[@]}" //tests:stdlib_test
+file "${binpath}" | tee /dev/stderr | grep -q ELF
+check_with_image "frolvlad/alpine-glibc" # Need glibc image for system libraries.
+
+echo ""
+echo "Testing static linked user and system libraries"
+build_args+=(
+ --features=fully_static_link
+)
+"${bazel}" --bazelrc=/dev/null build "${build_args[@]}" //tests:stdlib_test
+file "${binpath}" | tee /dev/stderr | grep -q ELF
+check_with_image "alpine"
diff --git a/tests/scripts/suse_leap_test.sh b/tests/scripts/suse_leap_test.sh
new file mode 100755
index 0000000..d4f54a7
--- /dev/null
+++ b/tests/scripts/suse_leap_test.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Copyright 2021 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euox pipefail
+
+images=(
+"opensuse/leap:latest"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+echo "git root: $git_root"
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src" "${image}" -c """
+set -exuo pipefail
+
+# Common setup
+zypper -n update
+zypper -n install curl python tar gzip gcc libncurses5 binutils-gold
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/suse_tumbleweed_test.sh b/tests/scripts/suse_tumbleweed_test.sh
new file mode 100755
index 0000000..785a83c
--- /dev/null
+++ b/tests/scripts/suse_tumbleweed_test.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Copyright 2021 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euox pipefail
+
+images=(
+"opensuse/tumbleweed:latest"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+echo "git root: $git_root"
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src" "${image}" -c """
+set -exuo pipefail
+
+# Common setup
+zypper -n update
+zypper -n install pkgconf-pkg-config curl python tar gzip findutils gcc libncurses5 binutils-gold
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/ubuntu_16_04_test.sh b/tests/scripts/ubuntu_16_04_test.sh
new file mode 100755
index 0000000..419900c
--- /dev/null
+++ b/tests/scripts/ubuntu_16_04_test.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# Copyright 2018 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+images=(
+"ubuntu:16.04"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Common setup
+export DEBIAN_FRONTEND=noninteractive
+apt-get -qq update
+apt-get -qq -y install apt-utils curl pkg-config zip g++ zlib1g-dev unzip python >/dev/null
+# The above command gives some verbose output that can not be silenced easily.
+# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=288778
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/ubuntu_18_04_test.sh b/tests/scripts/ubuntu_18_04_test.sh
new file mode 100755
index 0000000..12da28e
--- /dev/null
+++ b/tests/scripts/ubuntu_18_04_test.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# Copyright 2020 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+images=(
+"ubuntu:18.04"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Common setup
+export DEBIAN_FRONTEND=noninteractive
+apt-get -qq update
+apt-get -qq -y install apt-utils curl pkg-config zip g++ zlib1g-dev unzip python >/dev/null
+# The above command gives some verbose output that can not be silenced easily.
+# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=288778
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done
diff --git a/tests/scripts/ubuntu_20_04_test.sh b/tests/scripts/ubuntu_20_04_test.sh
new file mode 100755
index 0000000..059f01c
--- /dev/null
+++ b/tests/scripts/ubuntu_20_04_test.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# Copyright 2020 The Bazel Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+images=(
+"ubuntu:20.04"
+)
+
+git_root=$(git rev-parse --show-toplevel)
+readonly git_root
+
+for image in "${images[@]}"; do
+ docker pull "${image}"
+ docker run --rm --entrypoint=/bin/bash --volume="${git_root}:/src:ro" "${image}" -c """
+set -exuo pipefail
+
+# Common setup
+export DEBIAN_FRONTEND=noninteractive
+apt-get -qq update
+apt-get -qq -y install apt-utils curl pkg-config zip g++ zlib1g-dev unzip python >/dev/null
+# The above command gives some verbose output that can not be silenced easily.
+# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=288778
+
+# Run tests
+cd /src
+tests/scripts/run_tests.sh
+"""
+done