Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 7e6ca20

Browse files
authored
bazel: add config setting for zig linux 86 and incompatible cc (#52364)
For some bazel targets we want bazel to detect the host cc and use it. This puts the `--incompatible_enable_cc_toolchain_resolution` flag behind a config setting one has to opt into to use with `--config incompat-zig-linux-amd64`. I also extracted some of the bazelrc to selectively add the CI bazelrc, so that it is easier to run these scripts locally. ## Test plan * green ci * executed the symbols and server scripts locally <!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles -->
1 parent c028e30 commit 7e6ca20

File tree

5 files changed

+54
-36
lines changed

5 files changed

+54
-36
lines changed

.bazelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ build --test_env=ENABLE_BAZEL_PACKAGES_LOAD_HACK=true
2020

2121
# Needed by https://github.com/uber/bazel-zig-cc which we use to cross-compile
2222
# CGo code for cmd/symbols to be used in containers.
23-
build --incompatible_enable_cc_toolchain_resolution
23+
build:incompat-zig-linux-amd64 --incompatible_enable_cc_toolchain_resolution
24+
build:incompat-zig-linux-amd64 --platforms @zig_sdk//platform:linux_amd64
25+
build:incompat-zig-linux-amd64 --extra_toolchains @zig_sdk//toolchain:linux_amd64_musl
26+
2427

2528
# Except in CI run E2E tests in headless mode
2629
try-import %workspace%/user.bazelrc

cmd/server/build-bazel.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,41 +57,44 @@ MUSL_TARGETS=(
5757

5858
if [[ "${ENTERPRISE:-"false"}" == "false" ]]; then
5959
MUSL_TARGETS+=(//cmd/symbols)
60-
exit $?
6160
else
6261
MUSL_TARGETS+=(//enterprise/cmd/symbols)
6362
fi
6463

64+
bazelrc=(
65+
--bazelrc=.bazelrc
66+
)
67+
if [[ ${CI:-""} == "true" ]]; then
68+
bazelrc+=(
69+
--bazelrc=.aspect/bazelrc/ci.bazelrc
70+
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc
71+
)
72+
fi
73+
6574
echo "--- bazel build musl"
6675
bazel \
67-
--bazelrc=.bazelrc \
68-
--bazelrc=.aspect/bazelrc/ci.bazelrc \
69-
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc \
76+
"${bazelrc[@]}"
7077
build \
7178
"${MUSL_TARGETS[@]}" \
7279
--stamp \
7380
--workspace_status_command=./dev/bazel_stamp_vars.sh \
74-
--platforms @zig_sdk//platform:linux_amd64 \
75-
--extra_toolchains @zig_sdk//toolchain:linux_amd64_musl
81+
--config incompat-zig-linux-amd64
7682

7783
for MUSL_TARGET in "${MUSL_TARGETS[@]}"; do
78-
out=$(bazel --bazelrc=.bazelrc \
79-
--bazelrc=.aspect/bazelrc/ci.bazelrc \
80-
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc \
84+
out=$(bazel
85+
"${bazelrc[@]}"
8186
cquery \
8287
"$MUSL_TARGET" \
8388
--stamp \
8489
--workspace_status_command=./dev/bazel_stamp_vars.sh \
85-
--platforms @zig_sdk//platform:linux_amd64 \
86-
--extra_toolchains @zig_sdk//toolchain:linux_amd64_musl \
90+
--config incompat-zig-linux-amd64 \
8791
--output=files)
8892
cp "$out" "$BINDIR"
8993
echo "copying $MUSL_TARGET"
9094
done
9195

9296
if [[ "${ENTERPRISE:-"false"}" == "false" ]]; then
9397
TARGETS=("${OSS_TARGETS[@]}")
94-
exit $?
9598
else
9699
TARGETS=("${ENTERPRISE_TARGETS[@]}")
97100
fi

cmd/symbols/build-bazel.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,31 @@ cleanup() {
1212
trap cleanup EXIT
1313

1414
echo "--- bazel build"
15-
bazel build \
16-
--bazelrc=.bazelrc \
17-
--bazelrc=.aspect/bazelrc/ci.bazelrc \
18-
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc \
15+
16+
bazelrc=(
17+
--bazelrc=.bazelrc
18+
)
19+
if [[ ${CI:-""} == "true" ]]; then
20+
bazelrc+=(
21+
--bazelrc=.aspect/bazelrc/ci.bazelrc
22+
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc
23+
)
24+
fi
25+
26+
27+
bazel "${bazelrc[@]}" \
28+
build \
1929
//cmd/symbols \
2030
--stamp \
2131
--workspace_status_command=./dev/bazel_stamp_vars.sh \
22-
--platforms @zig_sdk//platform:linux_amd64 \
23-
--extra_toolchains @zig_sdk//toolchain:linux_amd64_musl
32+
--config incompat-zig-linux-amd64
2433

2534
out=$(
26-
bazel build \
27-
--bazelrc=.bazelrc \
28-
--bazelrc=.aspect/bazelrc/ci.bazelrc \
29-
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc \ cquery //cmd/symbols \
35+
bazel "${bazelrc[@]}" \
36+
cquery //cmd/symbols \
3037
--stamp \
3138
--workspace_status_command=./dev/bazel_stamp_vars.sh \
32-
--platforms @zig_sdk//platform:linux_amd64 \
33-
--extra_toolchains @zig_sdk//toolchain:linux_amd64_musl \
39+
--config incompat-zig-linux-amd64 \
3440
--output=files
3541
)
3642
cp "$out" "$OUTPUT"

enterprise/cmd/symbols/build-bazel.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,41 @@
33
# This script builds the symbols docker image.
44

55
cd "$(dirname "${BASH_SOURCE[0]}")/../../.."
6-
set -eux
6+
set -eu
77

88
OUTPUT=$(mktemp -d -t sgdockerbuild_XXXXXXX)
99
cleanup() {
1010
rm -rf "$OUTPUT"
1111
}
1212
trap cleanup EXIT
1313

14+
bazelrc=(
15+
--bazelrc=.bazelrc
16+
)
17+
if [[ ${CI:-""} == "true" ]]; then
18+
bazelrc+=(
19+
--bazelrc=.aspect/bazelrc/ci.bazelrc
20+
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc
21+
)
22+
fi
23+
1424
echo "--- bazel build"
1525
bazel \
16-
--bazelrc=.bazelrc \
17-
--bazelrc=.aspect/bazelrc/ci.bazelrc \
18-
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc \
26+
"${bazelrc[@]}" \
1927
build \
2028
//enterprise/cmd/symbols \
2129
--stamp \
2230
--workspace_status_command=./dev/bazel_stamp_vars.sh \
23-
--platforms @zig_sdk//platform:linux_amd64 \
24-
--extra_toolchains @zig_sdk//toolchain:linux_amd64_musl
31+
--config incompat-zig-linux-amd64
2532

2633
out=$(
27-
bazel --bazelrc=.bazelrc \
28-
--bazelrc=.aspect/bazelrc/ci.bazelrc \
29-
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc \
34+
bazel \
35+
"${bazelrc[@]}" \
3036
cquery \
3137
//enterprise/cmd/symbols \
3238
--stamp \
3339
--workspace_status_command=./dev/bazel_stamp_vars.sh \
34-
--platforms @zig_sdk//platform:linux_amd64 \
35-
--extra_toolchains @zig_sdk//toolchain:linux_amd64_musl \
40+
--config incompat-zig-linux-amd64 \
3641
--output=files
3742
)
3843
cp "$out" "$OUTPUT"

enterprise/dev/app/build-backend.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ bazel_build() {
6565
# for more info see the BUILD.bazel file in enterprise/cmd/sourcegraph
6666
if [[ ${CROSS_COMPILE_X86_64_MACOS:-0} == 1 ]]; then
6767
bazel_target="//enterprise/cmd/sourcegraph:sourcegraph_x86_64_darwin"
68+
# we don't use the incompat-zig-linux-amd64 bazel config here, since we need bazel to pick up the host cc
6869
bazel_opts="${bazel_opts} --platforms @zig_sdk//platform:darwin_amd64 --extra_toolchains @zig_sdk//toolchain:darwin_amd64"
6970
fi
7071

0 commit comments

Comments
 (0)