Skip to content

Commit 284a79c

Browse files
committed
chore: configure OS-specific variables in .bazelrc (#2102)
- Add `--enable_platform_specific_config` to `.bazelrc.common`. - Move MacOS- and Windows-specific environment variables to `.bazelrc.common` under their OS config names. - Update code that generates bazelrc files for integration tests to include the new entries. Related to #2099.
1 parent 0039f48 commit 284a79c

File tree

10 files changed

+31
-33
lines changed

10 files changed

+31
-33
lines changed

.bazelrc.common

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ common --incompatible_disallow_empty_glob=true
2323
# as LOCALE_ARCHIVE We also need to setup an utf8 locale
2424
test --test_env=LANG=C.UTF-8 --test_env=LOCALE_ARCHIVE
2525

26+
# Enable automatic OS-specific config (e.g. build:linux, build:macos, build:windows).
27+
common --enable_platform_specific_config
28+
29+
# MacOS Configuration
30+
# -------------------
31+
# do not use Xcode on macOS
32+
common:macos --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
33+
34+
# Windows Configuration
35+
# ---------------------
36+
# prevent auto-detection of system compilers on Windows
37+
common:windows --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
38+
2639
# Platform / Toolchain Selection
2740
# ------------------------------
2841
build:linux-nixpkgs --config=nixpkgs

.bcr/rules_haskell/presubmit.yml

-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ tasks:
1111
verify_targets:
1212
name: Verify build targets
1313
platform: ${{ platform }}
14-
environment:
15-
BAZEL_USE_CPP_ONLY_TOOLCHAIN: '1'
1614
shell_commands:
1715
- |
1816
if apt --version >/dev/null 2>/dev/null; then
@@ -22,7 +20,6 @@ tasks:
2220
batch_commands:
2321
# enforce certificate update
2422
- 'powershell -Command "Invoke-WebRequest -Uri https://hackage.haskell.org/root.json -OutFile out.json"'
25-
- set BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
2623
build_flags:
2724
- '--incompatible_enable_cc_toolchain_resolution'
2825
build_targets:

.github/workflows/patch-test.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ jobs:
7272
shell: bash
7373
run: |
7474
export PATH=$HOME/bazel:$PATH
75-
[[ ${{ runner.os }} == macOS ]] && export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
7675
export GHC_VERSION=${{ matrix.ghc-version }}
7776
cd rules_haskell_tests
7877
./tests/run-start-script.sh --use-bindists

.github/workflows/workflow.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ jobs:
157157
- ghc: 9.6.2
158158
os: windows-latest
159159
env:
160-
# prevent auto-detection of system compilers on Windows
161-
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN: ${{ matrix.os == 'windows-latest' && 1 || 0 }}
162-
# do not use Xcode on macOS
163-
BAZEL_USE_CPP_ONLY_TOOLCHAIN: ${{ matrix.os == 'macos-latest' && 1 || 0 }}
164160
GHC_VERSION: ${{ matrix.ghc }}
165161
runs-on: ${{ matrix.os }}
166162
steps:

README.md

-11
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ If you are on NixOS, this is the only way to set up your project,
7676
because the GHC toolchain provisioned through binary distributions
7777
cannot be executed on NixOS.
7878

79-
If you are on macOS, you will have to set the environment variable
80-
`BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1`, so that Bazel picks the correct C compiler.
81-
8279
[bazel-cli-commands]: https://docs.bazel.build/versions/master/command-line-reference.html#commands
8380
[nixpkgs]: https://nixos.org/nixpkgs/
8481

@@ -227,14 +224,6 @@ en_US.utf8
227224
POSIX
228225
```
229226

230-
### MacOS: Error: DEVELOPER_DIR not set.
231-
232-
Make sure to set the following environment variable:
233-
```
234-
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
235-
```
236-
This ensures that Bazel picks the correct C compiler.
237-
238227
### Windows: Incorrect `cc_toolchain` used
239228

240229
If you're using Windows, bazel might use a different `cc_toolchain`

rules_haskell_tests/shell.nix

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
with pkgs;
44
mkShell {
5-
# XXX: hack for macosX, this flags disable bazel usage of xcode
6-
# Note: this is set even for linux so any regression introduced by this flag
7-
# will be catched earlier
8-
# See: https://github.com/bazelbuild/bazel/issues/4231
9-
BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1;
105
TMPDIR = "/tmp";
116

127
GHC_VERSION = ghcVersion;

rules_haskell_tests/tests/integration_testing/IntegrationTesting.hs

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ generateBazelRc dir = do
7878
\ build:linux-bindist --incompatible_enable_cc_toolchain_resolution \n\
7979
\ build:macos-bindist --incompatible_enable_cc_toolchain_resolution \n\
8080
\ build:windows-bindist --incompatible_enable_cc_toolchain_resolution \n\
81+
\ common --enable_platform_specific_config \n\
82+
\ common:macos --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \n\
83+
\ common:windows --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \n\
8184
\ ")
8285

8386
setupWorkspace :: IO (String, String)

rules_haskell_tests/tests/integration_testing/rules_haskell_integration_test.bzl

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load(":haskell_bazel_integration_test.bzl", "haskell_bazel_integration_test")
1+
load("@os_info//:os_info.bzl", "is_nix_shell", "is_windows")
22
load(
33
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
44
"integration_test_utils",
@@ -9,7 +9,7 @@ load(
99
"SUPPORTED_NIXPKGS_BAZEL_PACKAGES",
1010
)
1111
load("//tests/integration_testing:dependencies.bzl", "nixpkgs_bazel_label")
12-
load("@os_info//:os_info.bzl", "is_nix_shell", "is_windows")
12+
load(":haskell_bazel_integration_test.bzl", "haskell_bazel_integration_test")
1313

1414
def rules_haskell_integration_test(
1515
name,
@@ -43,7 +43,6 @@ def rules_haskell_integration_test(
4343
"//tests:nix": [],
4444
"//conditions:default": ["@platforms//:incompatible"],
4545
}),
46-
additional_env_inherit = ["BAZEL_USE_CPP_ONLY_TOOLCHAIN"],
4746
**kwargs
4847
)
4948
elif not is_windows:
@@ -58,6 +57,5 @@ def rules_haskell_integration_test(
5857
"//tests:nix": ["@platforms//:incompatible"],
5958
"//conditions:default": [],
6059
}),
61-
additional_env_inherit = ["BAZEL_USE_CPP_ONLY_TOOLCHAIN"],
6260
**kwargs
6361
)

shell.nix

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ let
99
writeScriptBin "security" ''exec /usr/bin/security "$@"'';
1010
in
1111
mkShell {
12-
# XXX: hack for macosX, this flags disable bazel usage of xcode
13-
# Note: this is set even for linux so any regression introduced by this flag
14-
# will be catched earlier
15-
# See: https://github.com/bazelbuild/bazel/issues/4231
16-
BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1;
1712
TMPDIR = "/tmp";
1813

1914
GHC_VERSION = ghcVersion;

start

+13
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,19 @@ common --enable_bzlmod=$BZLMOD
443443
# Should become the default in bazel 7
444444
build --incompatible_enable_cc_toolchain_resolution
445445
446+
# Enable automatic OS-specific config (e.g. build:linux, build:macos, build:windows).
447+
common --enable_platform_specific_config
448+
449+
# MacOS Configuration
450+
# -------------------
451+
# do not use Xcode on macOS
452+
common:macos --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
453+
454+
# Windows Configuration
455+
# ---------------------
456+
# prevent auto-detection of system compilers on Windows
457+
common:windows --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
458+
446459
EOF
447460

448461
if [ "${MODE}" = "nix" ]; then

0 commit comments

Comments
 (0)