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

Refactor WORKSPACE file #1886

Merged
merged 7 commits into from
Apr 24, 2023
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
Empty file added MODULE.bazel
Empty file.
659 changes: 18 additions & 641 deletions WORKSPACE

Large diffs are not rendered by default.

47 changes: 27 additions & 20 deletions haskell/asterius/asterius_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def _nixpkgs_nodejs(name, nix_repository, nixpkgs_package_rule):
fail_not_supported = False,
)

def asterius_dependencies_bindist():
def asterius_dependencies_bindist(
register = True):
""" Install asterius dependencies for bindists.

A `rules_haskell_npm` repository is created that needs to be used as follow in the WORKSPACE file:
Expand All @@ -43,26 +44,31 @@ A `rules_haskell_npm` repository is created that needs to be used as follow in t
load("@rules_haskell_npm//:repositories.bzl", "npm_repositories")
npm_repositories()
```

Args:
register: Whether to register the asterius toolchain (must be set to False if bzlmod is activated)
"""
nodejs_register_toolchains(
name = "nodejs",
node_version = "16.19.0",
)
_ahc_target_build_setting(name = "rules_haskell_asterius_build_setting")
npm_translate_lock(
name = "rules_haskell_npm",
pnpm_lock = DEFAULT_PNPM_LOCK,
verify_node_modules_ignored = "//:.bazelignore",
link_workspace = "rules_haskell",
)
if register:
nodejs_register_toolchains(
name = "nodejs",
node_version = "16.19.0",
)
npm_translate_lock(
name = "rules_haskell_npm",
pnpm_lock = DEFAULT_PNPM_LOCK,
verify_node_modules_ignored = "//:.bazelignore",
link_workspace = "rules_haskell",
)
_declare_webpack(
name = "rules_haskell_asterius_webpack",
)

def asterius_dependencies_nix(
nix_repository,
nixpkgs_package_rule,
nixpkgs_nodejs = DEFAULT_NIXPKGS_NODEJS):
nixpkgs_nodejs = DEFAULT_NIXPKGS_NODEJS,
register = True):
"""Install asterius dependencies based on nix.

A `rules_haskell_npm` repository is created that needs to be used as follow in the WORKSPACE file:
Expand All @@ -76,6 +82,7 @@ npm_repositories()
nix_repository: The nix repository from which we try to install node.
nixpkgs_package_rule: The `nixpkgs_package` rule from `rules_nixpkgs`.
nixpkgs_nodejs: The prefix for the for the nodejs repositories that will be installed with `nixpkgs_package`.
register: Whether to register the asterius toolchain (must be set to False if bzlmod is activated)
"""

_nixpkgs_nodejs(nixpkgs_nodejs, nix_repository, nixpkgs_package_rule)
Expand All @@ -84,14 +91,14 @@ npm_repositories()
name = "rules_haskell_nix_node_toolchain",
nixpkgs_nodejs = nixpkgs_nodejs,
)
native.register_toolchains("@rules_haskell_nix_node_toolchain//:node_nixpkgs_toolchain")

npm_translate_lock(
name = "rules_haskell_npm",
pnpm_lock = DEFAULT_PNPM_LOCK,
verify_node_modules_ignored = "//:.bazelignore",
link_workspace = "rules_haskell",
)
if register:
native.register_toolchains("@rules_haskell_nix_node_toolchain//:node_nixpkgs_toolchain")
npm_translate_lock(
name = "rules_haskell_npm",
pnpm_lock = DEFAULT_PNPM_LOCK,
verify_node_modules_ignored = "//:.bazelignore",
link_workspace = "rules_haskell",
)
_ahc_target_build_setting(name = "rules_haskell_asterius_build_setting")

_declare_webpack(
Expand Down
15 changes: 9 additions & 6 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,7 @@ def stack_snapshot(
verbose = False,
netrc = "",
toolchain_libraries = None,
setup_stack = True,
**kwargs):
"""Use Stack to download and extract Cabal source distributions.

Expand Down Expand Up @@ -2609,13 +2610,14 @@ def stack_snapshot(
...,
)
```
setup_stack: Do not try to install stack if set to False (only usefull with bzlmod when only the first call to stack_snapshot must do the install).

"""
typecheck_stackage_extradeps(extra_deps)

# Allow overriding stack binary at workspace level by `use_stack()`.
# Otherwise this is a no-op.
if native.existing_rule("rules_haskell_stack"):
if native.existing_rule("rules_haskell_stack") or not setup_stack:
stack = Label("@rules_haskell_stack//:stack")

if not stack:
Expand All @@ -2626,11 +2628,12 @@ def stack_snapshot(
# This is to avoid multiple concurrent executions of stack update,
# which may fail due to ~/.stack/pantry/hackage/hackage-security-lock.
# See https://github.com/tweag/rules_haskell/issues/1090.
maybe(
_stack_update,
name = "rules_haskell_stack_update",
stack = stack,
)
if setup_stack:
maybe(
_stack_update,
name = "rules_haskell_stack_update",
stack = stack,
)
_stack_snapshot_unpinned(
name = name + "-unpinned",
stack = stack,
Expand Down
32 changes: 23 additions & 9 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def ghc_bindist(
haddock_flags = None,
repl_ghci_args = None,
cabalopts = None,
locale = None):
locale = None,
register = True):
"""Create a new repository from binary distributions of GHC.

The repository exports two targets:
Expand Down Expand Up @@ -361,7 +362,7 @@ def ghc_bindist(
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",
Expand Down Expand Up @@ -420,11 +421,13 @@ def ghc_bindist(
bindist_name = bindist_name,
target = target,
)
native.register_toolchains("@{}//:toolchain".format(toolchain_name))
if register:
native.register_toolchains("@{}//:toolchain".format(toolchain_name))
if target == "windows_amd64":
cc_toolchain_repo_name = "{}_cc_toolchain".format(bindist_name)
_windows_cc_toolchain(name = cc_toolchain_repo_name, bindist_name = bindist_name)
native.register_toolchains("@{}//:windows_cc_toolchain".format(cc_toolchain_repo_name))
if register:
native.register_toolchains("@{}//:windows_cc_toolchain".format(cc_toolchain_repo_name))

def haskell_register_ghc_bindists(
version = None,
Expand All @@ -433,7 +436,8 @@ def haskell_register_ghc_bindists(
haddock_flags = None,
repl_ghci_args = None,
cabalopts = None,
locale = None):
locale = None,
register = True):
""" Register GHC binary distributions for all platforms as toolchains.

See [rules_haskell_toolchains](toolchain.html#rules_haskell_toolchains).
Expand All @@ -446,6 +450,7 @@ def haskell_register_ghc_bindists(
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)
"""
version = version or _GHC_DEFAULT_VERSION
if not GHC_BINDIST.get(version):
Expand All @@ -461,13 +466,17 @@ def haskell_register_ghc_bindists(
repl_ghci_args = repl_ghci_args,
cabalopts = cabalopts,
locale = locale,
register = register,
)
local_sh_posix_repo_name = "rules_haskell_sh_posix_local"
if local_sh_posix_repo_name not in native.existing_rules():
sh_posix_configure(name = local_sh_posix_repo_name)
sh_posix_configure(
name = local_sh_posix_repo_name,
register = register,
)
local_python_repo_name = "rules_haskell_python_local"
if local_python_repo_name not in native.existing_rules():
_configure_python3_toolchain(name = local_python_repo_name)
_configure_python3_toolchain(name = local_python_repo_name, register = register)

def _configure_python3_toolchain_impl(repository_ctx):
cpu = get_cpu_value(repository_ctx)
Expand Down Expand Up @@ -521,7 +530,7 @@ _config_python3_toolchain = repository_rule(
environ = ["PATH"],
)

def _configure_python3_toolchain(name):
def _configure_python3_toolchain(name, register = True):
"""Autoconfigure python3 toolchain for GHC bindist

`rules_haskell` requires Python 3 to build Haskell targets. Under Nix we
Expand Down Expand Up @@ -558,9 +567,14 @@ def _configure_python3_toolchain(name):
does not restrict the visible installation paths. It then registers an
appropriate Python toolchain, so that build actions themselves can still be
sandboxed.

Args:
name: A unique name for the repository.
register: Whether to register the toolchains (must be set to False if bzlmod is enabled)
"""
_config_python3_toolchain(name = name)
native.register_toolchains("@{}//:toolchain".format(name))
if register:
native.register_toolchains("@{}//:toolchain".format(name))

# Note [GHC toolchain files]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 10 additions & 3 deletions haskell/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ load(
"check_bazel_version_compatible",
)

_rules_nixpkgs_version = "v0.9.0"
_rules_nixpkgs_sha256 = "b01f170580f646ee3cde1ea4c117d00e561afaf3c59eda604cf09194a824ff10"
_rules_nixpkgs_version = "fb0e76e093c6ba7987ea4276027507a0d6dceb06"
_rules_nixpkgs_sha256 = "a8f20854da16156bd4e0d53d13dfb0d3360ee43c5ce764f0dc60703ab2b910e5"

_rules_sh_version = "v0.3.0"
_rules_sh_sha256 = "d668bb32f112ead69c58bde2cae62f6b8acefe759a8c95a2d80ff6a85af5ac5e"
Expand Down Expand Up @@ -76,14 +76,21 @@ def rules_haskell_dependencies():
sha256 = _rules_nixpkgs_sha256,
)

# requiered by rules_nixpkgs
http_archive(
name = "rules_nodejs",
sha256 = "08337d4fffc78f7fe648a93be12ea2fc4e8eb9795a4e6aa48595b66b34555626",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.0/rules_nodejs-core-5.8.0.tar.gz"],
)

http_archive(
name = "rules_nixpkgs_core",
strip_prefix = strip_prefix + "/core",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % _rules_nixpkgs_version],
sha256 = _rules_nixpkgs_sha256,
)

for toolchain in ["cc", "java", "python", "go", "rust", "posix"]:
for toolchain in ["cc", "java", "python", "go", "rust", "posix", "nodejs"]:
http_archive(
name = "rules_nixpkgs_" + toolchain,
strip_prefix = strip_prefix + "/toolchains/" + toolchain,
Expand Down
Loading