Skip to content

Commit

Permalink
Add rules_haskell module version 0.17 (#1029)
Browse files Browse the repository at this point in the history
* Add rules_haskell module version 0.17

* Add patch fixing stack_snapshot extension usage

* Add patch to remove obsolete aliases referring to nixpkgs core module

* Build only //tools/... and //haskell/...

* Set BAZEL_USE_CPP_ONLY_TOOLCHAIN

* Install libtinfo5 and libgmp-dev on Debian / Ubuntu

* Only build / test //test/... from test module

* Enforce system certificates updates on Windows

The stack tool could not download the root.json file from hackage. It failed
with a TLS exception caused by a missing CA for the server certificate.

It seems that opening a web page with Internet Explorer or with powershell
causes the certificates to be updated.

See commercialhaskell/stack#234

* Enable cc toolchain resolution

* Add patch for windows

Register the cc toolchain that comes with the GHC bindist.

* Remove bcr_test_module for now

Our test module depends on rules_nixpkgs' modules which are not available yet.

* Set BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 on Windows

* Skip Windows on CI

It is currently failing with:
```
this rule is missing dependency declarations for the following files included by 'gzwrite.c':
  'C:/b/f3c3gu33/execroot/_main/external/rules_haskell~0.17~haskell_toolchains~rules_haskell_ghc_windows_amd64/mingw/x86_64-w64-mingw32/include/stdio.h'
  'C:/b/f3c3gu33/execroot/_main/external/rules_haskell~0.17~haskell_toolchains~rules_haskell_ghc_windows_amd64/mingw/x86_64-w64-mingw32/include/corecrt_stdio_config.h'
  'C:/b/f3c3gu33/execroot/_main/external/rules_haskell~0.17~haskell_toolchains~rules_haskell_ghc_windows_amd64/mingw/x86_64-w64-mingw32/include/corecrt.h'
...
```
  • Loading branch information
avdv committed Nov 6, 2023
1 parent 1173c14 commit aa95069
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 0 deletions.
350 changes: 350 additions & 0 deletions modules/rules_haskell/0.17/MODULE.bazel
@@ -0,0 +1,350 @@
module(
name = "rules_haskell",
version = "0.17",
)

bazel_dep(
name = "platforms",
version = "0.0.6",
)
bazel_dep(
name = "rules_java",
version = "6.1.0",
)
bazel_dep(
name = "rules_license",
version = "0.0.7",
)
bazel_dep(
name = "protobuf",
version = "3.19.0",
repo_name = "com_google_protobuf",
)
bazel_dep(
name = "rules_cc",
version = "0.0.8",
)
bazel_dep(
name = "rules_nodejs",
version = "5.8.2",
)
bazel_dep(
name = "rules_python",
version = "0.21.0",
)
bazel_dep(
name = "bazel_skylib",
version = "1.4.2",
)
bazel_dep(
name = "rules_proto",
version = "5.3.0-21.7",
)
bazel_dep(
name = "aspect_rules_js",
version = "1.31.0",
)
bazel_dep(
name = "rules_sh",
version = "0.3.0",
)

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

rules_haskell_dependencies = use_extension(
"//extensions:rules_haskell_dependencies.bzl",
"rules_haskell_dependencies",
)
use_repo(
rules_haskell_dependencies,
"Cabal",
"os_info",
"rules_haskell_stack",
"rules_haskell_stack_update",
"rules_haskell_worker_dependencies",
)

asterius = use_extension("@rules_haskell//haskell/asterius:extension.bzl", "rules_haskell_asterius")
use_repo(
asterius,
"rules_haskell_asterius_build_setting",
"rules_haskell_asterius_webpack",
)

haskell_toolchains = use_extension(
"@rules_haskell//extensions:haskell_toolchains.bzl",
"haskell_toolchains",
)
haskell_toolchains.bindists()
use_repo(
haskell_toolchains,
"all_bindist_toolchains",
"rules_haskell_ghc_windows_amd64_cc_toolchain",
"rules_haskell_python_local",
)

# We need to register the nix toolchain before the bindist ones so it
# take precedence when we use the nixpkgs config.
register_toolchains(
"@rules_haskell_ghc_nixpkgs_toolchain//:toolchain",
dev_dependency = True,
)

register_toolchains(
"@all_bindist_toolchains//:all",
"@rules_haskell_ghc_windows_amd64_cc_toolchain//:all",
"@rules_haskell_python_local//:toolchain",
)

# Setup node toolchain and install webpack for asterius.
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "16.9.0")

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
)
npm.npm_translate_lock(
name = "rules_haskell_npm",
link_workspace = "rules_haskell",
pnpm_lock = "//haskell/asterius/npm:pnpm-lock.yaml",
verify_node_modules_ignored = "@rules_haskell//:.bazelignore",
)
use_repo(npm, "rules_haskell_npm")

#### Development dependencies ####
bazel_dep(
name = "rules_nixpkgs_core",
version = "0.9.0",
dev_dependency = True,
)
bazel_dep(
name = "rules_nixpkgs_cc",
version = "0.9.0",
dev_dependency = True,
)
bazel_dep(
name = "rules_nixpkgs_python",
version = "0.9.0",
dev_dependency = True,
)
bazel_dep(
name = "rules_nixpkgs_go",
version = "0.9.0",
dev_dependency = True,
)
bazel_dep(
name = "rules_nixpkgs_posix",
version = "0.9.0",
dev_dependency = True,
)
bazel_dep(
name = "stardoc",
version = "0.5.4",
dev_dependency = True,
repo_name = "io_bazel_stardoc",
)
bazel_dep(
name = "rules_nixpkgs_nodejs",
version = "0.9.0",
dev_dependency = True,
)

non_module_dev_deps = use_extension(
"//:non_module_dev_deps.bzl",
"non_module_dev_deps",
dev_dependency = True,
)
use_repo(
non_module_dev_deps,
"examples",
"examples-arm",
"tutorial",
)
use_repo(
non_module_dev_deps,
"nixpkgs_default",
"rules_haskell_ghc_nixpkgs",
"rules_haskell_ghc_nixpkgs_toolchain",
)
use_repo(
non_module_dev_deps,
"nixpkgs_config_cc",
"nixpkgs_config_cc_info",
"nixpkgs_config_cc_toolchains",
"nixpkgs_python_toolchain",
)

register_toolchains(
"@nixpkgs_config_cc_toolchains//:all",
"@nixpkgs_python_toolchain//:toolchain",
dev_dependency = True,
)

# For buildifier
bazel_dep(
name = "rules_go",
version = "0.39.1",
dev_dependency = True,
repo_name = "io_bazel_rules_go",
)

use_repo(
non_module_dev_deps,
"com_github_bazelbuild_buildtools",
"nixpkgs_go_sdk_toolchains",
)

register_toolchains(
"@nixpkgs_go_sdk_toolchains//:all",
dev_dependency = True,
)

go_sdk = use_extension(
"@io_bazel_rules_go//go:extensions.bzl",
"go_sdk",
dev_dependency = True,
)
go_sdk.download(
version = "1.19.7",
)

bazel_dep(
name = "gazelle",
version = "0.30.0",
dev_dependency = True,
)

go_deps = use_extension(
"@gazelle//:extensions.bzl",
"go_deps",
dev_dependency = True,
)
go_deps.module(
path = "github.com/gogo/protobuf",
sum = "h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=",
version = "v1.3.2",
)
use_repo(
go_deps,
"com_github_gogo_protobuf",
"com_github_golang_mock",
"com_github_golang_protobuf",
"org_golang_google_genproto",
"org_golang_google_grpc",
"org_golang_google_protobuf",
"org_golang_x_net",
"org_golang_x_tools",
)

# For documentation
use_repo(
non_module_dev_deps,
"graphviz",
"linux_pandoc",
"macos_pandoc",
"nixpkgs_pandoc",
"sphinx",
"zip",
)

register_toolchains(
"@rules_haskell//docs/pandoc:nixpkgs",
"@rules_haskell//docs/pandoc:linux",
"@rules_haskell//docs/pandoc:macos",
"@rules_haskell//tests:protobuf-toolchain",
"@rules_haskell//tests:protobuf-toolchain-osx_arm64",
dev_dependency = True,
)

stack_snapshot = use_extension(
"@rules_haskell//extensions:stack_snapshot.bzl",
"stack_snapshot",
)

# The @stackage workspace is referenced in the `stack_snapshot` macro to
# forward the generated `components.json` file to the `_stack_executables`
# repository rule which generates the `@stackage-exe` workspace. This reference
# is resolved within the scope of rules_haskell and therefore requires
# `@stackage` to be imported.
# See https://github.com/tweag/rules_haskell/blob/e31617dcd76264f00a833625f70e1e46e91fbc57/haskell/cabal.bzl#L2709
# TODO[AH] Find a way to not require an import of `@stackage` into rules_haskell.
use_repo(
stack_snapshot,
"stackage",
)

stack_snapshot_dev = use_extension(
"@rules_haskell//extensions:stack_snapshot.bzl",
"stack_snapshot",
dev_dependency = True,
)

[
stack_snapshot_dev.package(
name = package,
)
for package in [
# Core libraries
"base",
"bytestring",
"containers",
"deepseq",
"mtl",
"text",
"vector",
# For tests
"lens-family-core",
"data-default-class",
"proto-lens",
"lens-family",
]
]

stack_snapshot_dev.package(
name = "ghc-paths",
vendored = "@rules_haskell//tools/ghc-paths",
)
stack_snapshot_dev.package(
name = "proto-lens-protoc",
components = [
"lib",
"exe",
],
setup_deps = ["@Cabal//:Cabal"],
)

[
# See https://github.com/tweag/rules_haskell/issues/1871
stack_snapshot_dev.package(
name = package,
setup_deps = ["@Cabal//:Cabal"],
)
for package in [
"HUnit",
"bifunctors",
"call-stack",
"generic-deriving",
"mono-traversable",
"proto-lens-runtime",
"quickcheck-io",
"transformers-compat",
"type-errors",
"typed-process",
"unliftio-core",
]
]

stack_snapshot_dev.stack_snapshot_json(label = "@rules_haskell//:stackage_snapshot.json")
stack_snapshot_dev.snapshot(
local_snapshot = "@rules_haskell//:stackage_snapshot.yaml",
)
use_repo(
stack_snapshot_dev,
"stackage-exe",
"stackage-unpinned",
)
20 changes: 20 additions & 0 deletions modules/rules_haskell/0.17/patches/register-mingw.patch
@@ -0,0 +1,20 @@
diff --git a/MODULE.bazel b/MODULE.bazel
index b613ac12..287f8dc5 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -83,6 +83,7 @@ haskell_toolchains.bindists()
use_repo(
haskell_toolchains,
"all_bindist_toolchains",
+ "rules_haskell_ghc_windows_amd64_cc_toolchain",
"rules_haskell_python_local",
)

@@ -95,6 +96,7 @@ register_toolchains(

register_toolchains(
"@all_bindist_toolchains//:all",
+ "@rules_haskell_ghc_windows_amd64_cc_toolchain//:all",
"@rules_haskell_python_local//:toolchain",
)

0 comments on commit aa95069

Please sign in to comment.