Skip to content

stephenjudkins/rules_scala

 
 

Repository files navigation

Bazel Scala Annex

Build Status

Principles

  1. Support the breadth of the Scala ecosystem.
  2. Follow Bazel best practices.
  3. Be accessible and maintainable.
  4. Have high-quality documentation.

If the right design principles are kept, implementing additional features should be simple and straightforward.

Features

  • Basic library and binary rules
  • Single deploy jar
  • Works with all sbt-compatible test frameworks
  • Multiple Scala versions in one build
  • Macros
  • ijars
  • REPL
  • Automatic main method detection
  • Errors on indirect and unused dependencies
  • Buildozer suggestions for dependency erors
  • Scalafmt
  • ScalaPB
  • Worker strategy
  • Optional Zinc-based stateful incremental compilation
  • IntelliJ Bazel plugin integration

Differences with rules_scala

  • More correctly handles of macros and ijars. See #445 and #632.
    • Detect missing macro = True attribute. See #366.
  • More precisely and straightforwardly detects indirect and unused dependencies, via Zinc. See #235 and #335.
  • Supports neverlink. See #213.
  • Optionally allows for fine-grained incrementality with stateful Zinc compilation. See bazel-discuss and #328.
  • Does not support intransitive classpaths, matching Java rules. See #432.
  • Tools written in Scala, using bootstrapping rules as necessary.
  • Uses depset and Args to completely defer expanding transitive dependency lists until execution time.
  • Supports many Scala versions: 2.10-2.13, Typelevel, Dotty, and anything else compatible with Zinc's compiler-bridge.
  • Allows for multiple Scala versions in the same workspace. See #80 and #393.
    • For example, rules_scala_annex tools use Scala 2.12, but that doesn't affect any client projects.
  • Robustly supports buildozer recommendations via an aspect.
  • Supports for all Scala test frameworks via sbt test-interface.
  • Support test sharding, custom test framework arguments (including options to the JVM itself).
  • Supports optional classloader and process-level isolation for tests, similar to sbt's fork := true.
  • Supports scalafmt.
  • Supports Scaladoc. See #230 and #256.
  • Has consistently formatted code, via buildifier and scalafmt. See #74.
  • Reorganized and simplified file and code structure. Less than 8 KLOC excluding tests and dependency resolutions. (git ls-files | grep -v '^test\|/maven.bzl$\|*.md' | xargs cat | wc -l)
  • Reorganized Travis CI builds, including better cache reuse.
  • Easy dependency managment of internal tools using bazel-deps.
  • Tested against three most recent Bazel versions.

Usage

Note: the rules are undergoing refactoring and the following configuration is only valid up to commit 6829904caaac3160636a7e30acd8bd500357e742. Expect updated documentation soon.

WORKSPACE

http_archive(
    name = "bazel_skylib",
    sha256 = "c0289fef5237c31e8462042b4cc3bdf831a3d3d135bb4a0d493a5072acecb074",
    strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
    urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.zip"],
)

http_archive(
    name = "com_google_protobuf",
    sha256 = "2c8f8614fb1be709d68abaab6b4791682aa7db2048012dd4642d3a50b4f67cb3",
    strip_prefix = "protobuf-0038ff49af882463c2af9049356eed7df45c3e8e",
    urls = ["https://github.com/google/protobuf/archive/0038ff49af882463c2af9049356eed7df45c3e8e.zip"],
)

http_archive(
  name = "rules_scala_annex",
  sha256 = "<hash>",
  strip_prefix = "rules_scala_annex-<commit>",
  url = "https://github.com/andyscott/rules_scala_annex/archive/<commit>.zip",
)

load("@rules_scala_annex//rules/scala:workspace.bzl", "scala_register_toolchains", "scala_repository", "scala_repositories")

scala_repositories()
scala_register_toolchains()

# Add a @scala repo, which is the default scala provider used by scala_*
scala_repository("scala", ("org.scala-lang", "2.12.4"), "@compiler_bridge_2_12//:src")

BUILD

load("@rules_scala_annex//rules:scala.bzl", "scala_library")

scala_library(
  name = "example",
  srcs = glob(["**/*.scala"])
)

Further Documentation

See contributing guidlines for help on contributing to this project.

For all rules and attributes, see the Stardoc.

About

Robust and featureful Bazel rules for Scala

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 56.6%
  • Scala 35.2%
  • Shell 8.1%
  • Java 0.1%