Skip to content
Open
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
5 changes: 2 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ coverage --build_tag_filters "coverage-compatible" --test_tag_filters "coverage-

# To update these lines, execute
# `bazel run @contrib_rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=examples,examples/arm,examples/cat_hs,examples/cat_hs/exec/cat_hs,examples/cat_hs/lib/args,examples/cat_hs/lib/cat,examples/primitive,examples/rts,examples/transformers,examples/vector,tests/c2hs/repo,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-a,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-b,tests/haskell_module/repl/haskell_module_repl_test,tests/library-external-workspace/repo,tests/repl-targets/hs_bin_repl_test,tests/repl-targets/hs_lib_repl_test,tests/stack-snapshot-deps/hs_override_stack_test,tutorial,tutorial/lib,tutorial/main,tutorial/tools/build_rules
query --deleted_packages=examples,examples/arm,examples/cat_hs,examples/cat_hs/exec/cat_hs,examples/cat_hs/lib/args,examples/cat_hs/lib/cat,examples/primitive,examples/rts,examples/transformers,examples/vector,tests/c2hs/repo,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-a,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-b,tests/haskell_module/repl/haskell_module_repl_test,tests/library-external-workspace/repo,tests/repl-targets/hs_bin_repl_test,tests/repl-targets/hs_lib_repl_test,tests/stack-snapshot-deps/hs_override_stack_test,tutorial,tutorial/lib,tutorial/main,tutorial/tools/build_rules

build --deleted_packages=examples,examples/arm,examples/asterius,examples/basic_modules,examples/cat_hs,examples/cat_hs/exec/cat_hs,examples/cat_hs/lib/args,examples/cat_hs/lib/cat,examples/primitive,examples/rts,examples/transformers,examples/vector,tests/c2hs/repo,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-a,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-b,tests/haskell_module/repl/haskell_module_repl_test,tests/library-external-workspace/repo,tests/repl-targets/hs_bin_repl_test,tests/repl-targets/hs_lib_repl_test,tests/stack-snapshot-deps/hs_override_stack_test,tutorial,tutorial/lib,tutorial/main,tutorial/tools/build_rules
query --deleted_packages=examples,examples/arm,examples/asterius,examples/basic_modules,examples/cat_hs,examples/cat_hs/exec/cat_hs,examples/cat_hs/lib/args,examples/cat_hs/lib/cat,examples/primitive,examples/rts,examples/transformers,examples/vector,tests/c2hs/repo,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-a,tests/haskell_module/repl/haskell_module_repl_cross_library_deps_test/package-b,tests/haskell_module/repl/haskell_module_repl_test,tests/library-external-workspace/repo,tests/repl-targets/hs_bin_repl_test,tests/repl-targets/hs_lib_repl_test,tests/stack-snapshot-deps/hs_override_stack_test,tutorial,tutorial/lib,tutorial/main,tutorial/tools/build_rules

# User Configuration
# ------------------
Expand Down
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bazel-*
/asterius/bazel-*
14 changes: 13 additions & 1 deletion examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,24 @@ stack_snapshot(
"optparse-applicative",
"text",
"text-show",
"transformers",
],
snapshot = "lts-18.0",
snapshot = "lts-18.28",
# This example uses an unpinned version of stack_snapshot, meaning that stack is invoked on every build.
# To switch to pinned stackage dependencies, run `bazel run @stackage-unpinned//:pin` and
# uncomment the following line.
# And uncomment the following line.
# stack_snapshot_json = "//:stackage_snapshot.json",
vendored_packages = {"split": "@split//:split"},
)

# We setup the Asterius related dependencies.
load(
"@rules_haskell//haskell/asterius:repositories.bzl",
"asterius_dependencies_bindist",
"rules_haskell_asterius_toolchains",
)

asterius_dependencies_bindist()

rules_haskell_asterius_toolchains()
43 changes: 43 additions & 0 deletions examples/asterius/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
load(
"@rules_haskell//haskell:defs.bzl",
"haskell_binary",
)
load(
"@rules_haskell//haskell/asterius:defs.bzl",
"ahc_dist",
"asterius_binary",
"asterius_webpack",
)

# We first define an Haskell binary.
haskell_binary(
name = "main-bin",
srcs = [
"Main.hs",
"src/Lib.hs",
],
main_file = "Main.hs",
src_strip_prefix = "src/",
deps = [
"@stackage//:base",
"@stackage//:transformers",
],
)

# Then an Asterius rule depending of this Haskell binary.
ahc_dist(
name = "asterius",
dep = ":main-bin",
)

# It is this Asterius rule which is then used to construct
# the Asterius binary and Asterius bundle.
asterius_binary(
name = "asterius_binary",
ahc_dist_dep = ":asterius",
)

asterius_webpack(
name = "asterius_bundle",
ahc_dist_dep = ":asterius",
)
6 changes: 6 additions & 0 deletions examples/asterius/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib (printValue)

main :: IO ()
main = printValue
17 changes: 17 additions & 0 deletions examples/asterius/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# asterius - An example on how to use 'asterius' with 'rules_haskell'

This project implements a very basic project with 2 modules.
It uses [Bazel][bazel] build system, using [rules_haskell][rules_haskell]
to define the Asterius Haskell build and output the webassmebly.

[bazel]: https://bazel.build/
[rules_haskell]: https://haskell.build/

## Instructions

To build the package execute the following command *in the `examples/asterius`
directory*:

```
$ bazel build //asterius:asterius_bundle
```
71 changes: 71 additions & 0 deletions examples/asterius/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
workspace(name = "asterius_example")

# Rules_haskell is imported
local_repository(
name = "rules_haskell",
path = "../..",
)

# We setup the dependencies related to rules_haskell.
load("@rules_haskell//haskell:repositories.bzl", "rules_haskell_dependencies")

rules_haskell_dependencies()

load("@rules_haskell//haskell:toolchain.bzl", "rules_haskell_toolchains")

rules_haskell_toolchains(version = "8.10.7")

# We setup the Asterius related dependencies.
load(
"@rules_haskell//haskell/asterius:repositories.bzl",
"asterius_dependencies_bindist",
"rules_haskell_asterius_toolchains",
"asterius_dependencies_nix",
)

asterius_dependencies_bindist()

rules_haskell_asterius_toolchains()

# This example relies on Nixpkgs to get a lot of tools,
# including GHC.
load("@rules_haskell//haskell:nixpkgs.bzl", "haskell_register_ghc_nixpkgs")

asterius_dependencies_nix(
nix_repository = "@nixpkgs",
nixpkgs_package_rule = nixpkgs_package,
nixpkgs_nodejs = "nodejs-16_x",
)

haskell_register_ghc_nixpkgs(
attribute_path = "haskell.compiler.ghc8107",
repository = "@rules_haskell//nixpkgs:default.nix",
version = "8.10.7",
)

load(
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
"nixpkgs_cc_configure",
"nixpkgs_python_configure",
)

nixpkgs_cc_configure(
name = "nixpkgs_config_cc",
repository = "@rules_haskell//nixpkgs:default.nix",
)

nixpkgs_python_configure(
repository = "@rules_haskell//nixpkgs:default.nix",
)

# Our small example uses libraries that we get via Stackage.
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")

stack_snapshot(
name = "stackage",
packages = [
"base",
"transformers",
],
snapshot = "lts-18.28",
)
13 changes: 13 additions & 0 deletions examples/asterius/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Lib (printValue) where

import Control.Monad (void)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Except (ExceptT, runExceptT)

getValue :: Monad m => ExceptT e m String
getValue = pure "Hello world!"

printValue :: IO ()
printValue = void $ runExceptT $ do
value <- getValue
lift $ print value