├── .bazelci └── presubmit.yml ├── .bazelignore ├── .bazelproject ├── .bazelrc ├── .bazelversion ├── .editorconfig ├── .gitignore ├── AUTHORS ├── BUILD ├── BUILD.release.bazel ├── CHANGELOG.md ├── CODEOWNERS ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE ├── Makefile ├── README.md ├── ROADMAP.md ├── WORKSPACE ├── WORKSPACE.release.bazel ├── docs ├── index.html ├── kotlin │ ├── kotlin.html │ └── toolchains.html └── main.css ├── examples ├── BUILD ├── README.md ├── android │ ├── WORKSPACE │ ├── app │ │ ├── BUILD.bazel │ │ └── src │ │ │ └── main │ │ │ └── AndroidManifest.xml │ ├── lib │ │ ├── BUILD.bazel │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ └── kotlin │ │ │ └── examples │ │ │ └── android │ │ │ └── lib │ │ │ └── MainActivity.kt │ └── lib2 │ │ ├── BUILD.bazel │ │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── examples │ │ │ └── android │ │ │ └── lib2 │ │ │ └── MainActivity.java │ │ └── kotlin │ │ └── examples │ │ └── android │ │ └── lib2 │ │ └── Utils.kt ├── dagger │ ├── BUILD.bazel │ ├── src │ │ ├── coffee │ │ │ ├── BUILD.bazel │ │ │ ├── CoffeeApp.kt │ │ │ ├── CoffeeMaker.kt │ │ │ └── DripCoffeeModule.kt │ │ ├── heating │ │ │ ├── BUILD.bazel │ │ │ ├── ElectricHeater.kt │ │ │ └── Heater.kt │ │ ├── pumping │ │ │ ├── BUILD.bazel │ │ │ ├── Pump.kt │ │ │ ├── PumpModule.kt │ │ │ └── Thermosiphon.kt │ │ └── time │ │ │ ├── BUILD.bazel │ │ │ └── Delayer.kt │ └── test │ │ └── coffee │ │ ├── BUILD.bazel │ │ ├── BasicTest.kt │ │ └── BasicTestUtil.kt ├── node │ ├── .gitignore │ ├── BUILD │ ├── README.MD │ ├── WORKSPACE │ ├── coroutines-helloworld │ │ ├── BUILD │ │ └── Main.kt │ ├── express │ │ ├── App.kt │ │ ├── BUILD │ │ ├── Routes.kt │ │ └── auth │ │ │ ├── Auth.kt │ │ │ └── BUILD │ ├── package.json │ └── yarn.lock ├── plugin │ └── src │ │ ├── allopen │ │ ├── BUILD │ │ ├── OpenForTesting.kt │ │ ├── User.kt │ │ └── UserIsOpenTest.kt │ │ ├── noarg │ │ ├── BUILD │ │ ├── NoArgConstructor.kt │ │ ├── User.kt │ │ └── UserHasNoargConstructorTest.kt │ │ └── sam_with_receiver │ │ ├── BUILD │ │ ├── Runner.java │ │ ├── RunnerTest.kt │ │ └── SamWithReceiver.kt └── trivial │ ├── BUILD │ ├── WORKSPACE │ └── app │ ├── BUILD.bazel │ └── app.kt ├── kotlin ├── BUILD ├── dependencies.bzl ├── internal │ ├── BUILD │ ├── BUILD.release.bazel │ ├── compiler_plugins.bzl │ ├── defs.bzl │ ├── js │ │ ├── BUILD │ │ ├── BUILD.release.bazel │ │ ├── impl.bzl │ │ ├── importer.py │ │ └── js.bzl │ ├── jvm │ │ ├── BUILD │ │ ├── android.bzl │ │ ├── compile.bzl │ │ ├── impl.bzl │ │ ├── jvm.bzl │ │ └── plugins.bzl │ ├── repositories │ │ ├── BUILD │ │ ├── BUILD.com_github_jetbrains_kotlin │ │ ├── download.bzl │ │ ├── http_java_proto_file.bzl │ │ ├── nomaven_repositories.bzl │ │ ├── release_repositories.bzl │ │ ├── repositories.bzl │ │ └── setup.bzl │ ├── toolchains.bzl │ └── utils │ │ ├── BUILD │ │ ├── packager.bzl │ │ └── utils.bzl └── kotlin.bzl ├── renovate.json ├── scripts ├── bazel_from_source ├── gen_proto_jars ├── noop.sh ├── reflow_skylark ├── regen_deps └── win.bat ├── src ├── main │ ├── kotlin │ │ ├── BUILD │ │ ├── BUILD.release.bazel │ │ ├── bootstrap.bzl │ │ ├── io │ │ │ └── bazel │ │ │ │ └── kotlin │ │ │ │ ├── builder │ │ │ │ ├── BUILD │ │ │ │ ├── KotlinBuilderComponent.java │ │ │ │ ├── KotlinBuilderMain.java │ │ │ │ ├── tasks │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ ├── BazelWorker.kt │ │ │ │ │ ├── KotlinBuilder.kt │ │ │ │ │ ├── js │ │ │ │ │ │ └── Kotlin2JsTaskExecutor.kt │ │ │ │ │ └── jvm │ │ │ │ │ │ ├── CompilationArgs.kt │ │ │ │ │ │ ├── JDepsGenerator.kt │ │ │ │ │ │ ├── JavaCompiler.kt │ │ │ │ │ │ ├── JdepsParser.kt │ │ │ │ │ │ ├── KotlinJvmTaskExecutor.kt │ │ │ │ │ │ └── compilation_task.kt │ │ │ │ ├── toolchain │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ ├── CompilationTaskContext.kt │ │ │ │ │ ├── KaptCompilerPluginArgsEncoder.kt │ │ │ │ │ ├── KotlinToolException.kt │ │ │ │ │ └── KotlinToolchain.kt │ │ │ │ └── utils │ │ │ │ │ ├── ArgMap.kt │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ ├── BazelUtils.kt │ │ │ │ │ ├── IOUtils.kt │ │ │ │ │ ├── MiscUtils.kt │ │ │ │ │ ├── TaskUtils.kt │ │ │ │ │ ├── WorkingDirectoryContext.kt │ │ │ │ │ └── jars │ │ │ │ │ ├── JarCreator.kt │ │ │ │ │ ├── JarExtractor.kt │ │ │ │ │ ├── JarHelper.kt │ │ │ │ │ ├── SourceJarCreator.kt │ │ │ │ │ └── SourceJarExtractor.kt │ │ │ │ └── compiler │ │ │ │ ├── BUILD.bazel │ │ │ │ └── BazelK2JVMCompiler.kt │ │ └── shade.jarjar │ └── protobuf │ │ ├── BUILD │ │ ├── deps.proto │ │ ├── jars │ │ ├── libdeps_proto-speed.jar │ │ ├── libkotlin_model_proto-speed.jar │ │ └── libworker_protocol_proto-speed.jar │ │ ├── kotlin_model.proto │ │ └── worker_protocol.proto └── test │ ├── Bazel_all_local_tests.xml │ ├── data │ └── jvm │ │ ├── basic │ │ ├── BUILD │ │ ├── conventional_strip_resources │ │ │ └── src │ │ │ │ ├── main │ │ │ │ └── resources │ │ │ │ │ └── main.txt │ │ │ │ └── test │ │ │ │ └── resources │ │ │ │ └── test.txt │ │ ├── helloworld │ │ │ └── Main.kt │ │ ├── propagation │ │ │ ├── CompileTimeDependent.java │ │ │ ├── RuntimeDependent.java │ │ │ └── Stub.kt │ │ ├── resourcejar │ │ │ └── pkg │ │ │ │ └── file.txt │ │ ├── test_friends │ │ │ └── Service.kt │ │ └── testresources │ │ │ ├── resources │ │ │ └── one │ │ │ │ ├── alsoAFile.txt │ │ │ │ └── two │ │ │ │ └── aFile.txt │ │ │ └── src │ │ │ └── AClass.kt │ │ └── kapt │ │ ├── BUILD │ │ ├── java │ │ ├── TestAPNoGenReferences.java │ │ ├── TestAutoValue.java │ │ └── TestJavaService.java │ │ └── kotlin │ │ ├── TestKtAPNoGenReference.kt │ │ ├── TestKtService.kt │ │ └── TestKtValue.kt │ └── kotlin │ └── io │ └── bazel │ └── kotlin │ ├── BUILD │ ├── KotlinAssertionTestCase.kt │ ├── KotlinJvm13Test.kt │ ├── KotlinJvmBasicAssertionTest.kt │ ├── KotlinJvmDaggerExampleTest.kt │ ├── KotlinJvmFriendsVisibilityTest.kt │ ├── KotlinJvmKaptAssertionTest.kt │ ├── KotlinNormalizationAssertionTest.kt │ ├── builder │ ├── BUILD │ ├── Deps.java │ ├── DirectoryType.java │ ├── KotlinAbstractTestBuilder.java │ ├── KotlinBuilderTestComponent.java │ ├── KotlinJsTestBuilder.java │ ├── KotlinJvmTestBuilder.java │ ├── tasks │ │ ├── BUILD.bazel │ │ ├── js │ │ │ └── KotlinBuilderJsTest.java │ │ └── jvm │ │ │ ├── JdepsParserTest.java │ │ │ ├── KotlinBuilderJvmBasicTest.java │ │ │ ├── KotlinBuilderJvmKaptTest.java │ │ │ ├── KotlinJvmTaskExecutorTest.kt │ │ │ └── KotlinWorkerTest.kt │ └── utils │ │ ├── BUILD.bazel │ │ └── jars │ │ └── SourceJarCreatorTest.java │ └── defs.bzl └── third_party ├── BUILD ├── BUILD.release.bazel ├── empty.jar └── jarjar.bzl /.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | validate_config: 1 3 | bazel: 1.1.0 4 | tasks: 5 | ubuntu1604: 6 | build_targets: 7 | - "//:rules_kotlin_release" 8 | test_targets: 9 | - "//:all_tests" 10 | - "//examples/dagger/..." 11 | ubuntu1804: 12 | test_targets: 13 | - "//:all_tests" 14 | - "//examples/dagger/..." 15 | build_targets: 16 | - "//:rules_kotlin_release" 17 | rbe_ubuntu1604: 18 | test_targets: 19 | - "--" 20 | - "//src/test/kotlin/io/bazel/kotlin/builder:builder_tests" 21 | # KotlinJvmDaggerExampleTest and KotlinJvmKaptAssertionTest are not remote 22 | # execution compatible, do not run them for now. 23 | - "//src/test/kotlin/io/bazel/kotlin:KotlinJvmFriendsVisibilityTest" 24 | - "//src/test/kotlin/io/bazel/kotlin:KotlinJvmBasicAssertionTest" 25 | - "//examples/dagger/..." 26 | test_flags: 27 | # Override the default worker strategy for remote builds (worker strategy 28 | # cannot be used with remote builds) 29 | - "--strategy=KotlinCompile=remote" 30 | macos: 31 | test_targets: 32 | - "//:all_tests" 33 | - "//examples/dagger/..." 34 | example-android: 35 | name: "Example - Android" 36 | platform: ubuntu1804 37 | shell_command: 38 | - "cd .. && bazel build //:rules_kotlin_release_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_release.tgz" 39 | working_directory: examples/android 40 | test_flags: 41 | - "--override_repository=io_bazel_rules_kotlin_release=/tmp/rules_kotlin_release" 42 | test_targets: 43 | - //... 44 | examples-trivial: 45 | name: "Example - Trivial" 46 | platform: ubuntu1804 47 | shell_command: 48 | - "cd .. && bazel build //:rules_kotlin_release_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_release.tgz" 49 | working_directory: examples/trivial 50 | test_flags: 51 | - "--override_repository=io_bazel_rules_kotlin_release=/tmp/rules_kotlin_release" 52 | include_json_profile: 53 | - build 54 | - test 55 | build_targets: 56 | - //... 57 | examples-nodejs: 58 | name: Example - Node 59 | platform: ubuntu1804 60 | shell_command: 61 | - "cd bazel build //:rules_kotlin_release_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_release.tgz" 62 | working_directory: examples/node 63 | include_json_profile: 64 | - build 65 | - test 66 | test_flags: 67 | - "--override_repository=io_bazel_rules_kotlin_release=/tmp/rules_kotlin_release" 68 | build_targets: 69 | - //coroutines-helloworld/... 70 | - //express/... 71 | -------------------------------------------------------------------------------- /.bazelignore: -------------------------------------------------------------------------------- 1 | # Some examples have their own WORKSPACE. Ignore as part of this root WORKSPACE so 2 | # we don't break trying to build separate workspaces using wildcards like //... 3 | # examples/dagger doesn't have its own workspace, so don't do all of examples. 4 | examples/android 5 | examples/node 6 | examples/trivial 7 | -------------------------------------------------------------------------------- /.bazelproject: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | directories: 15 | # Add the directories you want added as source here 16 | # By default, we've added your entire workspace ('.') 17 | -examples/node/bazel-node 18 | -examples/node/bazel-bin 19 | -examples/node/bazel-genfiles 20 | -examples/node/bazel-out 21 | -examples/node/bazel-testlogs 22 | . 23 | 24 | targets: 25 | //:all_local_tests 26 | //examples/dagger/... 27 | # These targets are built for the ide only. Primary purpose is to ensure the builder can build the targets, but it's 28 | # also a good way of testing the intellij plugin. 29 | //src/main/kotlin/io/bazel/kotlin/builder/tasks:tasks_for_ide 30 | //src/main/kotlin/io/bazel/kotlin/builder/utils:utils_for_ide 31 | //src/main/kotlin/io/bazel/kotlin/builder/toolchain:toolchain_for_ide 32 | //src/main/kotlin/io/bazel/kotlin/compiler:compiler_for_ide 33 | 34 | test_sources: 35 | src/test/* 36 | 37 | additional_languages: 38 | kotlin 39 | 40 | import_run_configurations: 41 | src/test/Bazel_all_local_tests.xml 42 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- 1 | build --strategy=KotlinCompile=worker 2 | build --test_output=all 3 | build --verbose_failures 4 | 5 | -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 2.0.0 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{kt, kts}] 2 | indent_size = 2 3 | insert_final_newline = true 4 | max_line_length = 100 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/bazel-* 2 | **/.project 3 | **/.ijwb 4 | **/.aswb 5 | **/.vscode 6 | trace.profile.gz 7 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This the official list of rules_kotlin authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Google Inc. 10 | Hassan Syed 11 | Paul Johnston 12 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 15 | load("//kotlin/internal/utils:utils.bzl", "utils") 16 | 17 | exports_files([ 18 | "scripts/noop.sh", 19 | ]) 20 | 21 | # The entire test suite excluding local tests. 22 | test_suite( 23 | name = "all_tests", 24 | tests = [ 25 | "//src/test/kotlin/io/bazel/kotlin:assertion_tests", 26 | "//src/test/kotlin/io/bazel/kotlin/builder:builder_tests", 27 | ], 28 | ) 29 | 30 | # Local tests. Tests that shouldn't be run on the CI server. 31 | test_suite( 32 | name = "all_local_tests", 33 | tests = [ 34 | ":all_tests", 35 | "//src/test/kotlin/io/bazel/kotlin:local_assertion_tests", 36 | ], 37 | ) 38 | 39 | # Release target. 40 | release_archive( 41 | name = "rules_kotlin_release", 42 | src_map = { 43 | "BUILD.release.bazel": "BUILD.bazel", 44 | "WORKSPACE.release.bazel": "WORKSPACE", 45 | }, 46 | deps = [ 47 | "//kotlin:pkg", 48 | "//src/main/kotlin:pkg", 49 | "//third_party:pkg", 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /BUILD.release.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @ahumesky @cgruber @djwhang @jin @timpeut @restingbull 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Want to contribute? Great! First, read this page (including the small print at the end). 4 | 5 | # Before you contribute 6 | 7 | Before we can use your code, you must sign the Google Individual Contributor License Agreement (CLA), which you can do online. 8 | 9 | The CLA is necessary mainly because you own the copyright to your changes, even after your contribution becomes part of our codebase, so we need your permission to use and distribute your code. We also need to be sure of various other things — for instance that you'll tell us if you know that your code infringes on other people's patents. You don't have to sign the CLA until after you've submitted your code for review and a member has approved it, but you must do it before we can put your code into our codebase. 10 | 11 | # The small print 12 | 13 | Contributions made by corporations are covered by a different agreement than the one above, the Software Grant and Corporate Contributor License Agreement. 14 | 15 | # Contribution process 16 | 17 | Explain your idea and discuss your plan with members of the team. The best way to do this is to create an issue or comment on an existing issue. 18 | 19 | Prepare a git commit with your change. Don't forget to add tests. Run the existing tests with bazel test //.... Update README.md if appropriate. 20 | 21 | Create a pull request. This will start the code review process. All submissions, including submissions by project members, require review. 22 | 23 | You may be asked to make some changes. You'll also need to sign the CLA at this point, if you haven't done so already. Our continuous integration bots will test your change automatically on supported platforms. Once everything looks good, your change will be merged. 24 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # https://developers.google.com/open-source/cla/individual 7 | # https://developers.google.com/open-source/cla/corporate 8 | # 9 | # Names should be added to this file as: 10 | # Name 11 | 12 | Hassan Syed 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | bazel test all_tests 3 | 4 | test.local: 5 | bazel test all_local_tests 6 | 7 | test.no_worker: 8 | bazel clean 9 | bazel shutdown 10 | bazel test --strategy=KotlinCompile=local //:all_tests 11 | 12 | sky.reflow: 13 | scripts/reflow_skylark 14 | 15 | deps.regen: 16 | scripts/regen_deps 17 | 18 | proto.regen: 19 | scripts/gen_proto_jars 20 | 21 | install.tools: 22 | go get github.com/bazelbuild/buildtools/buildifier 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://badge.buildkite.com/72a7641b782f6f365efb775d7efb6b6ac4ea33f7db4ae7db55.svg)](https://buildkite.com/christian-gruber-open-source-stuffs/gruber-rules-kotlin-presubmit) 2 | 3 | # A fork of the legacy branch of bazelbuild/rules_kotlin 4 | 5 | 6 | # News! 7 | * Oct 5, 2019. github.com/cgruber/rules_kotlin upstreamed into this repository. 8 | 9 | This repository now no longer takes patches from external contributors, who are encouraged to 10 | use the [main project](github.com/bazelbuild/rules_kotlin) 11 | -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | # Kotlin Bazel Roadmap 2 | 3 | This document describes the major release milestones for the Kotlin Bazel Rules. 4 | There are three major pillars that we are focused on when developing the Kotlin 5 | rules - **Performance**, **Features**, and **Developer Experience** - and for 6 | each milestone we list the main items for each pillar. Progress on each item is 7 | tracked via an issue. 8 | 9 | If you have feedback on this roadmap (including feature and reprioritization 10 | requests) please open an issue or comment on the existing one. 11 | 12 | ## Kotlin 1.3 (est. mid 2019) 13 | 14 | The existing Kotlin rules only support up to version 1.2. The primary goal of 15 | this release is to bring preliminary 1.3 support to Bazel. We will seek to 16 | provide a migration path for users of the existing rules, with the intention of 17 | 1.3 eventually becoming the master branch. This includes documenting the 18 | differences between the rulesets, and providing migration tooling and support. 19 | 20 | ### Performance 21 | 22 | * Compilation avoidance for non-structural changes to dependencies 23 | 24 | ### Features 25 | 26 | * Support android_instrumentation_test on Linux and macOS 27 | * Support building and testing on Google Cloud Platform Remote Build Execution 28 | * Support for ktlint 29 | * Simplified package and dependency management 30 | * Improve Android interoperability 31 | 32 | ### Developer Experience 33 | 34 | * Document major differences between the rulesets 35 | * Documentation for Kotlin with Bazel compatibility across Windows, macOS, 36 | Linux 37 | * Stable and reliable CI 38 | * Sample projects 39 | 40 | ## XPlat (est. late 2019) 41 | 42 | The goal for the XPlat release is to provide a stable cross-platform (XPlat) 43 | experience for developers. We intend to provide first class Kotlin/Native 44 | support for Android and iOS, and collaborate with the community to add 45 | additional target platforms. We also plan to deliver performance improvements 46 | for build speed and binary size. 47 | 48 | ### Performance 49 | 50 | * Implement persistent workers for faster compilation 51 | * Reduce output binary sizes 52 | 53 | ### Features 54 | 55 | * Stable Kotlin/Native support for Android and iOS 56 | * Support `bazel coverage` for all test rules 57 | * Support for Android Lint 58 | 59 | ### Developer Experience 60 | 61 | * Documentation and guides for writing a cross platform app 62 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | workspace(name = "io_bazel_rules_kotlin") 15 | 16 | load("//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") 17 | 18 | kt_download_local_dev_dependencies() 19 | 20 | load("//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") 21 | 22 | kotlin_repositories() 23 | 24 | kt_register_toolchains() 25 | 26 | # Creates toolchain configuration for remote execution with BuildKite CI 27 | # for rbe_ubuntu1604 28 | load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig") 29 | 30 | rbe_autoconfig( 31 | name = "buildkite_config", 32 | ) 33 | 34 | android_sdk_repository(name = "androidsdk") 35 | 36 | android_ndk_repository(name = "androidndk") 37 | -------------------------------------------------------------------------------- /WORKSPACE.release.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | workspace(name = "io_bazel_rules_kotlin") -------------------------------------------------------------------------------- /docs/main.css: -------------------------------------------------------------------------------- 1 | body{background-color:#fafafa}pre,code{font-family:"Liberation Mono",Consolas,Monaco,"Andale Mono",monospace}pre{background-color:#eee;padding:20px;overflow-x:auto;word-wrap:normal}pre code{overflow-wrap:normal;white-space:pre}code{display:inline-block;font-size:90%;white-space:pre-wrap}.mdl-layout__drawer{background-color:#fff}.mdl-layout__drawer .mdl-layout-title{border-bottom:1px solid #e0e0e0;padding-left:24px}.drawer-nav ul{list-style:none;padding-left:0}.drawer-nav ul li{display:block;padding:0}.drawer-nav ul li ul li a{padding-left:44px;font-weight:400}.drawer-nav ul li a{display:block;flex-shrink:0;padding:15px 0 15px 22px;margin:0;font-weight:600;color:#757575;line-height:1em;text-decoration:none;cursor:pointer}.drawer-nav ul li a:active,.drawer-nav ul li a:hover{background-color:#f0f0f0}.drawer-nav ul li.active a{color:#4caf50;font-weight:500}h1.page-title{font-size:34px;font-weight:400;line-height:40px;margin-bottom:30px;color:#4caf50}p.lead{font-size:20px;line-height:32px}table{border-collapse:collapse;border-spacing:0;background-color:#fff;table-layout:auto}table thead th{background-color:#fafafa;border:1px solid #eee;color:#757575;padding:12px 12px 12px 24px;vertical-align:top}table tbody td{border:1px solid #eee;padding:12px 12px 12px 24px;vertical-align:top}table.params-table{width:100%}table.params-table col.col-param{width:25%}table.params-table col.col-description{width:75%}table.overview-table{width:100%}table.overview-table col.col-name{width:25%}table.overview-table col.col-description{width:75%}table.overview-table td p{margin:0}hr{margin-top:40px;margin-bottom:40px}nav.toc{border-left:5px solid #4caf50;padding-left:20px;margin-bottom:48px}nav.toc h1,nav.toc h2{font-size:15px;line-height:16px;padding-bottom:12px;margin-bottom:0;font-weight:400;color:#757575}nav.toc ul{list-style:none;margin-top:0;padding-left:0}nav.toc ul li{font-size:20px;line-height:40px}nav.toc ul li a{color:#4caf50}.page-content{margin-left:auto;margin-right:auto;padding-top:60px;padding-bottom:60px;width:760px}.page-content a{text-decoration:none}.page-content h1{font-size:34px;font-weight:400;line-height:40px;margin-bottom:30px;color:#4caf50}.page-content h2{font-size:24px;font-weight:400;line-height:32px;margin-bottom:30px;color:#4caf50}.page-content h3{font-size:20px;font-weight:400;line-height:32px;margin-bottom:30px;color:#4caf50}@media(max-width: 768px){.page-content{width:360px}}@media(min-width: 768px){.page-content{width:760px}}@media(min-width: 1476px){.page-content{width:1160px}}.mdl-mini-footer{padding-left:40px}/*# sourceMappingURL=main.css.map */ 2 | -------------------------------------------------------------------------------- /examples/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | package(default_visibility = ["//visibility:private"]) 15 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | The examples directory is for test applications. These could be used in tests or for verifying the intellij plugin. -------------------------------------------------------------------------------- /examples/android/WORKSPACE: -------------------------------------------------------------------------------- 1 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 2 | 3 | RULES_JVM_EXTERNAL_TAG = "2.8" 4 | 5 | RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad" 6 | 7 | http_archive( 8 | name = "rules_jvm_external", 9 | sha256 = RULES_JVM_EXTERNAL_SHA, 10 | strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, 11 | url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, 12 | ) 13 | 14 | load("@rules_jvm_external//:defs.bzl", "maven_install") 15 | 16 | maven_install( 17 | artifacts = [ 18 | "androidx.appcompat:appcompat:1.0.0", 19 | "junit:junit:4.12", 20 | "androidx.test.espresso:espresso-core:3.1.1", 21 | "org.hamcrest:hamcrest-library:1.3", 22 | ], 23 | repositories = [ 24 | "https://jcenter.bintray.com/", 25 | "https://maven.google.com", 26 | "https://repo1.maven.org/maven2", 27 | ], 28 | ) 29 | 30 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 31 | 32 | http_archive( 33 | name = "build_bazel_rules_android", 34 | sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", 35 | strip_prefix = "rules_android-0.1.1", 36 | urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"], 37 | ) 38 | 39 | load( 40 | "@build_bazel_rules_android//android:rules.bzl", 41 | "android_ndk_repository", 42 | "android_sdk_repository", 43 | ) 44 | 45 | android_sdk_repository(name = "androidsdk") 46 | 47 | android_ndk_repository(name = "androidndk") # Required. Name *must* be "androidndk". 48 | 49 | # Directly load the kotlin rules from the parent repo. 50 | local_repository( 51 | name = "io_bazel_rules_kotlin", 52 | path = "../..", 53 | ) 54 | 55 | load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") 56 | 57 | kt_download_local_dev_dependencies() 58 | 59 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") 60 | 61 | kotlin_repositories() 62 | 63 | kt_register_toolchains() 64 | 65 | # Skylib, for build_test, so don't bother initializing the unit test infrastructure. 66 | http_archive( 67 | name = "bazel_skylib", 68 | sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", 69 | urls = [ 70 | "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", 71 | ], 72 | ) 73 | 74 | http_archive( 75 | name = "rules_pkg", 76 | sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", 77 | url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", 78 | ) 79 | -------------------------------------------------------------------------------- /examples/android/app/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_android//android:rules.bzl", "android_binary") 2 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 3 | 4 | # An app that consumes android-kt deps 5 | android_binary( 6 | name = "app", 7 | custom_package = "examples.android.app", 8 | incremental_dexing = 0, 9 | manifest = "src/main/AndroidManifest.xml", 10 | multidex = "native", 11 | deps = [ 12 | "//lib", 13 | ], 14 | ) 15 | 16 | # An app that consumes jvm-kt libs 17 | android_binary( 18 | name = "app2", 19 | custom_package = "examples.android.app", 20 | incremental_dexing = 0, 21 | manifest = "src/main/AndroidManifest.xml", 22 | multidex = "native", 23 | deps = [ 24 | "//lib2", 25 | ], 26 | ) 27 | 28 | # An app that consumes android-kt deps, and does incremental dexing. 29 | android_binary( 30 | name = "app3", 31 | custom_package = "examples.android.app", 32 | incremental_dexing = 1, 33 | manifest = "src/main/AndroidManifest.xml", 34 | multidex = "native", 35 | deps = [ 36 | "//lib", 37 | ], 38 | ) 39 | 40 | build_test( 41 | name = "force_build_apks_test", 42 | targets = [ 43 | ":app.apk", 44 | ":app2.apk", 45 | ":app3.apk", 46 | ], 47 | ) 48 | -------------------------------------------------------------------------------- /examples/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /examples/android/lib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") 2 | 3 | kt_android_library( 4 | name = "lib", 5 | srcs = glob(["src/main/kotlin/**/*.kt"]), 6 | custom_package = "examples.android.lib", 7 | manifest = "src/main/AndroidManifest.xml", 8 | visibility = ["//visibility:public"], 9 | deps = [ 10 | "@maven//:androidx_appcompat_appcompat", 11 | ], 12 | ) 13 | -------------------------------------------------------------------------------- /examples/android/lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/android/lib/src/main/kotlin/examples/android/lib/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package examples.android.lib 2 | 3 | import android.app.Activity 4 | import android.os.Bundle 5 | import android.widget.Button 6 | import android.widget.LinearLayout 7 | import android.widget.LinearLayout.LayoutParams 8 | import androidx.appcompat.app.AlertDialog 9 | 10 | class MainActivity : Activity() { 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | val parent = LinearLayout(this).apply { 14 | orientation = LinearLayout.VERTICAL 15 | }.also { it.addView(Button(this).apply { text = "Foo!" }) } 16 | setContentView(parent, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) 17 | AlertDialog.Builder(this) 18 | .setTitle("Blah") 19 | .setMessage("Blah blah blah?") 20 | .show() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/android/lib2/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 2 | load("@build_bazel_rules_android//android:rules.bzl", "android_library") 3 | 4 | android_library( 5 | name = "lib2", 6 | srcs = glob(["src/main/java/**/*.java"]), 7 | custom_package = "examples.android.lib2", 8 | manifest = "src/main/AndroidManifest.xml", 9 | visibility = ["//visibility:public"], 10 | deps = [ 11 | ":util", 12 | "@maven//:androidx_appcompat_appcompat", 13 | ], 14 | ) 15 | 16 | kt_jvm_library( 17 | name = "util", 18 | srcs = glob(["src/main/kotlin/**/*.kt"]), 19 | ) 20 | -------------------------------------------------------------------------------- /examples/android/lib2/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/android/lib2/src/main/java/examples/android/lib2/MainActivity.java: -------------------------------------------------------------------------------- 1 | package examples.android.lib2; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.Button; 6 | import android.widget.LinearLayout; 7 | import android.widget.LinearLayout.LayoutParams; 8 | import androidx.appcompat.app.AlertDialog; 9 | 10 | public class MainActivity extends Activity { 11 | @Override protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | LinearLayout parent = new LinearLayout(this); 14 | parent.setOrientation(LinearLayout.VERTICAL); 15 | Button button = new Button(this); 16 | button.setText("Foo!"); 17 | parent.addView(button); 18 | setContentView(parent, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 19 | 20 | new AlertDialog.Builder(this) 21 | .setTitle("Blah") 22 | .setMessage("Blah blah blah?") 23 | .show(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/android/lib2/src/main/kotlin/examples/android/lib2/Utils.kt: -------------------------------------------------------------------------------- 1 | package examples.android.lib2 2 | 3 | class Blargh 4 | 5 | fun doStuff() { 6 | println("yay!") 7 | Blargh() 8 | } 9 | -------------------------------------------------------------------------------- /examples/dagger/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | package(default_visibility = ["//examples/dagger:__subpackages__"]) 15 | 16 | java_binary( 17 | name = "coffee_app", 18 | main_class = "coffee.CoffeeApp", 19 | visibility = ["//visibility:public"], 20 | runtime_deps = ["//examples/dagger/src/coffee"], 21 | ) 22 | -------------------------------------------------------------------------------- /examples/dagger/src/coffee/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_plugin") 15 | 16 | package(default_visibility = ["//visibility:private"]) 17 | 18 | load("//kotlin:kotlin.bzl", "kt_jvm_library") 19 | 20 | # Generate a srcjar to validate intellij plugin correctly attaches it. 21 | genrule( 22 | name = "tea_lib_src", 23 | outs = ["tea_lib_src.srcjar"], 24 | cmd = """ 25 | cat << EOF > TeaPot.kt 26 | package tea 27 | object TeaPot { 28 | fun isEmpty() = true 29 | } 30 | EOF 31 | $(JAVABASE)/bin/jar -cf $@ TeaPot.kt 32 | rm TeaPot.kt 33 | """, 34 | toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"], 35 | ) 36 | 37 | kt_jvm_library( 38 | name = "coffee", 39 | srcs = glob(["*.kt"]) + [ 40 | # Adding a file ending with .srcjar is how code generation patterns are implemented. 41 | ":tea_lib_src", 42 | ], 43 | friends = ["//examples/dagger/src/heating"], 44 | visibility = ["//examples/dagger:__subpackages__"], 45 | deps = [ 46 | "//examples/dagger/src/heating", 47 | "//examples/dagger/src/pumping", 48 | "//examples/dagger/src/time", 49 | "//third_party:dagger", 50 | "@kotlin_rules_maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core", 51 | ], 52 | ) 53 | -------------------------------------------------------------------------------- /examples/dagger/src/coffee/CoffeeApp.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package coffee 17 | 18 | import dagger.Component 19 | import javax.inject.Singleton 20 | import kotlinx.coroutines.runBlocking 21 | import tea.TeaPot 22 | 23 | class CoffeeApp { 24 | @Singleton 25 | @Component(modules = [(DripCoffeeModule::class)]) 26 | interface CoffeeShop { 27 | fun maker(): CoffeeMaker 28 | } 29 | 30 | companion object { 31 | @JvmStatic 32 | fun main(args: Array) { 33 | if (TeaPot.isEmpty()) { 34 | val coffeeShop = DaggerCoffeeApp_CoffeeShop.builder().build() 35 | runBlocking { 36 | coffeeShop.maker().brew() 37 | } 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /examples/dagger/src/coffee/CoffeeMaker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package coffee 17 | 18 | import dagger.Lazy 19 | import heating.Heater 20 | import javax.inject.Inject 21 | import kotlinx.coroutines.Dispatchers 22 | import kotlinx.coroutines.withContext 23 | import pumping.Pump 24 | 25 | class CoffeeMaker @Inject internal constructor( 26 | // Create a possibly costly heater only when we use it. 27 | private val heater: Lazy, 28 | private val pump: Pump 29 | ) { 30 | 31 | suspend fun brew() { 32 | // this function is async to verify intellij support for coroutines. 33 | withContext(Dispatchers.Default) { 34 | heater.get().on() 35 | pump.pump() 36 | println(" [_]P coffee! [_]P ") 37 | heater.get().off() 38 | } 39 | withContext(Dispatchers.Default) { 40 | if (heater.get().isOn) throw IllegalStateException("Heater should be off") 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/dagger/src/coffee/DripCoffeeModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package coffee 17 | 18 | import dagger.Binds 19 | import dagger.Module 20 | import dagger.Provides 21 | import heating.ElectricHeater 22 | import heating.Heater 23 | import javax.inject.Singleton 24 | import pumping.PumpModule 25 | import time.Delayer 26 | 27 | @Module(includes = [ PumpModule::class, Bindings::class ]) 28 | internal class DripCoffeeModule { 29 | @Provides 30 | @Singleton 31 | fun provideDelayer(): Delayer { 32 | return object : Delayer { 33 | override fun delay() { 34 | Thread.sleep(1000) 35 | } 36 | } 37 | } 38 | } 39 | 40 | @Module 41 | internal abstract class Bindings { 42 | @Binds @Singleton 43 | internal abstract fun bindHeater(heater: ElectricHeater): Heater 44 | } 45 | -------------------------------------------------------------------------------- /examples/dagger/src/heating/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin:kotlin.bzl", "kt_jvm_library") 15 | 16 | kt_jvm_library( 17 | name = "heating", 18 | srcs = glob(["*.kt"]), 19 | visibility = ["//examples/dagger:__subpackages__"], 20 | deps = [ 21 | "//examples/dagger/src/time", 22 | "//third_party:dagger", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /examples/dagger/src/heating/ElectricHeater.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package heating 17 | 18 | import javax.inject.Inject 19 | import time.Delayer 20 | 21 | class ElectricHeater 22 | @Inject constructor(private val delayer: Delayer) : Heater() { 23 | 24 | override var isHot: Boolean = false 25 | override var isOn: Boolean = false 26 | 27 | override fun on() { 28 | isOn = true 29 | println("~ ~ ~ heating ~ ~ ~") 30 | delayer.delay() 31 | this.isHot = true 32 | } 33 | 34 | override fun off() { 35 | this.isOn = false 36 | println("~ ~ ~ cooling ~ ~ ~") 37 | delayer.delay() 38 | this.isHot = false 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/dagger/src/heating/Heater.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package heating 17 | 18 | abstract class Heater { 19 | abstract val isHot: Boolean 20 | 21 | internal abstract val isOn: Boolean 22 | 23 | abstract fun on() 24 | abstract fun off() 25 | } 26 | -------------------------------------------------------------------------------- /examples/dagger/src/pumping/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin:kotlin.bzl", "kt_jvm_library") 15 | 16 | kt_jvm_library( 17 | name = "pumping", 18 | srcs = glob(["*.kt"]), 19 | visibility = ["//examples/dagger:__subpackages__"], 20 | deps = [ 21 | "//examples/dagger/src/heating", 22 | "//examples/dagger/src/time", 23 | "//third_party:dagger", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /examples/dagger/src/pumping/Pump.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package pumping 17 | 18 | interface Pump { 19 | fun pump() 20 | } 21 | -------------------------------------------------------------------------------- /examples/dagger/src/pumping/PumpModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package pumping 17 | 18 | import dagger.Binds 19 | import dagger.Module 20 | 21 | @Module 22 | abstract class PumpModule { 23 | @Binds 24 | internal abstract fun providePump(pump: Thermosiphon): Pump 25 | } 26 | -------------------------------------------------------------------------------- /examples/dagger/src/pumping/Thermosiphon.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package pumping 17 | 18 | import heating.Heater 19 | import javax.inject.Inject 20 | import time.Delayer 21 | 22 | internal class Thermosiphon 23 | @Inject constructor(private val heater: Heater, private val delayer: Delayer) : 24 | Pump { 25 | 26 | override fun pump() { 27 | if (heater.isHot) { 28 | println("=> => pumping => =>") 29 | delayer.delay() 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/dagger/src/time/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin:kotlin.bzl", "kt_jvm_library") 15 | 16 | kt_jvm_library( 17 | name = "time", 18 | srcs = glob(["*.kt"]), 19 | visibility = ["//examples/dagger:__subpackages__"], 20 | ) 21 | -------------------------------------------------------------------------------- /examples/dagger/src/time/Delayer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Bazel Authors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package time 17 | 18 | /** Introduces a delay (which can be overridden in testing */ 19 | interface Delayer { 20 | fun delay(): Unit 21 | } 22 | -------------------------------------------------------------------------------- /examples/dagger/test/coffee/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("//kotlin:kotlin.bzl", "kt_jvm_library", "kt_jvm_test") 2 | 3 | kt_jvm_library( 4 | name = "testlib", 5 | srcs = ["BasicTestUtil.kt"], 6 | # Use the deprecated friend= just to test that it works. 7 | friend = "//examples/dagger/src/heating", 8 | deps = [ 9 | "//examples/dagger/src/heating", 10 | ], 11 | ) 12 | 13 | kt_jvm_test( 14 | name = "BasicTest", 15 | srcs = ["BasicTest.kt"], 16 | friends = [":testlib"], # old syntax 17 | deps = [ 18 | ":testlib", 19 | "//examples/dagger/src/heating", 20 | "@kotlin_rules_maven//:com_google_truth_truth", 21 | "@kotlin_rules_maven//:junit_junit", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /examples/dagger/test/coffee/BasicTest.kt: -------------------------------------------------------------------------------- 1 | package coffee 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import heating.ElectricHeater 5 | import org.junit.Test 6 | import time.Delayer 7 | 8 | class BasicTest { 9 | @Test fun `test that internal member is transitively visible`() { 10 | val heater = ElectricHeater(object : Delayer { 11 | override fun delay() { 12 | println("fake delay") 13 | } 14 | }) 15 | assertThat(isHeaterOn(heater)).isFalse() 16 | heater.on() 17 | assertThat(isHeaterOn(heater)).isTrue() 18 | heater.off() 19 | assertThat(heater.isOn).isFalse() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/dagger/test/coffee/BasicTestUtil.kt: -------------------------------------------------------------------------------- 1 | package coffee 2 | 3 | import heating.Heater 4 | 5 | internal fun isHeaterOn(heater: Heater): Boolean = heater.isOn 6 | -------------------------------------------------------------------------------- /examples/node/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /examples/node/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import") 15 | 16 | # Create kt_js_imports for KotlinX's Coroutines and Atomicfu libraries. 17 | # 18 | # These could be imported using package.json and NPM, but they are here as an example of how to 19 | # use KotlinJS libraries hosted on Maven directly. 20 | # 21 | # Note: It's important that the `name`s correspond to the base name of the library only (ie. not-ending with -js/_js) 22 | kt_js_import( 23 | name = "kotlinx-coroutines-core", 24 | jars = [ 25 | "@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core_js", 26 | ], 27 | visibility = ["//:__subpackages__"], 28 | ) 29 | 30 | kt_js_import( 31 | name = "kotlinx-atomicfu", 32 | jars = [ 33 | "@maven//:org_jetbrains_kotlinx_atomicfu_js", 34 | ], 35 | visibility = ["//:__subpackages__"], 36 | ) 37 | -------------------------------------------------------------------------------- /examples/node/README.MD: -------------------------------------------------------------------------------- 1 | This example workspace demonstrates the JS support. -------------------------------------------------------------------------------- /examples/node/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "kotlin_node_examples") 2 | 3 | # Directly load the kotlin rules from the parent repo. 4 | local_repository( 5 | name = "io_bazel_rules_kotlin", 6 | path = "../..", 7 | ) 8 | 9 | load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") 10 | 11 | kt_download_local_dev_dependencies() 12 | 13 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") 14 | 15 | kotlin_repositories() 16 | 17 | kt_register_toolchains() 18 | 19 | # Node example dependencies 20 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 21 | load("@rules_jvm_external//:defs.bzl", "maven_install") 22 | 23 | maven_install( 24 | artifacts = [ 25 | "org.jetbrains.kotlinx:atomicfu-js:0.13.1", 26 | "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.2", 27 | ], 28 | repositories = [ 29 | "https://maven-central.storage.googleapis.com/repos/central/data/", 30 | "https://repo1.maven.org/maven2", 31 | ], 32 | ) 33 | 34 | http_archive( 35 | name = "build_bazel_rules_nodejs", 36 | sha256 = "3356c6b767403392bab018ce91625f6d15ff8f11c6d772dc84bc9cada01c669a", 37 | urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.36.1/rules_nodejs-0.36.1.tar.gz"], 38 | ) 39 | 40 | load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install") 41 | 42 | yarn_install( 43 | name = "node_ws", 44 | package_json = "//:package.json", 45 | yarn_lock = "//:yarn.lock", 46 | ) 47 | -------------------------------------------------------------------------------- /examples/node/coroutines-helloworld/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library") 15 | load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") 16 | 17 | kt_js_library( 18 | name = "app", 19 | srcs = ["Main.kt"], 20 | visibility = ["//visibility:public"], 21 | deps = [ 22 | "//:kotlinx-coroutines-core", 23 | ], 24 | ) 25 | 26 | nodejs_binary( 27 | name = "coroutines-helloworld", 28 | data = [":app"], 29 | entry_point = ":app.js", 30 | node_modules = "@node_ws//:node_modules", 31 | visibility = ["//visibility:public"], 32 | ) 33 | -------------------------------------------------------------------------------- /examples/node/coroutines-helloworld/Main.kt: -------------------------------------------------------------------------------- 1 | package trivial 2 | 3 | import kotlinx.coroutines.* 4 | 5 | val scope = CoroutineScope(Dispatchers.Default) 6 | 7 | suspend fun main(vararg args: String) { 8 | val job = scope.launch { 9 | delay(1000) 10 | println("Hello world!") 11 | } 12 | 13 | job.join() 14 | } 15 | -------------------------------------------------------------------------------- /examples/node/express/App.kt: -------------------------------------------------------------------------------- 1 | package express 2 | 3 | import kotlinx.coroutines.* 4 | import kotlinx.coroutines.channels.* 5 | 6 | @JsModule("express") 7 | external fun express(): dynamic 8 | 9 | val app = express() 10 | 11 | @ExperimentalCoroutinesApi 12 | fun main(args: Array) { 13 | val scope = CoroutineScope(Dispatchers.Default) 14 | 15 | // register the routes. 16 | val hitCountChannel = routes(app) 17 | scope.launch { 18 | hitCountChannel.consumeEach { 19 | println("Hits so far: $it") 20 | } 21 | } 22 | 23 | app.listen(3000, { 24 | println("Listening on port 3000") 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /examples/node/express/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library") 15 | load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") 16 | 17 | # routes and auth have acme prepended to the rule name as these are the names of the resulting jars. The name of the 18 | # jar is the name of the module, and thus the name of the require statements. 19 | kt_js_library( 20 | name = "acme-routes", 21 | srcs = [":Routes.kt"], 22 | deps = [ 23 | "//:kotlinx-atomicfu", 24 | "//:kotlinx-coroutines-core", 25 | "//express/auth:acme-auth", 26 | ], 27 | ) 28 | 29 | kt_js_library( 30 | name = "app", 31 | srcs = [":App.kt"], 32 | deps = [ 33 | ":acme-routes", 34 | "//:kotlinx-coroutines-core", 35 | ], 36 | ) 37 | 38 | # The binary demonstrates an express app composed of three modules. The modules can co-exist in the same directory. 39 | nodejs_binary( 40 | name = "express", 41 | data = [":app"], 42 | entry_point = ":app.js", 43 | node_modules = "@node_ws//:node_modules", 44 | ) 45 | -------------------------------------------------------------------------------- /examples/node/express/Routes.kt: -------------------------------------------------------------------------------- 1 | package express 2 | 3 | import express.auth.isAuthenticated 4 | import kotlinx.atomicfu.* 5 | import kotlinx.coroutines.* 6 | import kotlinx.coroutines.channels.* 7 | 8 | fun routes(app: dynamic): Channel { 9 | val scope = CoroutineScope(Dispatchers.Default) 10 | val channel = Channel() 11 | val hitCounter = atomic(0) 12 | 13 | app.get("/") { req, res -> 14 | scope.launch { 15 | val hitsSoFar = hitCounter.updateAndGet { it + 1 } 16 | channel.send(hitsSoFar) 17 | } 18 | if (!isAuthenticated("bob")) { 19 | res.send(401, "you sir, are not authorized !") 20 | } else { 21 | res.type("text/plain") 22 | res.send("hello world") 23 | } 24 | } 25 | 26 | return channel 27 | } 28 | -------------------------------------------------------------------------------- /examples/node/express/auth/Auth.kt: -------------------------------------------------------------------------------- 1 | package express.auth 2 | 3 | fun isAuthenticated(user: String): Boolean { 4 | return user != "bob" 5 | } 6 | -------------------------------------------------------------------------------- /examples/node/express/auth/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library") 15 | 16 | kt_js_library( 17 | name = "acme-auth", 18 | srcs = ["Auth.kt"], 19 | visibility = ["//visibility:public"], 20 | ) 21 | -------------------------------------------------------------------------------- /examples/node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node_packages", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "express": "^4.16.3" 6 | }, 7 | "devDependencies": { 8 | "source-map-support": "^0.5.6" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/plugin/src/allopen/BUILD: -------------------------------------------------------------------------------- 1 | load("//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library") 2 | 3 | kt_compiler_plugin( 4 | name = "open_for_testing_plugin", 5 | id = "org.jetbrains.kotlin.allopen", 6 | options = { 7 | "annotation": "plugin.allopen.OpenForTesting", 8 | }, 9 | deps = [ 10 | "@com_github_jetbrains_kotlin//:allopen-compiler-plugin", 11 | ], 12 | ) 13 | 14 | kt_jvm_library( 15 | name = "open_for_testing", 16 | srcs = ["OpenForTesting.kt"], 17 | ) 18 | 19 | kt_jvm_library( 20 | name = "user", 21 | srcs = ["User.kt"], 22 | plugins = [ 23 | ":open_for_testing_plugin", 24 | ], 25 | deps = [ 26 | ":open_for_testing", 27 | ], 28 | ) 29 | 30 | kt_jvm_library( 31 | name = "user_is_open_test", 32 | srcs = ["UserIsOpenTest.kt"], 33 | deps = [ 34 | ":user", 35 | ], 36 | ) 37 | -------------------------------------------------------------------------------- /examples/plugin/src/allopen/OpenForTesting.kt: -------------------------------------------------------------------------------- 1 | package plugin.allopen 2 | 3 | annotation class OpenForTesting 4 | -------------------------------------------------------------------------------- /examples/plugin/src/allopen/User.kt: -------------------------------------------------------------------------------- 1 | package plugin.allopen 2 | 3 | import java.util.* 4 | 5 | @OpenForTesting 6 | data class User( 7 | val userId: UUID, 8 | val emails: String 9 | ) 10 | -------------------------------------------------------------------------------- /examples/plugin/src/allopen/UserIsOpenTest.kt: -------------------------------------------------------------------------------- 1 | package plugin.allopen 2 | 3 | import java.util.* 4 | 5 | class Subclass : User(UUID.randomUUID(), "test@example.org") 6 | -------------------------------------------------------------------------------- /examples/plugin/src/noarg/BUILD: -------------------------------------------------------------------------------- 1 | load("//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library", "kt_jvm_test") 2 | 3 | kt_compiler_plugin( 4 | name = "no_arg_plugin", 5 | id = "org.jetbrains.kotlin.noarg", 6 | options = { 7 | "annotation": "plugin.noarg.NoArgConstructor", 8 | }, 9 | deps = [ 10 | "@com_github_jetbrains_kotlin//:noarg-compiler-plugin", 11 | ], 12 | ) 13 | 14 | kt_jvm_library( 15 | name = "no_arg_constructor", 16 | srcs = ["NoArgConstructor.kt"], 17 | ) 18 | 19 | kt_jvm_library( 20 | name = "user", 21 | srcs = ["User.kt"], 22 | plugins = [":no_arg_plugin"], 23 | deps = [ 24 | ":no_arg_constructor", 25 | ], 26 | ) 27 | 28 | # The no-arg constructor that is generated cannot be compiled against, but should be discoverable at runtime. 29 | kt_jvm_test( 30 | name = "user_has_noarg_constructor_test", 31 | srcs = ["UserHasNoargConstructorTest.kt"], 32 | test_class = "plugin.noarg.UserHasNoargConstructorTest", 33 | deps = [ 34 | ":user", 35 | "@com_github_jetbrains_kotlin//:kotlin-reflect", 36 | "@kotlin_rules_maven//:junit_junit", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /examples/plugin/src/noarg/NoArgConstructor.kt: -------------------------------------------------------------------------------- 1 | package plugin.noarg 2 | 3 | annotation class NoArgConstructor 4 | -------------------------------------------------------------------------------- /examples/plugin/src/noarg/User.kt: -------------------------------------------------------------------------------- 1 | package plugin.noarg 2 | 3 | import java.util.* 4 | 5 | @NoArgConstructor 6 | data class User( 7 | val userId: UUID, 8 | val emails: String 9 | ) 10 | -------------------------------------------------------------------------------- /examples/plugin/src/noarg/UserHasNoargConstructorTest.kt: -------------------------------------------------------------------------------- 1 | package plugin.noarg 2 | 3 | import java.lang.Exception 4 | import org.junit.* 5 | 6 | class UserHasNoargConstructorTest { 7 | @Test 8 | fun userShouldHaveNoargConstructor() { 9 | if (User::class.java.constructors.none { it.parameters.isEmpty() }) { 10 | throw Exception("Expected an empty constructor to exist") 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/plugin/src/sam_with_receiver/BUILD: -------------------------------------------------------------------------------- 1 | load("//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library") 2 | load("@rules_java//java:defs.bzl", "java_library") 3 | 4 | kt_compiler_plugin( 5 | name = "sam_with_receiver_plugin", 6 | id = "org.jetbrains.kotlin.samWithReceiver", 7 | options = { 8 | "annotation": "plugin.sam_with_receiver.SamWithReceiver", 9 | }, 10 | deps = [ 11 | "@com_github_jetbrains_kotlin//:sam-with-receiver-compiler-plugin", 12 | ], 13 | ) 14 | 15 | kt_jvm_library( 16 | name = "sam_with_receiver", 17 | srcs = ["SamWithReceiver.kt"], 18 | ) 19 | 20 | java_library( 21 | name = "runner", 22 | srcs = ["Runner.java"], 23 | deps = [":sam_with_receiver"], 24 | ) 25 | 26 | kt_jvm_library( 27 | name = "runner_test", 28 | srcs = ["RunnerTest.kt"], 29 | plugins = [":sam_with_receiver_plugin"], 30 | deps = [":runner"], 31 | ) 32 | -------------------------------------------------------------------------------- /examples/plugin/src/sam_with_receiver/Runner.java: -------------------------------------------------------------------------------- 1 | package plugin.sam_with_receiver; 2 | 3 | @SamWithReceiver 4 | public interface Runner { 5 | void run(Double shouldBecomeThis); 6 | } 7 | -------------------------------------------------------------------------------- /examples/plugin/src/sam_with_receiver/RunnerTest.kt: -------------------------------------------------------------------------------- 1 | package plugin.sam_with_receiver 2 | 3 | val thisShouldWork = Runner { 4 | println(this.isFinite()) 5 | } 6 | -------------------------------------------------------------------------------- /examples/plugin/src/sam_with_receiver/SamWithReceiver.kt: -------------------------------------------------------------------------------- 1 | package plugin.sam_with_receiver 2 | 3 | annotation class SamWithReceiver 4 | -------------------------------------------------------------------------------- /examples/trivial/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | java_library( 4 | name = "java_deps", 5 | exports = [ 6 | "@maven//:com_expedia_graphql_kotlin", 7 | "@maven//:com_expedia_graphql_kotlin_schema_generator", 8 | "@maven//:com_graphql_java_graphql_java", 9 | "@maven//:org_apache_logging_log4j_log4j_core", 10 | "@maven//:org_apiguardian_apiguardian_api", 11 | "@maven//:org_opentest4j_opentest4j", 12 | ], 13 | ) 14 | -------------------------------------------------------------------------------- /examples/trivial/WORKSPACE: -------------------------------------------------------------------------------- 1 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 2 | 3 | local_repository( 4 | name = "io_bazel_rules_kotlin", 5 | path = "../..", 6 | ) 7 | 8 | load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") 9 | 10 | kt_download_local_dev_dependencies() 11 | 12 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") 13 | 14 | kotlin_repositories() 15 | 16 | kt_register_toolchains() 17 | 18 | RULES_JVM_EXTERNAL_TAG = "2.7" 19 | 20 | RULES_JVM_EXTERNAL_SHA = "f04b1466a00a2845106801e0c5cec96841f49ea4e7d1df88dc8e4bf31523df74" 21 | 22 | http_archive( 23 | name = "rules_jvm_external", 24 | sha256 = RULES_JVM_EXTERNAL_SHA, 25 | strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, 26 | url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, 27 | ) 28 | 29 | load("@rules_jvm_external//:defs.bzl", "maven_install") 30 | 31 | maven_install( 32 | artifacts = [ 33 | "com.expedia:graphql-kotlin:1.0.0-RC5", 34 | "com.expedia:graphql-kotlin-schema-generator:1.0.0-RC5", 35 | "com.expedia:graphql-kotlin-federation:1.0.0-RC5", 36 | "com.graphql-java:graphql-java:13.0", 37 | "org.opentest4j:opentest4j:1.1.1", 38 | "org.apiguardian:apiguardian-api:1.0.0", 39 | "org.junit.platform:junit-platform-commons:1.4.2", 40 | "org.junit.jupiter:junit-jupiter-api:5.4.2", 41 | "org.junit.jupiter:junit-jupiter-params:5.4.2", 42 | "org.apache.logging.log4j:log4j-core:2.12.1", 43 | ], 44 | repositories = [ 45 | "https://maven-central.storage.googleapis.com/repos/central/data/", 46 | "https://repo1.maven.org/maven2", 47 | ], 48 | ) 49 | 50 | http_archive( 51 | name = "rules_pkg", 52 | sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", 53 | url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", 54 | ) 55 | -------------------------------------------------------------------------------- /examples/trivial/app/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 2 | 3 | kt_jvm_library( 4 | name = "app_lib", 5 | srcs = glob(["**/*.kt"]), 6 | deps = [ 7 | "//:java_deps", 8 | ], 9 | ) 10 | 11 | java_binary( 12 | name = "myapp", 13 | main_class = "app.MyApp", 14 | runtime_deps = [":app_lib"], 15 | ) 16 | -------------------------------------------------------------------------------- /examples/trivial/app/app.kt: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import com.expedia.graphql.SchemaGeneratorConfig 4 | import com.expedia.graphql.TopLevelObject 5 | import com.expedia.graphql.toSchema 6 | import graphql.GraphQL 7 | 8 | data class Foo(val name: String, val age: Int) 9 | 10 | class Query { 11 | fun foo(bar: String?) = Foo("$bar!", 42) 12 | } 13 | 14 | class MyApp { 15 | companion object { 16 | @JvmStatic 17 | fun main(args: Array) { 18 | val schema = toSchema(queries = listOf(TopLevelObject(Query())), 19 | config = SchemaGeneratorConfig(listOf("app"))) 20 | 21 | val graphql = GraphQL.newGraphQL(schema).build() 22 | 23 | val result = graphql.execute("""{ foo(bar: "baz") { name, age } }""").toSpecification() 24 | 25 | println(result) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /kotlin/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 15 | 16 | release_archive( 17 | name = "pkg", 18 | srcs = glob(["*.*"]) + ["BUILD"], 19 | deps = [ 20 | "//kotlin/internal:pkg", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /kotlin/dependencies.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load( 16 | "//kotlin/internal/repositories:download.bzl", 17 | _kt_download_local_dev_dependencies = "kt_download_local_dev_dependencies", 18 | ) 19 | 20 | kt_download_local_dev_dependencies = _kt_download_local_dev_dependencies 21 | -------------------------------------------------------------------------------- /kotlin/internal/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains") 16 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 17 | 18 | # Configures the toolchains 19 | kt_configure_toolchains() 20 | 21 | release_archive( 22 | name = "pkg", 23 | srcs = glob(["*.bzl"]), 24 | src_map = { 25 | "BUILD.release.bazel": "BUILD.bazel", 26 | }, 27 | deps = [ 28 | "//kotlin/internal/js:pkg", 29 | "//kotlin/internal/jvm:pkg", 30 | "//kotlin/internal/repositories:pkg", 31 | "//kotlin/internal/utils:pkg", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /kotlin/internal/BUILD.release.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains") 16 | 17 | kt_configure_toolchains() 18 | -------------------------------------------------------------------------------- /kotlin/internal/compiler_plugins.bzl: -------------------------------------------------------------------------------- 1 | load( 2 | "//kotlin/internal:defs.bzl", 3 | _KtCompilerPluginInfo = "KtCompilerPluginInfo", 4 | ) 5 | 6 | def plugins_to_classpaths(providers_list): 7 | flattened_files = [] 8 | for providers in providers_list: 9 | if _KtCompilerPluginInfo in providers: 10 | provider = providers[_KtCompilerPluginInfo] 11 | for e in provider.classpath: 12 | flattened_files.append(e) 13 | return flattened_files 14 | 15 | def plugins_to_options(providers_list): 16 | kt_compiler_plugin_providers = [providers[_KtCompilerPluginInfo] for providers in providers_list if _KtCompilerPluginInfo in providers] 17 | flattened_options = [] 18 | for provider in kt_compiler_plugin_providers: 19 | for option in provider.options: 20 | flattened_options.append("%s:%s" % (option.id, option.value)) 21 | return flattened_options 22 | -------------------------------------------------------------------------------- /kotlin/internal/defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License.# 14 | 15 | # The Kotlin Toolchain type. 16 | TOOLCHAIN_TYPE = "@io_bazel_rules_kotlin//kotlin/internal:kt_toolchain_type" 17 | 18 | # The name of the Kotlin compiler workspace. 19 | KT_COMPILER_REPO = "com_github_jetbrains_kotlin" 20 | 21 | KtJvmInfo = provider( 22 | fields = { 23 | "module_name": "the module name", 24 | "friend_paths": "The target(s) that this library can see the internals of.", 25 | "srcs": "the source files. [intelij-aspect]", 26 | "outputs": "output jars produced by this rule. [intelij-aspect]", 27 | "language_version": "version of kotlin used. [intellij-aspect]", 28 | }, 29 | ) 30 | 31 | KtJsInfo = provider( 32 | fields = { 33 | "js": "The primary output of the library", 34 | "js_map": "The map file for the library", 35 | "jar": "A jar of the library.", 36 | "srcjar": "The jar containing the sources of the library", 37 | }, 38 | ) 39 | 40 | KtCompilerPluginInfo = provider( 41 | fields = { 42 | "classpath": "The kotlin compiler plugin classpath", 43 | "options": "List of plugin options, represented as structs with an id and a value field, to be passed to the compiler", 44 | }, 45 | ) 46 | -------------------------------------------------------------------------------- /kotlin/internal/js/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 15 | 16 | # TODO(https://github.com/bazelbuild/rules_kotlin/issues/270): Replace with Starlark 17 | py_binary( 18 | name = "importer", 19 | srcs = ["importer.py"], 20 | visibility = ["//visibility:public"], 21 | ) 22 | 23 | release_archive( 24 | name = "pkg", 25 | srcs = glob([ 26 | "*.bzl", 27 | "*.py", 28 | ]), 29 | src_map = { 30 | "BUILD.release.bazel": "BUILD.bazel", 31 | }, 32 | ) 33 | -------------------------------------------------------------------------------- /kotlin/internal/js/BUILD.release.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | py_binary( 16 | name = "importer", 17 | srcs = ["importer.py"], 18 | visibility = ["//visibility:public"], 19 | ) 20 | -------------------------------------------------------------------------------- /kotlin/internal/js/importer.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | import argparse 15 | import os 16 | import re 17 | import shutil 18 | import tempfile 19 | import zipfile 20 | 21 | 22 | def _is_jar(jar): 23 | if not os.path.exists(jar): 24 | raise argparse.ArgumentTypeError("jar:{0} does not exist".format(jar)) 25 | else: 26 | return zipfile.ZipFile(jar) 27 | 28 | 29 | def _extract_root_entry(jar, filename_pattern, output_path, touch=False): 30 | """ 31 | Extracts a root entry from a jar. and write it to a path. 32 | 33 | output_path is absolute and the basename is used to extract the entry from the jar. 34 | 35 | :param jar: The jar from which to make the extraction. 36 | :param filename_pattern: Regular expression to match when searching for the file in the jar. 37 | :param output_path: An absolute file path to where the entry should be written. 38 | :param touch: Should the file be touched if it was not found in the jar. 39 | """ 40 | target = None 41 | for filename in jar.namelist(): 42 | if filename_pattern.match(filename): 43 | target = filename 44 | break 45 | 46 | if not target: 47 | if touch: 48 | f = open(output_path, 'a') 49 | f.close() 50 | return 51 | else: 52 | raise FileNotFoundError("No file matching {0} was found in jar".format(filename_pattern)) 53 | 54 | # Extract the target file to a temporary location. 55 | temp_dir = tempfile.gettempdir() 56 | temp_file = os.path.join(temp_dir, os.path.basename(target)) 57 | jar.extract(target, path=temp_dir) 58 | 59 | # Move the temp file into the final output location. 60 | shutil.move(temp_file, output_path) 61 | 62 | 63 | def _main(p): 64 | args = p.parse_args() 65 | _extract_root_entry(args.jar, args.import_pattern, args.import_out) 66 | for (p, e) in zip(args.aux_pattern, args.aux_out): 67 | _extract_root_entry(args.jar, p, e, touch=True) 68 | 69 | 70 | parser = argparse.ArgumentParser() 71 | 72 | parser.add_argument("--jar", type=_is_jar, required=True) 73 | parser.add_argument("--import_pattern", required=True, type=re.compile, 74 | help="regular expression to match when searching the jar for the KotlinJS file") 75 | parser.add_argument("--import_out", required=True, help="path where the extracted KotlinJS import should be stored") 76 | parser.add_argument( 77 | "--aux_pattern", nargs="*", type=re.compile, 78 | help="""regular expressions to match when searching the jar for additional files""") 79 | parser.add_argument( 80 | "--aux_out", nargs="*", 81 | help="""paths where additonal files from the jar should be stored, if the files do not exist these paths are touched.""") 82 | 83 | _main(parser) 84 | -------------------------------------------------------------------------------- /kotlin/internal/jvm/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 16 | 17 | release_archive( 18 | name = "pkg", 19 | srcs = glob(["*.bzl"]) + ["BUILD"], 20 | ) 21 | -------------------------------------------------------------------------------- /kotlin/internal/jvm/android.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load( 15 | "//kotlin/internal/jvm:jvm.bzl", 16 | _kt_jvm_library = "kt_jvm_library", 17 | ) 18 | 19 | def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], friend = None, **kwargs): 20 | """Delegates Android related build attributes to the native rules but uses the Kotlin builder to compile Java and 21 | Kotlin srcs. Returns a sequence of labels that a wrapping macro should export. 22 | """ 23 | base_name = name + "_base" 24 | kt_name = name + "_kt" 25 | 26 | # TODO(bazelbuild/rules_kotlin/issues/273): This should be retrieved from a provider. 27 | base_deps = deps + ["@io_bazel_rules_kotlin//third_party:android_sdk"] 28 | 29 | native.android_library( 30 | name = base_name, 31 | visibility = ["//visibility:private"], 32 | exports = base_deps, 33 | **kwargs 34 | ) 35 | _kt_jvm_library( 36 | name = kt_name, 37 | srcs = srcs, 38 | deps = base_deps + [base_name], 39 | plugins = plugins, 40 | testonly = kwargs.get("testonly", default = 0), 41 | friend = friend, 42 | # must be public to be referenced as friends. 43 | # TODO: rework this into a proper android provider giving rule, so we can avoid all this. 44 | visibility = ["//visibility:public"], 45 | ) 46 | return [base_name, kt_name] 47 | 48 | def kt_android_library(name, exports = [], visibility = None, **kwargs): 49 | """Creates an Android sandwich library. `srcs`, `deps`, `plugins` are routed to `kt_jvm_library` the other android 50 | related attributes are handled by the native `android_library` rule. 51 | """ 52 | native.android_library( 53 | name = name, 54 | exports = exports + _kt_android_artifact(name, **kwargs), 55 | visibility = visibility, 56 | tags = kwargs.get("tags", default = None), 57 | testonly = kwargs.get("testonly", default = 0), 58 | ) 59 | -------------------------------------------------------------------------------- /kotlin/internal/jvm/plugins.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load( 15 | "//kotlin/internal/utils:utils.bzl", 16 | _utils = "utils", 17 | ) 18 | 19 | KtJvmPluginInfo = provider( 20 | doc = "This provider contains the plugin info for the JVM aspect", 21 | fields = { 22 | "annotation_processors": "depset of structs containing annotation processor definitions", 23 | }, 24 | ) 25 | 26 | _EMPTY_PLUGIN_INFO = [KtJvmPluginInfo(annotation_processors = depset())] 27 | 28 | # Mapping functions for args.add_all. 29 | # These preserve the transitive depsets until needed. 30 | def _kt_plugin_to_processor(processor): 31 | return processor.processor_class 32 | 33 | def _kt_plugin_to_processorpath(processor): 34 | return [j.path for j in processor.classpath.to_list()] 35 | 36 | def _targets_to_annotation_processors(targets): 37 | return depset(transitive = [t[KtJvmPluginInfo].annotation_processors for t in targets if t[KtJvmPluginInfo]]) 38 | 39 | def _targets_to_plugins(targets): 40 | return depset(transitive = [t[KtJvmPluginInfo].plugins for t in targets if t[KtJvmPluginInfo]]) 41 | 42 | mappers = struct( 43 | targets_to_annotation_processors = _targets_to_annotation_processors, 44 | kt_plugin_to_processor = _kt_plugin_to_processor, 45 | kt_plugin_to_processorpath = _kt_plugin_to_processorpath, 46 | ) 47 | 48 | def merge_plugin_infos(attrs): 49 | """Merge all of the plugin infos found in the provided sequence of attributes. 50 | Returns: 51 | A KtJvmPluginInfo provider, Each of the entries is serializable.""" 52 | return KtJvmPluginInfo( 53 | annotation_processors = _targets_to_annotation_processors(attrs), 54 | ) 55 | 56 | def _kt_jvm_plugin_aspect_impl(target, ctx): 57 | if ctx.rule.kind == "java_plugin": 58 | processor = ctx.rule.attr 59 | merged_deps = java_common.merge([j[JavaInfo] for j in processor.deps]) 60 | return [KtJvmPluginInfo( 61 | annotation_processors = depset([ 62 | struct( 63 | label = _utils.restore_label(ctx.label), 64 | processor_class = processor.processor_class, 65 | classpath = merged_deps.transitive_runtime_jars, 66 | generates_api = processor.generates_api, 67 | ), 68 | ]), 69 | )] 70 | elif ctx.rule.kind == "java_library": 71 | return [merge_plugin_infos(ctx.rule.attr.exported_plugins)] 72 | else: 73 | return _EMPTY_PLUGIN_INFO 74 | 75 | kt_jvm_plugin_aspect = aspect( 76 | doc = """This aspect collects Java Plugins info and other Kotlin compiler plugin configurations from the graph.""", 77 | attr_aspects = [ 78 | "plugins", 79 | "exported_plugins", 80 | ], 81 | provides = [KtJvmPluginInfo], 82 | implementation = _kt_jvm_plugin_aspect_impl, 83 | ) 84 | -------------------------------------------------------------------------------- /kotlin/internal/repositories/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 15 | 16 | release_archive( 17 | name = "pkg", 18 | srcs = [ 19 | "BUILD", 20 | "BUILD.com_github_jetbrains_kotlin", 21 | "download.bzl", 22 | ], 23 | src_map = { 24 | "release_repositories.bzl": "repositories.bzl", 25 | }, 26 | ) 27 | -------------------------------------------------------------------------------- /kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | package(default_visibility = ["//visibility:public"]) 15 | 16 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import", "kt_jvm_import") 17 | load("@rules_java//java:defs.bzl", "java_import") 18 | 19 | # Kotlin home filegroup containing everything that is needed. 20 | filegroup( 21 | name = "home", 22 | srcs = glob(["**"]), 23 | ) 24 | 25 | kt_jvm_import( 26 | name = "annotations", 27 | jar = "lib/annotations-13.0.jar", 28 | neverlink = 1, 29 | ) 30 | 31 | kt_jvm_import( 32 | name = "android-extensions-compiler", 33 | jars = ["lib/android-extensions-compiler.jar"], 34 | neverlink = 1, 35 | ) 36 | 37 | # Kotlin dependencies that are internal to this repo and are meant to be loaded manually into a classloader. 38 | [ 39 | kt_jvm_import( 40 | name = "kotlin-%s" % art, 41 | jar = "lib/kotlin-%s.jar" % art, 42 | neverlink = 1, 43 | ) 44 | for art in [ 45 | "annotation-processing", 46 | "annotation-processing-runtime", 47 | "compiler", 48 | ] 49 | ] 50 | 51 | kt_jvm_import( 52 | name = "allopen-compiler-plugin", 53 | jar = "lib/allopen-compiler-plugin.jar", 54 | ) 55 | 56 | kt_jvm_import( 57 | name = "noarg-compiler-plugin", 58 | jar = "lib/noarg-compiler-plugin.jar", 59 | ) 60 | 61 | kt_jvm_import( 62 | name = "sam-with-receiver-compiler-plugin", 63 | jar = "lib/sam-with-receiver-compiler-plugin.jar", 64 | ) 65 | 66 | # Kotlin dependencies that are internal to this repo and may be linked. 67 | [ 68 | java_import( 69 | name = "kotlin-%s" % art, 70 | jars = ["lib/kotlin-%s.jar" % art], 71 | ) 72 | for art in [ 73 | "preloader", 74 | ] 75 | ] 76 | 77 | # The Kotlin standard libraries. These should be setup in a Toolchain. 78 | [ 79 | kt_jvm_import( 80 | name = "kotlin-%s" % art, 81 | jar = "lib/kotlin-%s.jar" % art, 82 | srcjar = "lib/kotlin-%s-sources.jar" % art, 83 | visibility = ["//visibility:public"], 84 | ) 85 | for art in [ 86 | "stdlib", 87 | "stdlib-jdk7", 88 | "stdlib-jdk8", 89 | "reflect", 90 | "test", 91 | "script-runtime", 92 | ] 93 | ] 94 | 95 | # The Kotlin JS standard libraries. These should be setup in a Toolchain. 96 | [ 97 | kt_js_import( 98 | name = "kotlin-%s" % art, 99 | jars = ["lib/kotlin-%s.jar" % art], 100 | srcjar = "lib/kotlin-%s-sources.jar" % art, 101 | visibility = ["//visibility:public"], 102 | ) 103 | for art in [ 104 | "test-js", 105 | "stdlib-js", 106 | ] 107 | ] 108 | -------------------------------------------------------------------------------- /kotlin/internal/repositories/nomaven_repositories.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """This file contains the Kotlin compiler repository definitions. It should not be loaded directly by client workspaces. 15 | """ 16 | 17 | load( 18 | "//kotlin/internal:defs.bzl", 19 | _KT_COMPILER_REPO = "KT_COMPILER_REPO", 20 | ) 21 | load( 22 | "@bazel_tools//tools/build_defs/repo:http.bzl", 23 | _http_archive = "http_archive", 24 | _http_file = "http_file", 25 | ) 26 | 27 | BAZEL_JAVA_LAUNCHER_VERSION = "0.28.1" 28 | 29 | KOTLIN_CURRENT_COMPILER_RELEASE = { 30 | "urls": [ 31 | "https://github.com/JetBrains/kotlin/releases/download/v1.3.50/kotlin-compiler-1.3.50.zip", 32 | ], 33 | "sha256": "69424091a6b7f52d93eed8bba2ace921b02b113dbb71388d704f8180a6bdc6ec", 34 | } 35 | 36 | def kotlin_repositories(compiler_release = KOTLIN_CURRENT_COMPILER_RELEASE): 37 | """Call this in the WORKSPACE file to setup the Kotlin rules. 38 | 39 | Args: 40 | compiler_release: (internal) dict containing "urls" and "sha256" for the Kotlin compiler. 41 | """ 42 | _http_archive( 43 | name = _KT_COMPILER_REPO, 44 | urls = compiler_release["urls"], 45 | sha256 = compiler_release["sha256"], 46 | build_file = "@io_bazel_rules_kotlin//kotlin/internal/repositories:BUILD.com_github_jetbrains_kotlin", 47 | strip_prefix = "kotlinc", 48 | ) 49 | 50 | _http_file( 51 | name = "kt_java_stub_template", 52 | urls = [("https://raw.githubusercontent.com/bazelbuild/bazel/" + 53 | BAZEL_JAVA_LAUNCHER_VERSION + 54 | "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + 55 | "java_stub_template.txt")], 56 | sha256 = "e6531a6539ec1e38fec5e20523ff4bfc883e1cc0209eb658fe82eb918eb49657", 57 | ) 58 | -------------------------------------------------------------------------------- /kotlin/internal/repositories/release_repositories.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """This file contains the Kotlin compiler repository definitions. It should not be loaded directly by client workspaces. 15 | """ 16 | 17 | load( 18 | "//kotlin/internal:defs.bzl", 19 | _KT_COMPILER_REPO = "KT_COMPILER_REPO", 20 | ) 21 | load( 22 | "@bazel_tools//tools/build_defs/repo:http.bzl", 23 | _http_archive = "http_archive", 24 | _http_file = "http_file", 25 | ) 26 | 27 | BAZEL_JAVA_LAUNCHER_VERSION = "0.28.1" 28 | 29 | KOTLIN_CURRENT_COMPILER_RELEASE = { 30 | "urls": [ 31 | "https://github.com/JetBrains/kotlin/releases/download/v1.3.50/kotlin-compiler-1.3.50.zip", 32 | ], 33 | "sha256": "69424091a6b7f52d93eed8bba2ace921b02b113dbb71388d704f8180a6bdc6ec", 34 | } 35 | 36 | def kotlin_repositories(compiler_release = KOTLIN_CURRENT_COMPILER_RELEASE): 37 | """Call this in the WORKSPACE file to setup the Kotlin rules. 38 | 39 | Args: 40 | compiler_release: (internal) dict containing "urls" and "sha256" for the Kotlin compiler. 41 | """ 42 | _http_archive( 43 | name = _KT_COMPILER_REPO, 44 | urls = compiler_release["urls"], 45 | sha256 = compiler_release["sha256"], 46 | build_file = "@io_bazel_rules_kotlin//kotlin/internal/repositories:BUILD.com_github_jetbrains_kotlin", 47 | strip_prefix = "kotlinc", 48 | ) 49 | 50 | _http_file( 51 | name = "kt_java_stub_template", 52 | urls = [("https://raw.githubusercontent.com/bazelbuild/bazel/" + 53 | BAZEL_JAVA_LAUNCHER_VERSION + 54 | "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + 55 | "java_stub_template.txt")], 56 | sha256 = "e6531a6539ec1e38fec5e20523ff4bfc883e1cc0209eb658fe82eb918eb49657", 57 | ) 58 | -------------------------------------------------------------------------------- /kotlin/internal/repositories/repositories.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """This file contains the Kotlin compiler repository definitions. It should not be loaded directly by client workspaces. 15 | """ 16 | 17 | load("//kotlin/internal/repositories:setup.bzl", "kt_configure") 18 | load( 19 | "//kotlin/internal/repositories:release_repositories.bzl", 20 | "KOTLIN_CURRENT_COMPILER_RELEASE", 21 | _release_kotlin_repositories = "kotlin_repositories", 22 | ) 23 | 24 | def kotlin_repositories(compiler_release = KOTLIN_CURRENT_COMPILER_RELEASE): 25 | """Call this in the WORKSPACE file to setup the Kotlin rules. 26 | 27 | Args: 28 | compiler_release: (internal) dict containing "urls" and "sha256" for the Kotlin compiler. 29 | """ 30 | kt_configure() 31 | _release_kotlin_repositories(compiler_release) 32 | -------------------------------------------------------------------------------- /kotlin/internal/repositories/setup.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") 16 | load("@rules_jvm_external//:defs.bzl", "maven_install") 17 | load("//kotlin/internal/repositories:http_java_proto_file.bzl", "http_java_proto_file") 18 | 19 | def kt_configure(): 20 | """Setup dependencies. Must be called AFTER kt_download_local_dev_dependencies() """ 21 | maven_install( 22 | name = "kotlin_rules_maven", 23 | fetch_sources = True, 24 | artifacts = [ 25 | "org.jetbrains.kotlinx:atomicfu-js:0.13.1", 26 | "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.2", 27 | "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1", 28 | "com.google.code.findbugs:jsr305:3.0.2", 29 | "junit:junit:4.13-beta-3", 30 | "com.google.protobuf:protobuf-java:3.6.0", 31 | "com.google.protobuf:protobuf-java-util:3.6.0", 32 | "com.google.guava:guava:27.1-jre", 33 | "com.google.truth:truth:0.45", 34 | "com.google.auto.service:auto-service:1.0-rc5", 35 | "com.google.auto.service:auto-service-annotations:1.0-rc5", 36 | "com.google.auto.value:auto-value:1.6.5", 37 | "com.google.auto.value:auto-value-annotations:1.6.5", 38 | "com.google.dagger:dagger:2.26", 39 | "com.google.dagger:dagger-compiler:2.26", 40 | "com.google.dagger:dagger-producers:2.26", 41 | "javax.inject:javax.inject:1", 42 | "org.pantsbuild:jarjar:1.7.2", 43 | ], 44 | repositories = [ 45 | "https://maven-central.storage.googleapis.com/repos/central/data/", 46 | "https://repo1.maven.org/maven2", 47 | ], 48 | ) 49 | 50 | rules_proto_dependencies() 51 | rules_proto_toolchains() 52 | 53 | http_java_proto_file( 54 | name = "deps", 55 | sha256 = "b861dbce04177df9e4b7204876b2f27e18f40eb6d20b3dffefecdd2baf3cfe92", 56 | urls = ["https://raw.githubusercontent.com/bazelbuild/bazel/2.0.0/src/main/protobuf/deps.proto"], 57 | ) 58 | 59 | http_java_proto_file( 60 | name = "worker_protocol", 61 | sha256 = "1157c93666f98cfcfcc9f7b073b8dac5bbd50e18f5ab981e93c71e03ed08f304", 62 | urls = ["https://raw.githubusercontent.com/bazelbuild/bazel/2.0.0/src/main/protobuf/worker_protocol.proto"], 63 | ) 64 | -------------------------------------------------------------------------------- /kotlin/internal/utils/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 15 | 16 | release_archive( 17 | name = "pkg", 18 | srcs = glob(["*.bzl"]) + ["BUILD"], 19 | ) 20 | -------------------------------------------------------------------------------- /kotlin/internal/utils/packager.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_pkg//:pkg.bzl", "pkg_tar") 16 | 17 | def release_archive(name, srcs = None, src_map = {}, package_dir = None, extension = "tgz", deps = None): 18 | """ 19 | Creates an tar of the srcs, and renamed label artifacts. 20 | 21 | Usage: 22 | 23 | //:BUILD 24 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 25 | release_archive( 26 | name = "release_archive", 27 | src_map = { 28 | "BUILD.release.bazel.bazel": "BUILD.bazel", 29 | "WORKSPACE.release.bazel": "WORKSPACE", 30 | }, 31 | deps = [ 32 | "//dep:pkg" 33 | ], 34 | ) 35 | 36 | //dep:BUILD 37 | load("//kotlin/internal/utils:packager.bzl", "release_archive") 38 | release_archive( 39 | name = "pkg", 40 | srcs = [ 41 | ":label_of_artifact", 42 | ], 43 | ) 44 | 45 | 46 | Args: 47 | name: target identifier, points to a pkg_tar target. 48 | package_dir: directory to place the srcs, src_map, and dist_files under. Defaults to the current directory. 49 | dist_files: dict of : for files to be generated in the distribution artifact. 50 | src_map: dict of