Coder Social home page Coder Social logo

radixbio / urep-scala Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 2.0 70 KB

get started with Scala and Bazel!

License: BSD 3-Clause "New" or "Revised" License

Starlark 72.37% Shell 24.45% Scala 3.18%
bazel bazel-examples scala bazel-rules bazel-deps

urep-scala's Introduction

Bazel infrastructure for Scala

Scala's usually built with SBT, and this is not great.

Bazel, a build tool from Google, is the worst build system, except for all the others.

This repository contains all the infrastructure and examples required to allow you to build Scala code and its dependencies in Bazel.

What's included?

  • functioning, up-to-date, intellij support!
  • bazel-deps for managing dependencies via dependencies.yaml.
  • rules_scala for compiling and formatting, via scalafmt
  • rules_docker for packaging and isolated deployment
  • ammonite as a powerful REPL for working with your libraries

bonus compatible versioning for...

akka, scalaz, circe, logstage

getting started on the CLI

Ubuntu 20.04, amd64 - confirmed to work. Everything else may require some tweaks.

  • clone this repo
  • git submodule init && git submodule update - to grab the intellij bazel plugin for IDE support
  • ./scripts/update_bazel_deps.sh - grab dependencies
  • download bazelisk from here
  • rename as bazel and mark executable, place somewhere in your $PATH
  • hello, world!

hello world, and hello world in docker

SPX:~/urep-scala $ bazel run //src:main-bin
INFO: Analyzed target //src:main-bin (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //src:main-bin up-to-date:
  bazel-bin/src/main-bin.jar
INFO: Elapsed time: 0.195s, Critical Path: 0.01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Hello world!
I am running on 11.0.9+11-Ubuntu-0ubuntu1.20.04
this is a string in a library.

SPX:~/urep-scala $ bazel run //src:main-docker
INFO: Analyzed target //src:main-docker (47 packages loaded, 6463 targets configured).
INFO: Found 1 target...
Target //src:main-docker up-to-date:
  bazel-bin/src/main-docker-layer.tar
INFO: Elapsed time: 2.457s, Critical Path: 0.68s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Loaded image ID: sha256:ad196f426e5adf796470e6d861526f7de92ab2821e67087cb6a7eda671ad4146
Tagging ad196f426e5adf796470e6d861526f7de92ab2821e67087cb6a7eda671ad4146 as bazel/src:main-docker
Hello world!
I am running on 11.0.8+10
this is a string in a library.

hello world, with Ammonite

bazel run //:amm

SPX:~/urep-scala $ bazel run //:amm
INFO: Analyzed target //:amm (1 packages loaded, 4 targets configured).
INFO: Found 1 target...
Target //:amm up-to-date:
  bazel-bin/amm.jar
INFO: Elapsed time: 0.092s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Loading...
Welcome to the Ammonite Repl 2.2.0 (Scala 2.12.8 Java 11.0.9)
@ import com.urepscala.mylib._
import com.urepscala.mylib._

@ println(com.urepscala.mylib.MyLib.myString)
this is a string in a library.

@ com.urepscala.mylib.MyLib.helloWorld
hello, world!

@ Bye!

format your code with scalafmt and bazel!

SPX:~/urep-scala $ bazel run //src:main-bin.format
INFO: Analyzed target //src:main-bin.format (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //src:main-bin [action 'ScalaFmt src/src/main/Main.scala.fmt.output', configuration: 45d0b89373a0dfd75ac4b432cf2b12138c1203b34bdec57557dfef52e7a6ed03]
(cd /home/name/.cache/bazel/_bazel_name/0f392d4f227f7735cc2ffb1555d4a4e9/execroot/__main__ && \
  exec env - \
  bazel-out/host/bin/external/io_bazel_rules_scala/scala/scalafmt/scalafmt '--jvm_flag=-Dfile.encoding=UTF-8' @bazel-out/k8-fastbuild/bin/src/src/main/Main.scala.fmt.output-0.params)
Target //src:main-bin.format up-to-date:
  bazel-bin/src/main-bin.format
INFO: Elapsed time: 0.192s, Critical Path: 0.06s
INFO: 1 process: 1 worker.
INFO: Build completed successfully, 2 total actions
INFO: Build completed successfully, 2 total actions

build plugin for intellij:

The checksum for a dependency in the intellij plugin is presently incorrect, for whatever slightly unsettling reason.

Patch in the expected checksum and build the intellij plugin zip by running the below as "build.sh" in tools/intellij-bazel/

#!/bin/bash

JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

git checkout 1b66ac89e13513243f910c9cf950d99872ce8d5b

sed -ie 's/fa9524db2f5b6e42be559ffdab73a963ca06ca057e27a290f5665d38e581764a/61eb876781f3fd75f2d9e76cac192672a02e008725ad9d7ac0fbd4e3dcf25b16/' WORKSPACE

bazel build //ijwb:ijwb_bazel_zip --define=ij_product=intellij-2020.2 --sandbox_debug --verbose_failures

cp bazel-bin/ijwb/ijwb_bazel.zip .

echo 4b4d9d6e52aa559e79f7b0a9fbfcdbcece3e91a8add7d7c0eed51b3cad8dde23  ijwb_bazel.zip | sha256sum -c -

echo 'WORKSPACE' >> .gitignore

TODO: add this as a bazel rule :)

the rest of the owl

  • grab intellij community edition:

wget https://download.jetbrains.com/idea/ideaIC-2020.2.3.tar.gz

install the plugin (built?) and settings (from releases), cross your fingers

TODO: add these steps as a bazel rule :)

urep-scala's People

Contributors

itdaniher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

urep-scala's Issues

failed on macos

Hi there - it failed after brew install bazelisk and then installing the dependencies on the bazel run //src:main-bin:

ERROR: /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/external/bazel_tools/tools/jdk/BUILD:346:14: Action external/bazel_tools/tools/jdk/platformclasspath.jar failed (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/186/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/18/_tk6h6yj0hl72t43k_jrnsgw0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/186/sandbox.sb /var/tmp/_bazel_coliny/install/e74efe234cbfbe8b17b6baeb8c33e7ff/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos/lib/tools.jar DumpPlatformClassPath bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk) sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/186/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/18/_tk6h6yj0hl72t43k_jrnsgw0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/186/sandbox.sb /var/tmp/_bazel_coliny/install/e74efe234cbfbe8b17b6baeb8c33e7ff/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos/lib/tools.jar DumpPlatformClassPath bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Locations.java:1853)
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
	at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
	at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
	at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
	at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
	at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
	at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Target //src:main-bin failed to build
INFO: Elapsed time: 69.539s, Critical Path: 24.48s
INFO: 185 processes: 185 darwin-sandbox.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

Subsequent runs:

โžœ  urep-scala git:(main) bazel run //src:main-bin
DEBUG: Rule 'rules_pkg' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1596141723 -0400"
DEBUG: Repository rules_pkg instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
INFO: Analyzed target //src:main-bin (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # @bazel_tools//tools/jdk:platformclasspath [action 'Action external/bazel_tools/tools/jdk/platformclasspath.jar', configuration: 12c9f5b38ca9023465976bb4b98a011d02814ec73529bdcfee2e76a895d9598f]
(cd /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/execroot/__main__ && \
  exec env - \
  external/remotejdk11_macos/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos/lib/tools.jar DumpPlatformClassPath bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
ERROR: /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/external/bazel_tools/tools/jdk/BUILD:346:14: Action external/bazel_tools/tools/jdk/platformclasspath.jar failed (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/18/_tk6h6yj0hl72t43k_jrnsgw0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/sandbox.sb /var/tmp/_bazel_coliny/install/e74efe234cbfbe8b17b6baeb8c33e7ff/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos/lib/tools.jar DumpPlatformClassPath bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk) sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/18/_tk6h6yj0hl72t43k_jrnsgw0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/sandbox.sb /var/tmp/_bazel_coliny/install/e74efe234cbfbe8b17b6baeb8c33e7ff/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos/lib/tools.jar DumpPlatformClassPath bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Locations.java:1853)
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
	at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
	at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
	at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
	at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
	at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
	at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Target //src:main-bin failed to build
ERROR: /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/external/io_bazel_rules_scala/src/java/io/bazel/rulesscala/scalac/BUILD:3:12 Action external/bazel_tools/tools/jdk/platformclasspath.jar failed (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/18/_tk6h6yj0hl72t43k_jrnsgw0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/sandbox.sb /var/tmp/_bazel_coliny/install/e74efe234cbfbe8b17b6baeb8c33e7ff/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos/lib/tools.jar DumpPlatformClassPath bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk) sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/18/_tk6h6yj0hl72t43k_jrnsgw0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_coliny/a83db79adaf47a3cde98435555f04b76/sandbox/darwin-sandbox/189/sandbox.sb /var/tmp/_bazel_coliny/install/e74efe234cbfbe8b17b6baeb8c33e7ff/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos/lib/tools.jar DumpPlatformClassPath bazel-out/darwin-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
INFO: Elapsed time: 0.393s, Critical Path: 0.22s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

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.