Skip to content

Commit

Permalink
Move the Play Routes Compiler CLI back into this repo and improve too…
Browse files Browse the repository at this point in the history
…lchains
  • Loading branch information
jjudd committed Sep 24, 2024
1 parent f83f9dc commit ea410a1
Show file tree
Hide file tree
Showing 39 changed files with 9,658 additions and 575 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,24 @@ jobs:
- run: ./test/run_all_tests.sh ci
- run: ./scripts/gen-docs.sh && git diff --exit-code docs/
- run: bazel shutdown

publish:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: build-and-test
runs-on: ubuntu-24.04
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
- uses: bazel-contrib/[email protected]
with:
bazelisk-version: 1.20.0
- run: cat .bazelrc.ci >> .bazelrc
- name: Import gpg keys
run: echo "$PGP_SECRET" | base64 --decode | gpg --import
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
- name: Publish to Maven
run: ./scripts/publish.sh
env:
MAVEN_USER: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
File renamed without changes.
1,520 changes: 1,520 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

83 changes: 44 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Simple Core API: [play_routes](docs/stardoc/play-routes.md)
For more information about the Play Framework, see [the Play documentation](https://www.playframework.com/documentation/latest).

## Installation
Create a file at the top of your repository named `WORKSPACE` and add the following snippet to it.
Add the following to your `WORKSPACE` file:

```python
# update version as needed
Expand Down Expand Up @@ -42,50 +42,38 @@ rules_jvm_external_deps()
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
rules_jvm_external_setup()

load("@rules_play_routes//:workspace.bzl", "play_routes_repositories")
play_routes_repositories("3.0")
load("@play_routes//:defs.bzl", play_routes_pinned_maven_install = "pinned_maven_install")
play_routes_pinned_maven_install()
play_routes_compiler_cli_3_repositories()
load("@play_routes_compiler_cli_3//:defs.bzl", play_routes_compiler_cli_3_pinned_maven_install = "pinned_maven_install")
play_routes_compiler_cli_3_pinned_maven_install()

bind(
name = "default-play-routes-compiler-cli",
actual = "@rules_play_routes//default-compiler-clis:scala_2_13_play_3_0"
)
play_routes_compiler_cli_2_13_repositories()
load("@play_routes_compiler_cli_2_13//:defs.bzl", play_routes_compiler_cli_2_13_pinned_maven_install = "pinned_maven_install")
play_routes_compiler_cli_2_13_pinned_maven_install()

# Play routes compiler
load("//play-routes-toolchain:register-toolchains.bzl", "play_routes_register_toolchains")
play_routes_register_toolchains(default_toolchain_name = "play-routes-3")
```

This installs `rules_play_routes` to your `WORKSPACE` and binds the default play routes compiler cli the rules will use. Update the commit as needed.

In the above example, the play routes compiler cli for Scala 2.12 and Play 2.7 is used. However, you can specify a different compiler.

We provide several default compilers:
This installs `rules_play_routes` to your `WORKSPACE` and sets up toolchains for a Scala 2.13 and Scala 3 version of the Play routes compiler with Scala 3 being the default. To change the default to Scala 2.13, set `default_toolchain_name = "play-routes-2-13"`

- For Scala 2.11 + Play 2.5: `@rules_play_routes//default-compiler-clis:scala_2_11_play_2_5`
- For Scala 2.11 + Play 2.6: `@rules_play_routes//default-compiler-clis:scala_2_11_play_2_6`
- For Scala 2.11 + Play 2.7: `@rules_play_routes//default-compiler-clis:scala_2_11_play_2_7`
- For Scala 2.12 + Play 2.6: `@rules_play_routes//default-compiler-clis:scala_2_12_play_2_6`
- For Scala 2.12 + Play 2.7: `@rules_play_routes//default-compiler-clis:scala_2_12_play_2_7`
- For Scala 2.12 + Play 2.8: `@rules_play_routes//default-compiler-clis:scala_2_12_play_2_8`
- For Scala 2.13 + Play 2.8: `@rules_play_routes//default-compiler-clis:scala_2_13_play_2_8`
- For Scala 2.13 + Play 2.9: `@rules_play_routes//default-compiler-clis:scala_2_13_play_2_9`
- For Scala 2.13 + Play 3.0: `@rules_play_routes//default-compiler-clis:scala_2_13_play_3_0`

To bind one of the default compilers, simply specify the correct Play version in the call to `play_routes_repositories` and update the bind statement:
If you want to use a custom Play routes Compiler, you can set up a custom toolchain in a BUILD.bazel file as follows:
```python
play_routes_repositories(<Play Version>, <Optional Scala Version, see below>)
load("@play_routes//:defs.bzl", play_routes_pinned_maven_install = "pinned_maven_install")
play_routes_pinned_maven_install()
load("@rules_play_routes//play-routes-toolchain:create-toolchain.bzl", "create_play_routes_toolchain")

bind(
name = "default-play-routes-compiler-cli",
actual = <Default Compiler Label>
create_play_routes_toolchain(
name = "play-routes-custom",
play_routes_compiler = "<label of your custom Play routes compiler>",
)
```

Note: play_routes_respositories by default only needs to know the Play version. By default, there's no special config
for the Scala version (just make sure you bind the right compiler label).

You can optionally include the Scala version, this might be needed for certain versions of Play.
Then change the `play_routes_register_toolchains` in the `WORKSPACE` file to use your custom toolchain:
```python
play_routes_register_toolchains(
default_toolchain_name = "play-routes-custom",
toolchains = ["<label of your custom Play routes compiler>"]
)
```

## Usage
The `play_routes` rule compiles Play routes files to a source jar that can be used with the `rules_scala` rules. For example,
Expand All @@ -110,6 +98,21 @@ scala_binary(
)
```

### Overriding the default Play routes compiler
To override the default Play routes compiler for a single target, you can change the `play_routes_toolchain_name` attribute on the `play_routes` target. That attribute can be set to the name of any `play_routes_toolchain` registered with `play_routes_register_toolchains` (and created using `create_play_routes_toolchain`). By default `play-routes-3` and `play-routes-2-13` are valid values.

For example:
```python
play_routes(
name = "play-routes",
srcs = ["conf/routes"] + glob(["conf/*.routes"]),
include_play_imports = True,
generate_reverse_router = True,
routes_imports = [...],
play_routes_toolchain_name = "play-routes-2-13",
)
```

See the [Stardoc documentation](docs/stardoc/play-routes.md) for the full list of options for `play_routes`.

### Use with the Play Framework
Expand Down Expand Up @@ -165,21 +168,23 @@ filegroup(
)
```

If you want to have webjars support (https://www.playframework.com/documentation/2.8.1/AssetsOverview#WebJars),
If you want to have webjars support (https://www.playframework.com/documentation/3.0.x/AssetsOverview#WebJars),
then check out https://github.com/gergelyfabian/rules_play_utils.

## Development
### Command Line Play Routes Compiler
This project consists of the Play routes Bazel rules and a command line Play routes compiler compiler. The command line compiler can be built with
This project consists of the Play routes Bazel rules and a command line Play routes compiler. The command line compiler can be built with
```bash
bazel build //play-routes-compiler
bazel build //play-routes-compiler-cli:play-routes-compiler-cli-3
```

It can be run with
```bash
bazel run //play-routes-compiler
bazel run //play-routes-compiler-cli:play-routes-compiler-cli-3
```

There is a 2.13 verison of the routes compiler: `//play-routes-compiler-cli:play-routes-compiler-cli-2-13`

### Testing
All tests can be run using

Expand Down
125 changes: 43 additions & 82 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ workspace(name = "rules_play_routes")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# rules_java
http_archive(
name = "rules_java",
sha256 = "41131de4417de70b9597e6ebd515168ed0ba843a325dc54a81b92d7af9a7b3ea",
sha256 = "6f3ce0e9fba979a844faba2d60467843fbf5191d8ca61fa3d2ea17655b56bb8c",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/7.9.0/rules_java-7.9.0.tar.gz",
"https://github.com/bazelbuild/rules_java/releases/download/7.11.1/rules_java-7.11.1.tar.gz",
],
)

Expand Down Expand Up @@ -37,27 +36,45 @@ load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
rules_jvm_external_setup()

# Set up 3rd party jvm dependencies
load("//:workspace.bzl", "play_routes_repositories")
load(
"//:workspace.bzl",
"play_routes_compiler_cli_2_13_repositories",
"play_routes_compiler_cli_3_repositories",
)

play_routes_compiler_cli_3_repositories()

load("@play_routes_compiler_cli_3//:defs.bzl", play_routes_compiler_cli_3_pinned_maven_install = "pinned_maven_install")

play_routes_compiler_cli_3_pinned_maven_install()

play_routes_repositories()
play_routes_compiler_cli_2_13_repositories()

load("@play_routes//:defs.bzl", play_routes_pinned_maven_install = "pinned_maven_install")
load("@play_routes_compiler_cli_2_13//:defs.bzl", play_routes_compiler_cli_2_13_pinned_maven_install = "pinned_maven_install")

play_routes_pinned_maven_install()
play_routes_compiler_cli_2_13_pinned_maven_install()

load("//:test_workspace.bzl", "play_routes_test_repositories")
load("//:test_workspace.bzl", "play_routes_test_2_13_repositories", "play_routes_test_3_repositories")

play_routes_test_repositories()
play_routes_test_3_repositories()

load("@play_routes_test//:defs.bzl", play_routes_test_pinned_maven_install = "pinned_maven_install")
load("@play_routes_test_3//:defs.bzl", play_routes_test_3_pinned_maven_install = "pinned_maven_install")

play_routes_test_pinned_maven_install()
play_routes_test_3_pinned_maven_install()

play_routes_test_2_13_repositories()

load("@play_routes_test_2_13//:defs.bzl", play_routes_test_2_13_pinned_maven_install = "pinned_maven_install")

play_routes_test_2_13_pinned_maven_install()

# Play routes compiler
register_toolchains("//play-routes:cross_platform_play_routes_toolchain")
load("//play-routes-toolchain:register-toolchains.bzl", "play_routes_register_toolchains")

play_routes_register_toolchains(default_toolchain_name = "play-routes-3")

# Skylib
skylib_version = "1.5.0" # update this as needed
skylib_version = "1.7.1" # update this as needed

http_archive(
name = "bazel_skylib",
Expand All @@ -74,10 +91,10 @@ bazel_skylib_workspace()
# Stardoc
http_archive(
name = "io_bazel_stardoc",
sha256 = "62bd2e60216b7a6fec3ac79341aa201e0956477e7c8f6ccc286f279ad1d96432",
sha256 = "fabb280f6c92a3b55eed89a918ca91e39fb733373c81e87a18ae9e33e75023ec",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.7.1/stardoc-0.7.1.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.7.1/stardoc-0.7.1.tar.gz",
],
)

Expand All @@ -96,33 +113,31 @@ stardoc_pinned_maven_install()
# com_github_bazelbuild_buildtools

# buildifier
buildtools_version = "4.2.2"
buildtools_version = "7.3.1"

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
sha256 = "051951c10ff8addeb4f10be3b0cf474b304b2ccd675f2cc7683cdd9010320ca9",
strip_prefix = "buildtools-{}".format(buildtools_version),
url = "https://github.com/bazelbuild/buildtools/archive/refs/tags/{}.tar.gz".format(buildtools_version),
url = "https://github.com/bazelbuild/buildtools/archive/refs/tags/v{}.tar.gz".format(buildtools_version),
)

# buildifier is written in Go and hence needs rules_go to be built.
# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
http_archive(
name = "io_bazel_rules_go",
sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996",
sha256 = "f4a9314518ca6acfa16cc4ab43b0b8ce1e4ea64b81c38d8a3772883f153346b8",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.50.1/rules_go-v0.50.1.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.50.1/rules_go-v0.50.1.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains")

go_register_toolchains(version = "1.20.3")
go_register_toolchains(version = "1.23.0")

# Also for buildifier. Comes from
# https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md
Expand Down Expand Up @@ -170,51 +185,12 @@ annex_pinned_maven_install()

scala_register_toolchains()

## delete all this when cli changes are published upstream

skylib_version = "1.4.1"

http_archive(
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
type = "tar.gz",
url = "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{}/bazel-skylib-{}.tar.gz".format(skylib_version, skylib_version),
)

graknlabs_bazel_distribution_version = "ebb4660cff37574876d37bf7c498bd735155554f"

http_archive(
name = "graknlabs_bazel_distribution",
sha256 = "c3181786d2544a7df54bcf326d5e40e6ec0b86dbc6c42e58d40f8c2c2225859f",
strip_prefix = "bazel-distribution-{}".format(graknlabs_bazel_distribution_version),
type = "zip",
url = "https://github.com/graknlabs/bazel-distribution/archive/{}.zip".format(graknlabs_bazel_distribution_version),
)

# Make COMPILER_CLI_ARTIFACT_ID available in BUILD files
env_vars_to_bzl_vars_version = "d67a600bb0917cd0e1c7a17ee78a3e2110fdbde2"

http_archive(
name = "env_vars_to_bzl_vars",
sha256 = "f0f7077a83590ff566c8ef17b74ca02728592f6f400eecb6d3ccef8997a9f41d",
strip_prefix = "env_vars_to_bzl_vars-{}".format(env_vars_to_bzl_vars_version),
type = "zip",
url = "https://github.com/SrodriguezO/env_vars_to_bzl_vars/archive/{}.zip".format(env_vars_to_bzl_vars_version),
)

load("@env_vars_to_bzl_vars//:env_vars_loader.bzl", "load_env_vars")

load_env_vars(
name = "env_vars",
env_vars = ["COMPILER_CLI_ARTIFACT_ID"],
)

# rules_pkg
rules_pkg_version = "0.10.1"
rules_pkg_version = "1.0.1"

http_archive(
name = "rules_pkg",
sha256 = "d250924a2ecc5176808fc4c25d5cf5e9e79e6346d79d5ab1c493e289e722d1d0",
sha256 = "d20c951960ed77cb7b341c2a59488534e494d5ad1d30c4818c736d57772a9fef",
urls = [
"https://github.com/bazelbuild/rules_pkg/releases/download/{0}/rules_pkg-{0}.tar.gz".format(rules_pkg_version),
],
Expand All @@ -223,18 +199,3 @@ http_archive(
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

# delete below

local_repository(
name = "play_routes_compiler_cli",
path = "/home/james/lucid/play_routes_compiler_cli",
)

load("@play_routes_compiler_cli//:workspace.bzl", "play_routes_compiler_cli_repositories")

play_routes_compiler_cli_repositories()

load("@play_routes_compiler_cli_maven//:defs.bzl", play_routes_compiler_cli_pinned_maven_install = "pinned_maven_install")

play_routes_compiler_cli_pinned_maven_install()
Loading

0 comments on commit ea410a1

Please sign in to comment.