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

chore: configure OS-specific variables in .bazelrc #2102

Merged
merged 1 commit into from
Jan 8, 2024
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
13 changes: 13 additions & 0 deletions .bazelrc.common
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ common --incompatible_disallow_empty_glob=true
# as LOCALE_ARCHIVE We also need to setup an utf8 locale
test --test_env=LANG=C.UTF-8 --test_env=LOCALE_ARCHIVE

# Enable automatic OS-specific config (e.g. build:linux, build:macos, build:windows).
common --enable_platform_specific_config

# MacOS Configuration
# -------------------
# do not use Xcode on macOS
common:macos --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1

# Windows Configuration
# ---------------------
# prevent auto-detection of system compilers on Windows
common:windows --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

# Platform / Toolchain Selection
# ------------------------------
build:linux-nixpkgs --config=nixpkgs
Expand Down
3 changes: 0 additions & 3 deletions .bcr/rules_haskell/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
environment:
BAZEL_USE_CPP_ONLY_TOOLCHAIN: '1'
shell_commands:
- |
if apt --version >/dev/null 2>/dev/null; then
Expand All @@ -22,7 +20,6 @@ tasks:
batch_commands:
# enforce certificate update
- 'powershell -Command "Invoke-WebRequest -Uri https://hackage.haskell.org/root.json -OutFile out.json"'
- set BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build_flags:
- '--incompatible_enable_cc_toolchain_resolution'
build_targets:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/patch-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ jobs:
shell: bash
run: |
export PATH=$HOME/bazel:$PATH
[[ ${{ runner.os }} == macOS ]] && export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
export GHC_VERSION=${{ matrix.ghc-version }}
cd rules_haskell_tests
./tests/run-start-script.sh --use-bindists
4 changes: 0 additions & 4 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ jobs:
- ghc: 9.6.2
os: windows-latest
env:
# prevent auto-detection of system compilers on Windows
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN: ${{ matrix.os == 'windows-latest' && 1 || 0 }}
# do not use Xcode on macOS
BAZEL_USE_CPP_ONLY_TOOLCHAIN: ${{ matrix.os == 'macos-latest' && 1 || 0 }}
GHC_VERSION: ${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
steps:
Expand Down
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ If you are on NixOS, this is the only way to set up your project,
because the GHC toolchain provisioned through binary distributions
cannot be executed on NixOS.

If you are on macOS, you will have to set the environment variable
`BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1`, so that Bazel picks the correct C compiler.

[bazel-cli-commands]: https://docs.bazel.build/versions/master/command-line-reference.html#commands
[nixpkgs]: https://nixos.org/nixpkgs/

Expand Down Expand Up @@ -227,14 +224,6 @@ en_US.utf8
POSIX
```

### MacOS: Error: DEVELOPER_DIR not set.

Make sure to set the following environment variable:
```
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
```
This ensures that Bazel picks the correct C compiler.

### Windows: Incorrect `cc_toolchain` used

If you're using Windows, bazel might use a different `cc_toolchain`
Expand Down
5 changes: 0 additions & 5 deletions rules_haskell_tests/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

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

GHC_VERSION = ghcVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ generateBazelRc dir = do
\ build:linux-bindist --incompatible_enable_cc_toolchain_resolution \n\
\ build:macos-bindist --incompatible_enable_cc_toolchain_resolution \n\
\ build:windows-bindist --incompatible_enable_cc_toolchain_resolution \n\
\ common --enable_platform_specific_config \n\
\ common:macos --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \n\
\ common:windows --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \n\
\ ")

setupWorkspace :: IO (String, String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load(":haskell_bazel_integration_test.bzl", "haskell_bazel_integration_test")
load("@os_info//:os_info.bzl", "is_nix_shell", "is_windows")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"integration_test_utils",
Expand All @@ -9,7 +9,7 @@ load(
"SUPPORTED_NIXPKGS_BAZEL_PACKAGES",
)
load("//tests/integration_testing:dependencies.bzl", "nixpkgs_bazel_label")
load("@os_info//:os_info.bzl", "is_nix_shell", "is_windows")
load(":haskell_bazel_integration_test.bzl", "haskell_bazel_integration_test")

def rules_haskell_integration_test(
name,
Expand Down Expand Up @@ -43,7 +43,6 @@ def rules_haskell_integration_test(
"//tests:nix": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
additional_env_inherit = ["BAZEL_USE_CPP_ONLY_TOOLCHAIN"],
**kwargs
)
elif not is_windows:
Expand All @@ -58,6 +57,5 @@ def rules_haskell_integration_test(
"//tests:nix": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
additional_env_inherit = ["BAZEL_USE_CPP_ONLY_TOOLCHAIN"],
**kwargs
)
5 changes: 0 additions & 5 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ let
writeScriptBin "security" ''exec /usr/bin/security "$@"'';
in
mkShell {
# XXX: hack for macosX, this flags disable bazel usage of xcode
# Note: this is set even for linux so any regression introduced by this flag
# will be catched earlier
# See: https://github.com/bazelbuild/bazel/issues/4231
BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1;
TMPDIR = "/tmp";

GHC_VERSION = ghcVersion;
Expand Down
13 changes: 13 additions & 0 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ common --enable_bzlmod=$BZLMOD
# Should become the default in bazel 7
build --incompatible_enable_cc_toolchain_resolution

# Enable automatic OS-specific config (e.g. build:linux, build:macos, build:windows).
common --enable_platform_specific_config

# MacOS Configuration
# -------------------
# do not use Xcode on macOS
common:macos --repo_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1

# Windows Configuration
# ---------------------
# prevent auto-detection of system compilers on Windows
common:windows --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

EOF

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