Skip to content

Commit

Permalink
Merge pull request #1619 from tweag/ylecornec/asterius_toolchain_decl…
Browse files Browse the repository at this point in the history
…arations

Asterius toolchain declarations
  • Loading branch information
mergify[bot] authored Oct 28, 2021
2 parents c991642 + b64079d commit b6ac6ee
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 46 deletions.
31 changes: 20 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ haskell_cabal_binary(

load(
"@rules_haskell//:constants.bzl",
"test_asterius_version",
"test_ghc_version",
"test_stack_snapshot",
)
Expand Down Expand Up @@ -271,6 +272,25 @@ haskell_register_ghc_nixpkgs(
version = test_ghc_version,
)

load(
"//haskell/asterius:repositories.bzl",
"asterius_dependencies_bindist",
"asterius_dependencies_nix",
"rules_haskell_asterius_toolchains",
)

(asterius_dependencies_nix(
nix_repository = "@nixpkgs_default",
nixpkgs_package_rule = nixpkgs_package,
) if is_nix_shell else asterius_dependencies_bindist())

rules_haskell_asterius_toolchains(
cabalopts = test_cabalopts,
ghcopts = test_ghcopts,
repl_ghci_args = test_repl_ghci_args,
version = test_asterius_version,
)

load(
"@rules_haskell//haskell:ghc_bindist.bzl",
"haskell_register_ghc_bindists",
Expand Down Expand Up @@ -460,17 +480,6 @@ maybe(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.6.0/rules_nodejs-3.6.0.tar.gz"],
)

load(
"//haskell/asterius:asterius_repositories.bzl",
"asterius_dependencies_bindist",
"asterius_dependencies_nix",
)

(asterius_dependencies_nix(
nix_repository = "@nixpkgs_default",
nixpkgs_package_rule = nixpkgs_package,
) if is_nix_shell else asterius_dependencies_bindist())

http_archive(
name = "io_bazel_rules_sass",
sha256 = "86f734253cb2480acab150f37eb6c5952f33ed463182f77eedf2e41ba2fe2e8f",
Expand Down
1 change: 1 addition & 0 deletions constants.bzl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test_ghc_version = "8.10.4"
test_stack_snapshot = "lts-18.0"
test_asterius_version = "0.0.1"
18 changes: 18 additions & 0 deletions haskell/asterius/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ bzl_library(
name = "asterius_bzl",
srcs = [
"asterius_config.bzl",
"repositories.bzl",
],
visibility = ["//haskell:__pkg__"],
deps = [
"//haskell/platforms",
],
)

platform(
name = "asterius_platform",
constraint_values = [
"@platforms//cpu:wasm32",
],
)

# Toolchain type for asterius specific tools such as ahc-dist,
# which are not part of the regular haskell toolchain.
toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"],
)
22 changes: 20 additions & 2 deletions haskell/asterius/asterius_config.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# From the asterius/cabal/config file of asterius and ahc-cabal.hs
asterius_cabalopts = [
"--enable-library-vanilla",
"--disable-executable-dynamic",
"--disable-profiling",
"-O 2",
"--disable-debug-info",
"--disable-library-for-ghci",
"--disable-split-sections",
"--disable-split-objs",
"--disable-executable-stripping",
"--disable-library-stripping",
"--disable-tests",
"--disable-coverage",
"--disable-benchmarks",
"--hsc2hs-options=--cross-compile",
]

# asterius equivalents of tools from the haskell toolchain.
ASTERIUS_BINARIES = {
"ghc": "ahc",
"ghc-pkg": "ahc-pkg",
"ahc": "ghc",
"ahc-pkg": "ghc_pkg",
}

def asterius_tools_config(exec_cc_toolchain, posix_toolchain, node_toolchain, tools_for_ghc_pkg):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def asterius_dependencies_nix(
nixpkgs_package_rule: The `nixpkgs_package` rule from `rules_nixpkgs`.
package_json: The package.json file that will be passed to [yarn_install](https://bazelbuild.github.io/rules_nodejs/Built-ins.html#yarn_install)
yarn_lock: The yarn.lock file that will be passed to [yarn_install](https://bazelbuild.github.io/rules_nodejs/Built-ins.html#yarn_install)
nixpkgs_nodejs = The name for the nodejs that will be installed with `nixpkgs_package`.
nixpkgs_nodejs: The name for the nodejs that will be installed with `nixpkgs_package`.
"""
_nixpkgs_nodejs(nixpkgs_nodejs, nix_repository, nixpkgs_package_rule)
node_repositories(
Expand Down
33 changes: 33 additions & 0 deletions haskell/asterius/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@bazel_skylib//lib:paths.bzl", "paths")

def _asterius_toolchain_impl(ctx):
ahc_dist = None
for file in ctx.files.binaries:
basename_no_ext = paths.split_extension(file.basename)[0]
if basename_no_ext == "ahc-dist":
ahc_dist = file
if ahc_dist == None:
fail("ahc-dist was not found when defining the asterius toolchain")

return [
platform_common.ToolchainInfo(
name = ctx.label.name,
ahc_dist = ahc_dist,
tools = ctx.files.tools,
),
]

asterius_toolchain = rule(
_asterius_toolchain_impl,
attrs = {
"binaries": attr.label_list(
mandatory = True,
doc = "The asterius top level wrappers",
),
"tools": attr.label_list(
mandatory = True,
doc = "The complete asterius bundle, which is needed to execute the wrappers.",
),
},
doc = "Toolchain for asterius tools that are not part of the regular haskell toolchain",
)
Loading

0 comments on commit b6ac6ee

Please sign in to comment.