Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

higherkindness/rules_scala

 
 

Repository files navigation

Bazel Scala Annex

Build Status

The Bazel Scala Annex is a prototyping area for bazelbuild/rules_scala focused on exploring design changes required to support big and challenging feature asks.

At this time there isn't a formal plan on how to incorporate changes upstream other than: we want to!

Feature list

  • Scala cross compilation
  • Zinc based backend
  • Bloop based backend
  • testing framework support (parity with SBT)
  • automatic main method detection
  • errors on unused dependencies
  • buildozer suggestions to fix unused dependency errors
  • IntelliJ support
  • tests for IntelliJ support
  • scalafmt support

rules_scala compatibility

  • scala_library (partial)
  • scala_macro_library (partial)
  • scala_binary (partial)
  • scala_import (partial)
  • scala_test
  • scala_test_suite
  • scala_library_suite
  • thrift_library
  • scalapb_proto_library

Usage

Don't.

Eventually (we hope) useful and proven functionality will wind up in bazelbuild/rules_scala. Use rules_scala.

Basic

WORKSPACE

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", "annex_scala_repositories")
annex_scala_repositories()

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

BUILD

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

annex_scala_libray(
  name = "example",
  src = glob(["**/*.scala"])
)

Tests

annex_scala_test supports

# Run tests
$ bazel test :mytest

# Run a single test
$ bazel test --test_filter=my.test.Example :mytest

# Run all tests with Java/Scala package prefix
$ bazel test --test_filter='my.test.*' :mytest

# Debug JVM on port 5005
$ bazel test --test_arg=--debug=5005 :mytest

# Limit heap space to 1GB
$ bazel test --test_arg=--jvm_arg='-Xmx 1G' :mytest

# Don't use ANSI color codes
$ bazel test --test_arg=--color=false

# Reduce logs
$ bazel test --test_arg=--verbosity=LOW

# Generate local script to run tests
$ bazel run --script_path=script :mytest

Scalafmt

Create .scalafmt.conf at the repo root (may be empty). And add to the WORKSPACE

load("@rules_scala_annex//rules/scalafmt:workspace.bzl", "scalafmt_default")
scalafmt_default()

And in BUILD

load("@rules_scala_annex//rules:scalafmt.bzl", "annex_scala_format_test")
annex_scala_format_test(
    name = "format",
    srcs = glob(["**/*.scala"]),
)
# format files
$ bazel run :format "$(bazel info | grep workspace: | cut -d' ' -f2)"
# check format
$ bazel test :format

Stateful compilation

Beyond the normal per-target incremental compilation, Zinc can achieve even finer-grained compilation by reusing dependency information collected on previous runs.

Stateful compilers like Zinc operate outside the Bazel paradigm, and Bazel cannot enforce correctness. Technically, this caveat applies to all worker strategies: performance is improving by maintaining state, but improper state may be shared across actions. In Zinc's case, the risk is higher, because the sharing is (intentionally) aggressive.

To enable Zinc's stateful compilation, add --worker_extra_flag=ScalaCompile=--persistent_dir=~/.cache/bazel-zinc.

Contributing

Buildifier

Buildifier is used to format Skylark files. To run it,

$ ./setup-tools.sh # first time
$ ./format.sh

Maven deps

Bazel-deps is used to generate maven deps. If you need to change dependencies, modify dependencies.yaml and

$ ./setup-tools.sh # first time
$ ./gen-deps.sh

Tests

$ # runs all tests
$ ./test.sh
$ # runs all tests in tests/dependencies/
$ ./test.sh tests/dependencies/

About

Robust and featureful Bazel rules for Scala

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 19