Bazel build rules for Elm
Adding these rules to your project
Add the following declarations to your
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "com_github_edschouten_rules_elm", sha256 = "c34015356f755e5c8dd26c5a82ff9710353f925f435861892fb80a929fa07445", strip_prefix = "rules_elm-0.2", urls = ["https://github.com/EdSchouten/rules_elm/archive/v0.2.tar.gz"], ) load("@com_github_edschouten_rules_elm//elm:deps.bzl", "elm_register_toolchains") elm_register_toolchains()
Build rules provided by this project
load("@com_github_edschouten_rules_elm//elm:def.bzl", "elm_binary") elm_binary(name, main, deps, visibility)
main: The name of the source file containing the
deps: List of
elm_package()targets on which the application depends.
Note: When the compilation mode (
-c) is equal to
When the compilation mode is
opt, optimizations are performed.
load("@com_github_edschouten_rules_elm//elm:def.bzl", "elm_library") elm_library(name, srcs, deps, strip_import_prefix, visibility)
Purpose: declare a collection of Elm source files that can be reused
srcs: List of source files to package together.
deps: List of
elm_package()targets on which the library depends.
strip_import_prefix: Workspace root relative path prefix that should be removed from pathname resolution. For example, if the source file
strip_import_prefixshould be set to
my/projectfor module resolution to work.
load("@com_github_edschouten_rules_elm//elm:def.bzl", "elm_package") elm_package(name, package_name, package_version, srcs, deps, visibility)
Purpose: make an off-the-shelf Elm package usable as a dependency.
package_name: The publicly used name of the package (e.g.,
package_version: The version of the package (e.g.,
srcs: Files that are part of this package. This list SHOULD include
deps: List of packages on which this package depends.
Note: This function is typically not used directly; it is often
sufficient to use
load("@com_github_edschouten_rules_elm//proto:def.bzl", "elm_proto_library") elm_proto_library(name, proto, visibility)
proto_library()that should be converted to Elm.
Note: This function is implemented using Bazel aspects,
meaning that it automatically instantiates build rules for all
transitive dependencies of the
proto_library() and sets up
dependencies between them accordingly.
load("@com_github_edschouten_rules_elm//elm:def.bzl", "elm_test") elm_test(name, main, deps, visibility)
main: The name of the source file containing one or more
deps: List of
elm_package()targets on which the testing application depends.
Repository rules provided by this project
load("@com_github_edschouten_rules_elm//repository:def.bzl", "elm_repository") elm_repository(name, urls, sha256, strip_prefix, patches)
Purpose: download an Elm package over HTTP, extract it and create a
BUILD.bazel file containing either an
used. For others,
elm_library() is used to prevent the Elm compiler
from returning hard to debug dependency management related errors.
urls: List of URLs where the package tarball may be downloaded.
sha256: SHA-256 checksum of the tarball.
strip_prefix: Directory prefix that may be removed from the files upon extraction.
patches: List of labels of patches to apply after extraction.
Examples on how to use these rules
The Bazel Elm SPA Example repository contains a concrete example of how these rules may be used to build a web application written in Elm. This repository contains a copy of a well-known demonstration application that has been adjusted to be buildable using Bazel.