Skip to content

Commit

Permalink
Remove compiler_flags
Browse files Browse the repository at this point in the history
This option was deprecated since rules_haskell 0.14, so it is time to get rid of it.
  • Loading branch information
avdv committed Nov 20, 2023
1 parent 7c8be73 commit f47d2d0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 52 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/).

## Unreleased

### Removed

* remove `compiler_flags` option which was deprecated since 0.14 from macros and rules

## [0.17] 2023-10-19

[0.17]: https://github.com/tweag/rules_haskell/compare/v0.16...v0.17
Expand Down
16 changes: 5 additions & 11 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,8 @@ def _haskell_cabal_library_impl(ctx):

user_cabalopts = _expand_make_variables("cabalopts", ctx, ctx.attr.cabalopts)
if ctx.attr.compiler_flags:
print("WARNING: compiler_flags attribute is deprecated. Use cabalopts instead.")
user_cabalopts.extend([
"--ghc-option=" + opt
for opt in _expand_make_variables("compiler_flags", ctx, ctx.attr.compiler_flags)
])
fail("ERROR: `compiler_flags` attribute was removed. Use `cabalopts` with `--ghc-option` instead.")

cabal = _find_cabal(hs, ctx.files.srcs)
setup = _find_setup(hs, cabal, ctx.files.srcs)
package_database = hs.actions.declare_file(
Expand Down Expand Up @@ -696,7 +693,7 @@ haskell_cabal_library = rule(
""",
),
"compiler_flags": attr.string_list(
doc = """DEPRECATED. Use `cabalopts` with `--ghc-option` instead.
doc = """REMOVED. Use `cabalopts` with `--ghc-option` instead.
Flags to pass to Haskell compiler, in addition to those defined the cabal file. Subject to Make variable substitution.""",
),
Expand Down Expand Up @@ -808,11 +805,8 @@ def _haskell_cabal_binary_impl(ctx):
exe_name = ctx.attr.exe_name if ctx.attr.exe_name else hs.label.name
user_cabalopts = _expand_make_variables("cabalopts", ctx, ctx.attr.cabalopts)
if ctx.attr.compiler_flags:
print("WARNING: compiler_flags attribute is deprecated. Use cabalopts instead.")
user_cabalopts.extend([
"--ghc-option=" + opt
for opt in _expand_make_variables("compiler_flags", ctx, ctx.attr.compiler_flags)
])
fail("ERROR: `compiler_flags` attribute was removed. Use `cabalopts` with `--ghc-option` instead.")

cabal = _find_cabal(hs, ctx.files.srcs)
setup = _find_setup(hs, cabal, ctx.files.srcs)
package_database = hs.actions.declare_file(
Expand Down
30 changes: 10 additions & 20 deletions haskell/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ load(
":plugins.bzl",
_ghc_plugin = "ghc_plugin",
)
load(
":private/validate_attrs.bzl",
"check_deprecated_attribute_usage",
)
load(
"//haskell:providers.bzl",
"HaskellLibraryInfo",
Expand Down Expand Up @@ -224,14 +220,6 @@ _haskell_library = rule(
)

def _haskell_worker_wrapper(rule_type, **kwargs):
kwargs["ghcopts"] = check_deprecated_attribute_usage(
old_attr_name = "compiler_flags",
old_attr_value = kwargs["compiler_flags"],
new_attr_name = "ghcopts",
new_attr_value = kwargs["ghcopts"],
)
kwargs.pop("compiler_flags")

defaults = dict(
worker = select({
"@rules_haskell//haskell:use_worker": Label("@rules_haskell//tools/worker:bin"),
Expand All @@ -255,7 +243,6 @@ def haskell_binary(
deps = [],
narrowed_deps = [],
data = [],
compiler_flags = [],
ghcopts = [],
repl_ghci_args = [],
runcompile_flags = [],
Expand Down Expand Up @@ -323,7 +310,6 @@ def haskell_binary(
modules: List of extra haskell_module() dependencies to be linked into this binary.
Note: This attribute is experimental and not ready for production, yet.
data: See [Bazel documentation](https://docs.bazel.build/versions/master/be/common-definitions.html#common.data).,
compiler_flags: DEPRECATED. Use new name ghcopts.
ghcopts: Flags to pass to Haskell compiler. Subject to Make variable substitution.
repl_ghci_args: Arbitrary extra arguments to pass to GHCi. This extends `ghcopts` and `repl_ghci_args` from the toolchain. Subject to Make variable substitution.,
runcompile_flags: Arbitrary extra arguments to pass to runghc. This extends `ghcopts` and `repl_ghci_args` from the toolchain. Subject to Make variable substitution.
Expand All @@ -337,6 +323,10 @@ def haskell_binary(
version: Executable version. If this is specified, CPP version macros will be generated for this build.
**kwargs: Common rule attributes. See [Bazel documentation](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).
"""

if "compiler_flags" in kwargs:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

_haskell_worker_wrapper(
"binary",
name = name,
Expand All @@ -346,7 +336,6 @@ def haskell_binary(
deps = deps,
narrowed_deps = narrowed_deps,
data = data,
compiler_flags = compiler_flags,
ghcopts = ghcopts,
repl_ghci_args = repl_ghci_args,
runcompile_flags = runcompile_flags,
Expand Down Expand Up @@ -406,7 +395,6 @@ def haskell_test(
deps = [],
narrowed_deps = [],
data = [],
compiler_flags = [],
ghcopts = [],
repl_ghci_args = [],
runcompile_flags = [],
Expand Down Expand Up @@ -464,7 +452,6 @@ def haskell_test(
modules: List of extra haskell_module() dependencies to be linked into this test.
Note: This attribute is experimental and not ready for production, yet.
data: See [Bazel documentation](https://docs.bazel.build/versions/master/be/common-definitions.html#common.data).,
compiler_flags: DEPRECATED. Use new name ghcopts.
ghcopts: Flags to pass to Haskell compiler. Subject to Make variable substitution.
repl_ghci_args: Arbitrary extra arguments to pass to GHCi. This extends `ghcopts` and `repl_ghci_args` from the toolchain. Subject to Make variable substitution.,
runcompile_flags: Arbitrary extra arguments to pass to runghc. This extends `ghcopts` and `repl_ghci_args` from the toolchain. Subject to Make variable substitution.
Expand All @@ -491,6 +478,9 @@ def haskell_test(
Note, this attribute may leave experimental status depending on the outcome of https://github.com/bazelbuild/bazel/issues/7763.
**kwargs: Common rule attributes. See [Bazel documentation](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).
"""
if "compiler_flags" in kwargs:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

_haskell_worker_wrapper(
"test",
name = name,
Expand All @@ -500,7 +490,6 @@ def haskell_test(
deps = deps,
narrowed_deps = narrowed_deps,
data = data,
compiler_flags = compiler_flags,
ghcopts = ghcopts,
repl_ghci_args = repl_ghci_args,
runcompile_flags = runcompile_flags,
Expand Down Expand Up @@ -607,7 +596,6 @@ def haskell_library(
modules: List of extra haskell_module() dependencies to be linked into this library.
Note: This attribute is experimental and not ready for production, yet.
data: See [Bazel documentation](https://docs.bazel.build/versions/master/be/common-definitions.html#common.data).,
compiler_flags: DEPRECATED. Use new name ghcopts.
ghcopts: Flags to pass to Haskell compiler. Subject to Make variable substitution.
repl_ghci_args: Arbitrary extra arguments to pass to GHCi. This extends `ghcopts` and `repl_ghci_args` from the toolchain. Subject to Make variable substitution.,
runcompile_flags: Arbitrary extra arguments to pass to runghc. This extends `ghcopts` and `repl_ghci_args` from the toolchain. Subject to Make variable substitution.
Expand All @@ -626,6 +614,9 @@ def haskell_library(
originally defined as a Cabal package, or which is a dependency of a Cabal package. If this is specified, CPP version macro will be generated.
**kwargs: Common rule attributes. See [Bazel documentation](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).
"""
if "compiler_flags" in kwargs:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

_haskell_worker_wrapper(
"library",
name = name,
Expand All @@ -637,7 +628,6 @@ def haskell_library(
narrowed_deps = narrowed_deps,
modules = modules,
data = data,
compiler_flags = compiler_flags,
ghcopts = ghcopts,
repl_ghci_args = repl_ghci_args,
runcompile_flags = runcompile_flags,
Expand Down
15 changes: 6 additions & 9 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -446,20 +446,15 @@ def ghc_bindist(
Args:
name: A unique name for the repository.
version: The desired GHC version.
compiler_flags: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-compiler_flags)
ghcopts: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-ghcopts)
haddock_flags: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-haddock_flags)
repl_ghci_args: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-repl_ghci_args)
cabalopts: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-cabalopts)
locale: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-locale)
register: Whether to register the toolchains (must be set to False if bzlmod is enabled)
"""
ghcopts = check_deprecated_attribute_usage(
old_attr_name = "compiler_flags",
old_attr_value = compiler_flags,
new_attr_name = "ghcopts",
new_attr_value = ghcopts,
)
if compiler_flags:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

bindist_name = name
toolchain_name = "{}-toolchain".format(name)
Expand Down Expand Up @@ -525,7 +520,7 @@ _GHC_AVAILABLE_TARGETS = [

def haskell_register_ghc_bindists(
version = None,
compiler_flags = None,
compiler_flags = None, # TODO remove
ghcopts = None,
haddock_flags = None,
repl_ghci_args = None,
Expand All @@ -539,7 +534,6 @@ def haskell_register_ghc_bindists(
Args:
version: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-version)
compiler_flags: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-compiler_flags)
ghcopts: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-ghcopts)
haddock_flags: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-haddock_flags)
repl_ghci_args: [see rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains-repl_ghci_args)
Expand All @@ -548,6 +542,9 @@ def haskell_register_ghc_bindists(
register: Whether to register the toolchains (must be set to False if bzlmod is enabled)
targets: A list of target platforms to generate bindists for, e.g. `["linux_amd64", "windows_amd64"]` (default: all)
"""
if compiler_flags:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

version = version or _GHC_DEFAULT_VERSION

for target in targets:
Expand Down
18 changes: 7 additions & 11 deletions haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ def haskell_toolchain(
tools,
libraries,
asterius_binaries = None,
compiler_flags = [],
ghcopts = [],
repl_ghci_args = [],
haddock_flags = [],
Expand Down Expand Up @@ -482,7 +481,6 @@ def haskell_toolchain(
asterius_binaries: An optional filegroup containing asterius binaries.
If present the toolchain will target WebAssembly and only use binaries from `tools` if needed to complete the toolchain.
ghcopts: A collection of flags that will be passed to GHC on every invocation.
compiler_flags: DEPRECATED. Use new name ghcopts.
repl_ghci_args: A collection of flags that will be passed to GHCI on repl invocation. It extends the `ghcopts` collection.\\
Flags set here have precedance over `ghcopts`.
haddock_flags: A collection of flags that will be passed to haddock.
Expand All @@ -496,13 +494,10 @@ def haskell_toolchain(
**kwargs: Common rule attributes. See [Bazel documentation](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).
"""
if "compiler_flags" in kwargs:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

corrected_ghci_args = repl_ghci_args + ["-no-user-package-db"]
ghcopts = check_deprecated_attribute_usage(
old_attr_name = "compiler_flags",
old_attr_value = compiler_flags,
new_attr_name = "ghcopts",
new_attr_value = ghcopts,
)

toolchain_rule = _ahc_haskell_toolchain if asterius_binaries else _haskell_toolchain
toolchain_rule(
Expand Down Expand Up @@ -537,7 +532,7 @@ def haskell_toolchain(

def rules_haskell_toolchains(
version = None,
compiler_flags = None,
compiler_flags = None, # TODO remove
ghcopts = None,
haddock_flags = None,
repl_ghci_args = None,
Expand All @@ -557,13 +552,14 @@ def rules_haskell_toolchains(
version: The desired GHC version
locale: Locale that will be set during compiler
invocations. Default: C.UTF-8 (en_US.UTF-8 on MacOS)
compiler_flags: DEPRECATED. Use new name ghcopts.
ghcopts: A collection of flags that will be passed to GHC on every invocation.
"""
if compiler_flags:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

haskell_register_ghc_bindists(
version = version,
compiler_flags = compiler_flags,
ghcopts = ghcopts,
haddock_flags = haddock_flags,
repl_ghci_args = repl_ghci_args,
Expand Down
4 changes: 3 additions & 1 deletion rules_haskell_nix/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ def haskell_register_ghc_nixpkgs(
required in order to use statically-linked Haskell libraries with GHCi
and Template Haskell.
fully_static_link: True if and only if fully-statically-linked binaries are to be built.
compiler_flags: DEPRECADED. Use new name ghcopts.
ghcopts: A collection of flags that will be passed to GHC
compiler_flags_select: temporary workaround to pass conditional arguments.
See https://github.com/bazelbuild/bazel/issues/9199 for details.
Expand All @@ -382,6 +381,9 @@ def haskell_register_ghc_nixpkgs(
Passed to [nixpkgs_sh_posix_configure](https://github.com/tweag/rules_nixpkgs#nixpkgs_sh_posix_configure).
register: Whether to register the toolchain (must be set to False if bzlmod is enabled)
"""
if compiler_flags:
fail("`compiler_flags` argument was removed, use `ghcopts` instead")

nixpkgs_ghc_repo_name = "{}_ghc_nixpkgs".format(name)
nixpkgs_sh_posix_repo_name = "{}_sh_posix_nixpkgs".format(name)

Expand Down

0 comments on commit f47d2d0

Please sign in to comment.