#!/bin/sh MIN_BAZEL_MAJOR=0 MIN_BAZEL_MINOR=24 set -e check_files_dont_exist () { if [ -e WORKSPACE ] || [ -e BUILD ] || [ -e BazelExample.hs ] then echo "Current directory already has WORKSPACE and/or BUILD and/or BazelExample.hs files." >/dev/stderr exit 1 fi } check_bazel_version () { local actual_raw=$(bazel version | egrep '^Build label:' | egrep -o '[0-9.]+') IFS=. read actual_major actual_minor actual_patch </dev/stderr exit 1 fi } check_files_dont_exist check_bazel_version cat > WORKSPACE <<"EOF" # Give your project a name. :) workspace(name = "YOUR_PROJECT_NAME_HERE") # Load the repository rule to download an http archive. load( "@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive" ) # Download `rules_haskell`. # and make it accessible `@io_tweag_rules_haskell`. http_archive( name = "io_tweag_rules_haskell", strip_prefix = "rules_haskell-0.8", urls = ["https://github.com/tweag/rules_haskell/archive/v0.8.tar.gz"], sha256 = "431d492a8ee6a110cdf42496181c9d27225dfb997379e64a148eb8e69f272ab7", ) load( "@io_tweag_rules_haskell//haskell:repositories.bzl", "haskell_repositories" ) # `haskell_repositories()` sets up all bazel dependencies # required by `rules_haskell`. haskell_repositories() load( "@io_tweag_rules_haskell//haskell:haskell.bzl", "haskell_register_ghc_bindists", ) # Registers a haskell toolchain with a GHC binary # downloaded from haskell.org. haskell_register_ghc_bindists(version = "8.6.4") EOF cat > BUILD.bazel <<"EOF" # Set all target’s visibility in this package to "public". package(default_visibility = ["//visibility:public"]) # Load `rules_haskell` rules. load( "@io_tweag_rules_haskell//haskell:haskell.bzl", "haskell_toolchain_library", "haskell_library", "haskell_binary", ) # `haskell_toolchain_library` can access builtin GHC packages # and assign them a bazel target name, so that they # can be referenced as dependencies. haskell_toolchain_library(name = "base") # You can add your own libraries with `haskell_library`. # haskell_library( # name = "MY_LIBRARY_NAME", # src_strip_prefix = "src", # srcs = glob(['src/**/*.hs']), # deps = [ # "base_pkg" # ], # ) # An example binary using the Prelude module from the # GHC base package, to print the hello world. haskell_binary( name = "example", srcs = [":Example.hs"], deps = [":base"], ) EOF cat > Example.hs <<"EOF" module Main where import Prelude (putStrLn) main = putStrLn "Hello from rules_haskell!" EOF cat <<"EOF" WORKSPACE and initial BUILD files created. To run Bazel and build the example: $ bazel run //:example EOF