Giter VIP home page Giter VIP logo

rules_scala's Introduction

Scala Rules for Bazel

Build Status

Overview

This rule is used for building Scala projects with Bazel. There are currently four rules, scala_library, scala_macro_library, scala_binary and scala_test.

Getting started

In order to use scala_library, scala_macro_library, and scala_binary, you must have bazel 0.2.3 and add the following to your WORKSPACE file:

git_repository(
    name = "io_bazel_rules_scala",
    remote = "https://github.com/bazelbuild/rules_scala.git",
    commit = "7b891adb975b4e3e6569b763d39ab6e9234196c9", # update this as needed
)
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
scala_repositories()

To use a particular tag, use the tagged number in tag = and omit the commit attribute. Note that these plugins are still evolving quickly, as is bazel, so you may need to select the version most appropriate for you.

Then in your BUILD file just add the following so the rules will be available:

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library", "scala_binary", "scala_test")

You may wish to have these rules loaded by default using bazel's prelude. You can add the above to the file tools/build_rules/prelude_bazel in your repo (don't forget to have a, possible empty, BUILD file there) and then it will be automatically prepended to every BUILD file in the workspace.

scala_library / scala_macro_library

scala_library(name, srcs, deps, runtime_deps, exports, data, main_class, resources, scalacopts, jvm_flags)
scala_macro_library(name, srcs, deps, runtime_deps, exports, data, main_class, resources, scalacopts, jvm_flags)

scala_library generates a .jar file from .scala source files. This rule also creates an interface jar to avoid recompiling downstream targets unless then interface changes.

scala_macro_library generates a .jar file from .scala source files when they contain macros. For macros, there are no interface jars because the macro code is executed at compile time. For best performance, you want very granular targets until such time as the zinc incremental compiler can be supported.

In order to make a java rule use this jar file, use the java_import rule.

Attributes
name

Name, required

A unique name for this target

srcs

List of labels, required

List of Scala .scala source files used to build the library

deps

List of labels, optional

List of other libraries to linked to this library target

runtime_deps

List of labels, optional

List of other libraries to put on the classpath only at runtime. This is rarely needed in Scala.

exports

List of labels, optional

List of targets to add to the dependencies of those that depend on this target. Similar to the `java_library` parameter of the same name. Use this sparingly as it weakens the precision of the build graph.

data

List of labels, optional

List of files needed by this rule at runtime.

main_class

String, optional

Name of class with main() method to use as an entry point

The value of this attribute is a class name, not a source file. The class must be available at runtime: it may be compiled by this rule (from srcs) or provided by direct or transitive dependencies (through deps). If the class is unavailable, the binary will fail at runtime; there is no build-time check.

resources

List of labels; optional

A list of data files to be included in the JAR.

scalacopts

List of strings; optional

Extra compiler options for this library to be passed to scalac. Subject to Make variable substitution and Bourne shell tokenization.

jvm_flags

List of strings; optional

List of JVM flags to be passed to scalac after the scalacopts. Subject to Make variable substitution and Bourne shell tokenization.

scala_binary

scala_binary(name, srcs, deps, runtime_deps, data, main_class, resources, scalacopts, jvm_flags)

scala_binary generates a Scala executable. It may depend on scala_library, scala_macro_library and java_library rules.

A scala_binary requires a main_class attribute.

Attributes
name

Name, required

A unique name for this target

srcs

List of labels, required

List of Scala .scala source files used to build the binary

deps

List of labels, optional

List of other libraries to linked to this binary target

runtime_deps

List of labels, optional

List of other libraries to put on the classpath only at runtime. This is rarely needed in Scala.

data

List of labels, optional

List of files needed by this rule at runtime.

main_class

String, required

Name of class with main() method to use as an entry point

The value of this attribute is a class name, not a source file. The class must be available at runtime: it may be compiled by this rule (from srcs) or provided by direct or transitive dependencies (through deps). If the class is unavailable, the binary will fail at runtime; there is no build-time check.

resources

List of labels; optional

A list of data files to be included in the JAR.

scalacopts

List of strings; optional

Extra compiler options for this binary to be passed to scalac. Subject to Make variable substitution and Bourne shell tokenization.

jvm_flags

List of strings; optional

List of JVM flags to be passed to scalac after the scalacopts. Subject to Make variable substitution and Bourne shell tokenization.

scala_test

scala_test(name, srcs, suites, deps, data, main_class, resources, scalacopts, jvm_flags)

scala_test generates a Scala executable which runs unit test suites written using the scalatest library. It may depend on scala_library, scala_macro_library and java_library rules.

A scala_test by default runs all tests in a given target. For backwards compatiblity it accepts a suites attribute which is ignored due to the ease with which that field is not correctly populated and tests are not run.

scala_repl

scala_repl(name, deps, scalacopts, jvm_flags)

A scala repl allows you to add library dependendencies (not currently scala_binary targets) to generate a script to run which starts a REPL. Since bazel run closes stdin, it cannot be used to start the REPL. Instead, you use bazel build to build the script, then run that script as normal to start a REPL session. An example in this repo:

bazel build test:HelloLibRepl
bazel-bin/test/HelloLibRepl

rules_scala's People

Contributors

ahumesky avatar colinmarc avatar damienmg avatar davidzchen avatar devnev avatar dinowernli avatar haxorz avatar ianoc avatar ianoc-stripe avatar improbable-dino avatar ittaiz avatar jacksullivan avatar jart avatar jcoveney avatar johnynek avatar kchodorow avatar laurentlb avatar oscar-stripe avatar rbraunstein avatar smparkes avatar valdemaras-wix avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.