Skip to content

Commit

Permalink
Rework examples to auto build repository.
Browse files Browse the repository at this point in the history
Signed-off-by: restingbull@cabaretmechanique.com <restingbull@cabaretmechanique.com>
  • Loading branch information
restingbull committed Jul 29, 2021
1 parent 54045ba commit 9326d32
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 163 deletions.
24 changes: 6 additions & 18 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,40 @@ tasks:
name: "Example - Android"
platform: ubuntu1804
shell_commands:
- "cd ../.. && bazel build //:rules_kotlin_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release.tgz"
- "export RULES_KOTLIN_WORKSPACE_PATH=$(realpath ../..)"
working_directory: examples/android
test_flags:
- "--override_repository=io_bazel_rules_kotlin=/tmp/rules_kotlin_release"
test_targets:
- //...
example-associates:
name: "Example - Associates"
platform: ubuntu1804
shell_commands:
- "cd ../.. && bazel build //:rules_kotlin_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release.tgz && cat /tmp/rules_kotlin_release/kotlin/internal/opts.bzl"
- "export RULES_KOTLIN_WORKSPACE_PATH=$(realpath ../..)"
working_directory: examples/associates
test_flags:
- "--override_repository=io_bazel_rules_kotlin=/tmp/rules_kotlin_release"
test_targets:
- //...
example-anvil:
name: "Example - Anvil"
platform: ubuntu1804
shell_commands:
- "cd ../.. && bazel build //:rules_kotlin_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release.tgz && cat /tmp/rules_kotlin_release/kotlin/internal/opts.bzl"
- "export RULES_KOTLIN_WORKSPACE_PATH=$(realpath ../..)"
working_directory: examples/anvil
#test_flags:
# - "--override_repository=io_bazel_rules_kotlin=/tmp/rules_kotlin_release"
test_targets:
- //...
example-plugins:
name: "Example - Plugins"
platform: ubuntu1804
shell_commands:
- "cd ../.. && bazel build //:rules_kotlin_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release.tgz && grep -R rkt_1_4 /tmp/rules_kotlin_release"
- "export RULES_KOTLIN_WORKSPACE_PATH=$(realpath ../..)"
working_directory: examples/plugin
test_flags:
- "--override_repository=io_bazel_rules_kotlin=/tmp/rules_kotlin_release"
test_targets:
- //...
examples-trivial:
name: "Example - Trivial"
platform: ubuntu1804
shell_commands:
- "cd ../.. && bazel build //:rules_kotlin_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release.tgz"
- "export RULES_KOTLIN_WORKSPACE_PATH=$(realpath ../..)"
working_directory: examples/trivial
test_flags:
- "--override_repository=io_bazel_rules_kotlin=/tmp/rules_kotlin_release"
include_json_profile:
- build
- test
Expand All @@ -84,13 +74,11 @@ tasks:
name: Example - Node
platform: ubuntu1804
shell_commands:
- "cd ../.. && bazel build //:rules_kotlin_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release.tgz"
- "export RULES_KOTLIN_WORKSPACE_PATH=$(realpath ../..)"
working_directory: examples/node
include_json_profile:
- build
- test
test_flags:
- "--override_repository=io_bazel_rules_kotlin=/tmp/rules_kotlin_release"
build_targets:
- //coroutines-helloworld/...
- //express/...
Expand Down
12 changes: 2 additions & 10 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
# Some examples have their own WORKSPACE. Ignore as part of this root WORKSPACE so
# we don't break trying to build separate workspaces using wildcards like //...
# examples/dagger doesn't have its own workspace, so don't do all of examples.
examples/android
examples/associates
examples/jetpack_compose
examples/node
examples/trivial
examples/anvil
examples/multiplex
# Exclude examples from //...:all
examples/*
4 changes: 2 additions & 2 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ Define the Kotlin toolchain.
| experimental_report_unused_deps | <p align="center"> - </p> | <code>None</code> |
| experimental_reduce_classpath_mode | <p align="center"> - </p> | <code>None</code> |
| experimental_multiplex_workers | <p align="center"> - </p> | <code>None</code> |
| javac_options | <p align="center"> - </p> | <code>None</code> |
| kotlinc_options | <p align="center"> - </p> | <code>None</code> |
| javac_options | <p align="center"> - </p> | <code>Label("//kotlin/internal:default_javac_options")</code> |
| kotlinc_options | <p align="center"> - </p> | <code>Label("//kotlin/internal:default_kotlinc_options")</code> |
| jacocorunner | <p align="center"> - </p> | <code>None</code> |


Expand Down
21 changes: 14 additions & 7 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
workspace(name = "android_example")

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

# Directly load the kotlin rules from the parent repo.
local_repository(
name = "io_bazel_rules_kotlin",
path = "../..",
name = "release_archive",
path = "../release_archive",
)

load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
load("@release_archive//:repository.bzl", "archive_repository")

kt_download_local_dev_dependencies()
archive_repository(
name = "io_bazel_rules_kotlin",
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions")

kotlin_repositories()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()

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

http_archive(
name = "bazel_skylib",
sha256 = versions.SKYLIB_SHA,
Expand Down
40 changes: 15 additions & 25 deletions examples/anvil/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "build_bazel_rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
strip_prefix = "rules_android-0.1.1",
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
local_repository(
name = "release_archive",
path = "../release_archive",
)

# Directly load the kotlin rules from the parent repo.
rules_kotlin_version = "1.5.0-beta-3"

rules_kotlin_sha = "d8650bb939d87a080448ffbbbd1594f5ae054738df5d9471941c18784aa139b9"
load("@release_archive//:repository.bzl", "archive_repository")

http_archive(
archive_repository(
name = "io_bazel_rules_kotlin",
sha256 = rules_kotlin_sha,
strip_prefix = "rules_kotlin-%s" % rules_kotlin_version,
type = "zip",
urls = ["https://github.com/bazelbuild/rules_kotlin/archive/v%s.zip" % rules_kotlin_version],
)

print("loading repositories")

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions")

print("setting up repositories")

kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below

print("loading core")
kotlin_repositories()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

print("registering toolchians")
kt_register_toolchains()

kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "build_bazel_rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
strip_prefix = "rules_android-0.1.1",
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
)

load(
"@build_bazel_rules_android//android:rules.bzl",
Expand Down
45 changes: 23 additions & 22 deletions examples/associates/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
local_repository(
name = "release_archive",
path = "../release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")

SKYLIB_VERSION = "1.0.3"
archive_repository(
name = "io_bazel_rules_kotlin",
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions")

SKYLIB_SHA = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c"
kotlin_repositories()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()

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

http_archive(
name = "rules_android",
Expand All @@ -20,27 +35,13 @@ http_archive(

http_archive(
name = "bazel_skylib",
sha256 = SKYLIB_SHA,
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (SKYLIB_VERSION, SKYLIB_VERSION)],
sha256 = versions.SKYLIB_SHA,
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (
versions.SKYLIB_VERSION,
versions.SKYLIB_VERSION,
)],
)

local_repository(
name = "io_bazel_rules_kotlin",
path = "../..",
)

load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")

kt_download_local_dev_dependencies()

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions")

kotlin_repositories()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()

http_archive(
name = "rules_jvm_external",
sha256 = versions.RULES_JVM_EXTERNAL_SHA,
Expand Down
4 changes: 2 additions & 2 deletions examples/dagger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_java//java:defs.bzl", "java_binary")
load("//kotlin:jvm.bzl", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

package(default_visibility = ["//visibility:private"])

Expand Down Expand Up @@ -58,7 +58,7 @@ kt_jvm_library(
],
deps = [
"//third_party:dagger",
"@kotlin_rules_maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core",
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core",
],
)

Expand Down
42 changes: 42 additions & 0 deletions examples/dagger/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local_repository(
name = "release_archive",
path = "../release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")

archive_repository(
name = "io_bazel_rules_kotlin",
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions")

kotlin_repositories()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()

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

http_archive(
name = "rules_jvm_external",
sha256 = versions.RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
artifacts = [
"com.google.dagger:dagger:2.35.1",
"com.google.dagger:dagger-compiler:2.35.1",
"com.google.dagger:dagger-producers:2.35.1",
"javax.inject:javax.inject:1",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2",
],
repositories = [
"https://repo1.maven.org/maven2",
],
)
21 changes: 21 additions & 0 deletions examples/dagger/third_party/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@rules_java//java:defs.bzl", "java_library", "java_plugin")

java_plugin(
name = "dagger_component_plugin",
generates_api = True,
processor_class = "dagger.internal.codegen.ComponentProcessor",
visibility = ["//visibility:private"],
deps = [
"@maven//:com_google_dagger_dagger_compiler",
],
)

java_library(
name = "dagger",
exported_plugins = [":dagger_component_plugin"],
visibility = ["//visibility:public"],
exports = [
"@maven//:com_google_dagger_dagger",
"@maven//:javax_inject_javax_inject",
],
)
34 changes: 17 additions & 17 deletions examples/jetpack_compose/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
local_repository(
name = "release_archive",
path = "../release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")

archive_repository(
name = "io_bazel_rules_kotlin",
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")

kotlin_repositories()

register_toolchains("//:kotlin_toolchain")

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

_KOTLIN_COMPILER_VERSION = "1.4.21"
Expand Down Expand Up @@ -127,20 +144,3 @@ android_sdk_repository(
name = "androidsdk",
api_level = 29,
)

## Kotlin

local_repository(
name = "io_bazel_rules_kotlin",
path = "../..",
)

load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")

kt_download_local_dev_dependencies()

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")

kotlin_repositories()

register_toolchains("//:kotlin_toolchain")
10 changes: 6 additions & 4 deletions examples/multiplex/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
workspace(name = "multiplex")

local_repository(
name = "io_bazel_rules_kotlin",
path = "../..",
name = "release_archive",
path = "../release_archive",
)

load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
load("@release_archive//:repository.bzl", "archive_repository")

kt_download_local_dev_dependencies()
archive_repository(
name = "io_bazel_rules_kotlin",
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")

Expand Down
Loading

0 comments on commit 9326d32

Please sign in to comment.