Skip to content

Commit

Permalink
Use bazel_features to check for Bazel 5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Aug 23, 2023
1 parent e2480d2 commit 388e3ac
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ http_archive(
strip_prefix = "${PREFIX}",
url = "${URL}",
)
load("${REPO_NAME}//haskell:repositories.bzl", "rules_haskell_dependencies")
rules_haskell_dependencies()
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()
\`\`\`
EOF
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ bazel_dep(
version = "0.3.0",
)

bazel_dep(name = "bazel_features", version = "1.0.0")

ghc_version = use_extension("//extensions:ghc_version.bzl", "ghc_default_version")

use_repo(
Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ load("//haskell:repositories.bzl", "rules_haskell_dependencies")

rules_haskell_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
Expand Down
8 changes: 8 additions & 0 deletions haskell/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def rules_haskell_dependencies():
strip_prefix = "rules_sh-%s" % _rules_sh_version.lstrip("v"),
)

maybe(
http_archive,
name = "bazel_features",
sha256 = "9fcb3d7cbe908772462aaa52f02b857a225910d30daa3c252f670e3af6d8036d",
strip_prefix = "bazel_features-1.0.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.0.0/bazel_features-v1.0.0.tar.gz",
)

if "io_tweag_rules_nixpkgs" not in native.existing_rules():
# N.B. rules_nixpkgs was split into separate components, which need to be loaded separately
#
Expand Down
7 changes: 5 additions & 2 deletions haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_features//:features.bzl", "bazel_features")
load(":ghc_bindist.bzl", "haskell_register_ghc_bindists")
load(
":private/actions/compile.bzl",
Expand All @@ -19,7 +20,6 @@ load(":private/actions/package.bzl", "package")
load(":cc.bzl", "ghc_cc_program_args")
load(":private/validate_attrs.bzl", "check_deprecated_attribute_usage")
load(":private/context.bzl", "append_to_path")
load(":private/versions.bzl", "check_bazel_version")
load(
"//haskell/asterius:asterius_config.bzl",
"ASTERIUS_BINARIES",
Expand Down Expand Up @@ -332,6 +332,9 @@ def _haskell_toolchain_impl(ctx):
),
]

# RunEnvironmentInfo was introduced in Bazel 5.3.0
_is_at_least_5_3_0 = bazel_features.globals.RunEnvironmentInfo

common_attrs = {
"tools": attr.label_list(
mandatory = True,
Expand Down Expand Up @@ -386,7 +389,7 @@ common_attrs = {
cfg = "exec",
# N.B. can be overridden by `--proto_compiler` flag
# (the proto_compiler configuration field has been introduced in Bazel 5.3.0)
default = configuration_field("proto", "proto_compiler") if check_bazel_version("5.3.0")[0] else "@com_google_protobuf//:protoc",
default = configuration_field("proto", "proto_compiler") if _is_at_least_5_3_0 else "@com_google_protobuf//:protoc",
),
"_rule_info_proto": attr.label(
allow_single_file = True,
Expand Down
7 changes: 7 additions & 0 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ load(
# Setup all Bazel dependencies required by rules_haskell.
rules_haskell_dependencies()
load(
"@bazel_features//:deps.bzl",
"bazel_features_deps"
)
bazel_features_deps()
load(
"@rules_haskell//haskell:toolchain.bzl",
"rules_haskell_toolchains",
Expand Down

0 comments on commit 388e3ac

Please sign in to comment.