Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
seemingly functional ide

+configs

sane readme

+bsd3c

drop spurious artifacts

bump

bump

+ammonite support

+ cleanups and docs and better examples
  • Loading branch information
itdaniher committed Nov 4, 2020
0 parents commit 305d2fc
Show file tree
Hide file tree
Showing 37 changed files with 856 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tools/idea-IC-202.7660.26
tools/intellij-bazel
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build -s --sandbox_debug --verbose_failures
run -s --sandbox_debug --verbose_failures
build --strategy=Scalac=worker
build --worker_sandboxing
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.1
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tools/intellij-bazel
idea-IC-202.7660.26
ideaIC-2020.2.3.tar.gz
3rdparty
bazel-*
tools/bazelisk*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "intellij-bazel"]
path = tools/intellij-bazel
url = https://github.com/bazelbuild/intellij.git
20 changes: 20 additions & 0 deletions .ijwb/.bazelproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
directories:
# Add the directories you want added as source here
# By default, we've added your entire workspace ('.')
.

# Automatically includes all relevant targets under the 'directories' above
derive_targets_from_directories: true

targets:
# If source code isn't resolving, add additional targets that compile it here
//src:main-bin
//src:main-docker

additional_languages:
# Uncomment any additional languages you want supported
# android
# dart
# kotlin
# python
scala
12 changes: 12 additions & 0 deletions .ijwb/.blaze/modules/.project-data-dir.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.id="Blaze" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<exclude-output />
<content url="file://$MODULE_DIR$/../..">
<excludeFolder url="file://$MODULE_DIR$/.." />
<excludeFolder url="file://$MODULE_DIR$/../../.idea" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
21 changes: 21 additions & 0 deletions .ijwb/.blaze/modules/.workspace.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.id="Blaze" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<exclude-output />
<content url="file://$MODULE_DIR$/../../..">
<sourceFolder url="file://$MODULE_DIR$/../../.." isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/../.." />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-bin" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-genfiles" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-out" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-testlogs" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-urep-scala" />
<excludeFolder url="file://$APPLICATION_HOME_DIR$" />
<excludeFolder url="file://$MODULE_DIR$/../../../tools/intellij-bazel" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="scala-library-2.12.8_1798c1ef" level="project" />
<orderEntry type="library" name="scala-reflect-2.12.8_4e6073f1" level="project" />
</component>
</module>
3 changes: 3 additions & 0 deletions .ijwb/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .ijwb/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .ijwb/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .ijwb/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .ijwb/.idea/libraries/scala_library_2_12_8_1798c1ef.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .ijwb/.idea/libraries/scala_reflect_2_12_8_4e6073f1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .ijwb/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .ijwb/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .ijwb/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .ijwb/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .ijwb/Bazel_build_src_main_bin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<configuration name="Bazel build src:main-bin" type="BlazeCommandRunConfigurationType" factoryName="Bazel Command" nameIsGenerated="true"><blaze-settings kind="scala_binary" handler-id="BlazeJavaRunConfigurationHandlerProvider" blaze-command="build"><blaze-target>//src:main-bin</blaze-target></blaze-settings><method v="2"><option name="Blaze.BeforeRunTask" enabled="true" /></method></configuration>
1 change: 1 addition & 0 deletions .ijwb/Bazel_run_src_main_bin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<configuration name="Bazel run src:main-bin" type="BlazeCommandRunConfigurationType" factoryName="Bazel Command"><blaze-settings handler-id="BlazeJavaRunConfigurationHandlerProvider" blaze-command="run" kind="scala_binary"><blaze-target>//src:main-bin</blaze-target></blaze-settings><method v="2"><option name="Blaze.BeforeRunTask" enabled="true" /></method></configuration>
13 changes: 13 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
align.openParenCallSite = false
align.openParenDefnSite = false
continuationIndent.defnSite = 2
docstrings = JavaDoc
importSelectors = singleLine
maxColumn = 120
rewrite.redundantBraces.stringInterpolation = true
rewrite.rules = [
RedundantParens,
PreferCurlyFors,
SortImports
]
unindentTopLevelOperators = false
22 changes: 22 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package(
default_visibility = ["//visibility:public"],
)

scala_binary(
name = "amm",
srcs = [],
deps = ["@third_party//3rdparty/jvm/com/lihaoyi:ammonite_2_12_8", "//src:mylib"],
main_class = "ammonite.Main"
)


# this is the base docker image used for all scala_image targets
# adoptopenjdk is great, but their images do not have the `java` executable at the path expected by rules_docker

container_image(
name = "custom_java_base",
base = "@openjdk-base//image",
symlinks = {"/usr/bin/java": "/opt/java/openjdk/bin/java"},
visibility = ["//visibility:public"],
)

29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2020, itdaniher
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
## Bazel infrastructure for Scala


### What's included?

- functioning, up-to-date, intellij support!
- [bazel-deps](https://github.com/johnynek/bazel-deps) for managing dependencies via dependencies.yaml.
- [rules_scala](https://github.com/bazelbuild/rules_scala) for compiling and formatting, via scalafmt
- [rules_docker](https://github.com/bazelbuild/rules_docker) for packaging and isolated deployment
- [ammonite](http://ammonite.io/) 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](https://github.com/bazelbuild/bazelisk) from [here](https://github.com/bazelbuild/bazelisk/releases/download/v1.7.4/bazelisk-linux-amd64)
* 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/`

```bash

#!/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 :)
Loading

0 comments on commit 305d2fc

Please sign in to comment.