Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove third_party checked in jars, and properly pull maven dependencies. #279

Merged
merged 7 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,33 @@ _(e.g. Maven artifacts)_

Third party (external) artifacts can be brought in with systems such as [`rules_jvm_external`](https://github.com/bazelbuild/rules_jvm_external) or [`bazel_maven_repository`](https://github.com/square/bazel_maven_repository) or [`bazel-deps`](https://github.com/johnynek/bazel-deps), but make sure the version you use doesn't naively use `java_import`, as this will cause bazel to make an interface-only (`ijar`), or ABI jar, and the native `ijar` tool does not know about kotlin metadata with respect to inlined functions, and will remove method bodies inappropriately. Recent versions of `rules_jvm_external` and `bazel_maven_repository` are known to work with Kotlin.


# Development Setup Guide
To use the rules directly from git, an additional dependency downloads are required.
restingbull marked this conversation as resolved.
Show resolved Hide resolved

In the project's `WORKSPACE`, change the setup:
```python
load("//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
kt_download_local_dev_dependencies()


cgruber marked this conversation as resolved.
Show resolved Hide resolved

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

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below
```


## Examples

Examples can be found in the [examples directory](https://github.com/bazelbuild/rules_kotlin/tree/master/examples), including usage with Android, Dagger, Node-JS, etc.
Expand Down
122 changes: 8 additions & 114 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,126 +13,20 @@
# limitations under the License.
workspace(name = "io_bazel_rules_kotlin")

RULES_NODEJS_VERSION = "0.36.1"
RULES_NODEJS_SHA = "3356c6b767403392bab018ce91625f6d15ff8f11c6d772dc84bc9cada01c669a"

BAZEL_TOOLCHAINS_VERSION = "be10bee3010494721f08a0fccd7f57411a1e773e"
BAZEL_TOOLCHAINS_SHA = "5962fe677a43226c409316fcb321d668fc4b7fa97cb1f9ef45e7dc2676097b26"
load("//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
kt_download_local_dev_dependencies()

SKYLIB_VERSION = "0.8.0"
SKYLIB_SHA = "2ea8a5ed2b448baf4a6855d3ce049c4c452a6470b1efd1504fdb7c1c134d220a"

PROTOBUF_GIT_COMMIT = "09745575a923640154bcf307fba8aedff47f240a" # v3.8.0, as of 2019-05-28
PROTOBUF_SHA = "76ee4ba47dec6146872b6cd051ae5bd12897ef0b1523d5aeb56d81a5a4ca885a"

BAZEL_DEPS_VERSION = "0.1.0"
BAZEL_DEPS_SHA = "05498224710808be9687f5b9a906d11dd29ad592020246d4cd1a26eeaed0735e"


local_repository(
name = "node_example",
path = "examples/node",
)

load("//kotlin/internal/repositories:repositories.bzl", "github_archive")

github_archive(
name = "com_google_protobuf",
commit = PROTOBUF_GIT_COMMIT,
repo = "google/protobuf",
sha256 = PROTOBUF_SHA,
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

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

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

http_jar(
name = "bazel_deps",
sha256 = BAZEL_DEPS_SHA,
url = "https://github.com/hsyed/bazel-deps/releases/download/v%s/parseproject_deploy.jar" % BAZEL_DEPS_VERSION,
)

http_archive(
name = "bazel_toolchains",
sha256 = BAZEL_TOOLCHAINS_SHA,
strip_prefix = "bazel-toolchains-%s" % BAZEL_TOOLCHAINS_VERSION,
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/%s.tar.gz" % BAZEL_TOOLCHAINS_VERSION,
"https://github.com/bazelbuild/bazel-toolchains/archive/%s.tar.gz" % BAZEL_TOOLCHAINS_VERSION,
],
)

load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
load("//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories()
kt_register_toolchains()

# Creates toolchain configuration for remote execution with BuildKite CI
# for rbe_ubuntu1604
load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
rbe_autoconfig(
name = "buildkite_config",
)

load(
"//third_party/jvm:workspace.bzl", "maven_dependencies",
)

maven_dependencies()
load("//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

kotlin_repositories()

kt_register_toolchains()

# The following are to support building and running nodejs examples from src/test

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = RULES_NODEJS_SHA,
url = "https://github.com/bazelbuild/rules_nodejs/releases/download/{0}/rules_nodejs-{0}.tar.gz".format(RULES_NODEJS_VERSION),
)

load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")

yarn_install(
name = "node_ws",
package_json = "@node_example//:package.json",
yarn_lock = "@node_example//:yarn.lock",
)

RULES_JVM_EXTERNAL_TAG = "2.7"

RULES_JVM_EXTERNAL_SHA = "f04b1466a00a2845106801e0c5cec96841f49ea4e7d1df88dc8e4bf31523df74"

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

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

maven_install(
artifacts = [
"org.jetbrains.kotlinx:atomicfu-js:0.13.1",
"org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.2",
],
repositories = [
"https://maven-central.storage.googleapis.com/repos/central/data/",
"https://repo1.maven.org/maven2",
],
)

http_archive(
name = "rules_pkg",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
)
android_sdk_repository(name = "androidsdk")
android_ndk_repository(name = "androidndk")
cgruber marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ local_repository(
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:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

kotlin_repositories()
Expand Down
25 changes: 2 additions & 23 deletions examples/dagger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,6 @@ package(default_visibility = ["//visibility:private"])

load("//kotlin:kotlin.bzl", "kt_jvm_library")

java_plugin(
name = "dagger_plugin",
processor_class = "dagger.internal.codegen.ComponentProcessor",
deps = [
"//third_party/jvm/com/google/dagger",
"//third_party/jvm/com/google/dagger:dagger_compiler",
"//third_party/jvm/com/google/dagger:dagger_producers",
"//third_party/jvm/javax/inject:javax_inject",
"@//third_party/jvm/com/google/guava",
],
)

java_library(
name = "dagger_lib",
exported_plugins = ["dagger_plugin"],
exports = [
"//third_party/jvm/com/google/dagger",
"//third_party/jvm/javax/inject:javax_inject",
],
)

# Generate a srcjar to validate intellij plugin correctly attaches it.
genrule(
name = "tea_lib_src",
Expand All @@ -62,8 +41,8 @@ kt_jvm_library(
":tea_lib_src",
],
deps = [
":dagger_lib",
"//third_party/jvm/org/jetbrains/kotlinx:kotlinx_coroutines_core",
"//third_party:dagger",
"@kotlin_rules_maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core",
],
)

Expand Down
44 changes: 16 additions & 28 deletions examples/node/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
workspace(name = "kotlin_node_examples")

# Directly load the kotlin rules from the parent repo.
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:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories()
kt_register_toolchains()

# Node example dependencies
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "3356c6b767403392bab018ce91625f6d15ff8f11c6d772dc84bc9cada01c669a",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.36.1/rules_nodejs-0.36.1.tar.gz"],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")

yarn_install(
name = "node_ws",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

RULES_JVM_EXTERNAL_TAG = "2.7"

RULES_JVM_EXTERNAL_SHA = "f04b1466a00a2845106801e0c5cec96841f49ea4e7d1df88dc8e4bf31523df74"

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

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

maven_install(
Expand All @@ -49,7 +29,15 @@ maven_install(
)

http_archive(
name = "rules_pkg",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
name = "build_bazel_rules_nodejs",
sha256 = "3356c6b767403392bab018ce91625f6d15ff8f11c6d772dc84bc9cada01c669a",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.36.1/rules_nodejs-0.36.1.tar.gz"],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")

yarn_install(
name = "node_ws",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
3 changes: 3 additions & 0 deletions examples/trivial/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ local_repository(
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:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

kotlin_repositories()
Expand Down
19 changes: 19 additions & 0 deletions kotlin/dependencies.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


load("//kotlin/internal/repositories:download.bzl",
_kt_download_local_dev_dependencies="kt_download_local_dev_dependencies")

kt_download_local_dev_dependencies=_kt_download_local_dev_dependencies
4 changes: 2 additions & 2 deletions kotlin/internal/jvm/android.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], **kwargs):
"""
base_name = name + "_base"
kt_name = name + "_kt"

base_deps = deps + ["@io_bazel_rules_kotlin//third_party:android_sdk"]
# TODO(bazelbuild/rules_kotlin/issues/273): This should be retrieved from a provider.
base_deps = deps + [ "@io_bazel_rules_kotlin//third_party:android_sdk" ]

native.android_library(
name = base_name,
Expand Down
3 changes: 2 additions & 1 deletion kotlin/internal/repositories/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ release_archive(
srcs = [
"BUILD",
"BUILD.com_github_jetbrains_kotlin",
"download.bzl"
],
src_map = {
"nomaven_repositories.bzl": "repositories.bzl",
"release_repositories.bzl": "repositories.bzl",
},
)
Loading