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

Plug gazelle_cabal.ImportData in Resolve to allow both gazelle extensions to run in the same gazelle_binary #41

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
57 changes: 51 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,36 @@ This [example project][example] shows it in action.
## Configuration

Firstly, setup [gazelle][gazelle] and [rules_haskell][rules_haskell].
Then import `gazelle_haskell_modules`.
Then import `gazelle_cabal` and `gazelle_haskell_modules`.

```python
####################
# Gazelle_cabal
####################

http_archive(
name = "io_tweag_gazelle_cabal",
strip_prefix = "gazelle_cabal-240ad1af8d0d0ca5c3fd3ff7afcdb2f0fe0dbbe2",
urls = ["https://github.com/tweag/gazelle_cabal/archive/240ad1af8d0d0ca5c3fd3ff7afcdb2f0fe0dbbe2.zip"],
)
Copy link
Member

@facundominguez facundominguez Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a unsatisfying that we now have to bring gazelle_cabal even if the user does not intend to use it. But I don't see how to avoid it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree


load("@io_tweag_gazelle_cabal//:defs.bzl", "gazelle_cabal_dependencies")

gazelle_cabal_dependencies()

####################
# Gazelle_haskell_modules
####################

http_archive(
name = "io_tweag_gazelle_haskell_modules",
strip_prefix = "gazelle_haskell_modules-main",
url = "https://github.com/tweag/gazelle_haskell_modules/archive/main.zip",
strip_prefix = "gazelle_haskell_modules-a94dfc9591029aa35a7a62519735d0fe04b0e4fa",
urls = ["https://github.com/tweag/gazelle_haskell_modules/archive/a94dfc9591029aa35a7a62519735d0fe04b0e4fa.zip"],
)

load("@io_tweag_gazelle_haskell_modules//:defs.bzl", "gazelle_haskell_modules_dependencies")

gazelle_haskell_modules_dependencies()
```

Additionally, some Haskell packages are needed to build
Expand All @@ -69,13 +91,11 @@ Additionally, some Haskell packages are needed to build

```python
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")
load("@io_tweag_gazelle_haskell_modules//:defs.bzl", "gazelle_haskell_modules_dependencies")
gazelle_haskell_modules_dependencies()

stack_snapshot(
name = "stackage",
packages = [
"hspec",
"json", #keep
],
# Most snapshots of your choice might do
snapshot = "lts-18.28",
Expand Down Expand Up @@ -106,6 +126,31 @@ gazelle_binary(
)
```

### Combining `gazelle_cabal` and `gazelle_haskell_modules`

One can run both extensions in one invocation,
to both update the binary/library/tests rules depending of the changes made to your cabal files,
and generate/update the associated `haskell_module` rules.

To do so, one simply has to declare the `gazelle_binary` as

```python
gazelle_binary(
name = "gazelle_binary",
name = "gazelle_binary",
languages = DEFAULT_LANGUAGES + [
"@io_tweag_gazelle_cabal//gazelle_cabal",
"@io_tweag_gazelle_haskell_modules//gazelle_haskell_modules",
],
)
```

Please note that the order of the language extension is relevant here.
One must first grab the updates from the cabal files using `gazelle_cabal`
and then create/update the associated `haskell_module` rules.
If the order of the extensions is wrong,
the creation/updating of `haskell_modules` will be based on an outdated version of the library/binary/test rules.

### Using GHC version 9.2

Due to a regression in `cabal`, which badly handles relocatable build now,
Expand Down
3 changes: 0 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ gazelle_dependencies()
# Gazelle Cabal
####################

# QUESTION: When the pull request adding the 2 missing library functions in gazelle_cabal is merged,
# should we refer to an explicit commit of gazelle_cabal or to `main`?

http_archive(
name = "io_tweag_gazelle_cabal",
sha256 = "853acd38dc69284c915c0d30fe6e051593bf4e7f900e6be13ef306fc7ffa74c0",
Expand Down
3 changes: 0 additions & 3 deletions example/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ gazelle_dependencies()
# Gazelle Cabal
####################

# QUESTION: When the pull request adding the 2 missing library functions in gazelle_cabal is merged,
# should we refer to an explicit commit of gazelle_cabal or to `main`?

http_archive(
name = "io_tweag_gazelle_cabal",
sha256 = "853acd38dc69284c915c0d30fe6e051593bf4e7f900e6be13ef306fc7ffa74c0",
Expand Down
3 changes: 0 additions & 3 deletions tests/alternative-deps/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ gazelle_dependencies()
# Gazelle Cabal
####################

# QUESTION: When the pull request adding the 2 missing library functions in gazelle_cabal is merged,
# should we refer to an explicit commit of gazelle_cabal or to `main`?

http_archive(
name = "io_tweag_gazelle_cabal",
sha256 = "853acd38dc69284c915c0d30fe6e051593bf4e7f900e6be13ef306fc7ffa74c0",
Expand Down