Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor compiler configuration repositories #900

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
validate_config: 1
bazel: 6.0.0-pre.20221020.1
bazel: 6.0.0
buildifier:
version: 5.1.0
# no lint warnings for the moment. They are basically a smoke alarm in hell.
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.0-pre.20221020.1
6.0.0
12 changes: 0 additions & 12 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//src/main/starlark/release:packager.bzl", "release_archive")
load("//src/main/starlark/core/repositories:versions.bzl", "versions")
load("//kotlin:lint.bzl", "ktlint_config")

exports_files([
Expand Down Expand Up @@ -52,20 +51,9 @@ test_suite(
],
)

[
release_archive(
name = version,
deps = [
"@%s//:pkg" % version,
],
)
for version in versions.CORE
]

# Release target.
release_archive(
name = "rules_kotlin_release",
srcs = ["%s.tgz" % v for v in versions.CORE],
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
"WORKSPACE.release.bazel": "WORKSPACE",
Expand Down
12 changes: 0 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ The `rules_kotlin` runtime is comprised of multiple repositories. The end user w
versioned feature sub-repositories. Currently, the delegation is managed by using well known names (e.g. core lives in `@io_bazel_rules_kotlin_configured`),
a necessity while the initial repository can be named arbitrarily. Future development intends to remove this restriction.

### Versioning

To cope with API churn, the release archive can configure different rule attributes for depending on the chosen kotlin version.
Each major release of kotlin (1.4, 1.5) has a specific sub-repository under [src/main/starlark](src/main/starlark). The naming convention for these
is `rkt_<major>_<minor>` ([r]elease [k]o[t]lin).

The version is selected by the [kotlin_repositories](src/main/starlark/repositories/initialize.release.bzl) rule during initialization.
New versions of kotlin that change the API should be added to [versions.bzl](src/main/starlark/repositories/versions.bzl), under `CORE` following the
existing naming convention.

Multiple versions of kotlin are not currently handled.(_help wanted_)

## Idioms and Styles
TBD

Expand Down
3 changes: 1 addition & 2 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ This macro registers the kotlin toolchain.
## kotlin_repositories

<pre>
kotlin_repositories(<a href="#kotlin_repositories-compiler_repository_name">compiler_repository_name</a>, <a href="#kotlin_repositories-compiler_release">compiler_release</a>, <a href="#kotlin_repositories-configured_repository_name">configured_repository_name</a>)
kotlin_repositories(<a href="#kotlin_repositories-compiler_repository_name">compiler_repository_name</a>, <a href="#kotlin_repositories-compiler_release">compiler_release</a>)
</pre>

Call this in the WORKSPACE file to setup the Kotlin rules.
Expand All @@ -497,6 +497,5 @@ Call this in the WORKSPACE file to setup the Kotlin rules.
| :------------- | :------------- | :------------- |
| <a id="kotlin_repositories-compiler_repository_name"></a>compiler_repository_name | for the kotlinc compiler repository. | <code>"com_github_jetbrains_kotlin"</code> |
| <a id="kotlin_repositories-compiler_release"></a>compiler_release | version provider from versions.bzl. | <code>struct()</code> |
| <a id="kotlin_repositories-configured_repository_name"></a>configured_repository_name | for the default versioned kt_* rules repository. If None, no versioned repository is created. | <code>"io_bazel_rules_kotlin_configured"</code> |


4 changes: 2 additions & 2 deletions examples/anvil/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ http_archive(

http_archive(
name = "rules_pkg",
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
)

http_archive(
Expand Down
4 changes: 2 additions & 2 deletions examples/associates/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ maven_install(

http_archive(
name = "rules_pkg",
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
)
4 changes: 2 additions & 2 deletions examples/trivial/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ maven_install(

http_archive(
name = "rules_pkg",
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
)
7 changes: 1 addition & 6 deletions kotlin/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains")
load("//src/main/starlark/release:packager.bzl", "release_archive")
load("//src/main/starlark/core/repositories:versions.bzl", "versions")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

# Configures the toolchains
Expand All @@ -23,11 +22,9 @@ release_archive(
name = "pkg",
srcs = glob(
["*.bzl"],
exclude = ["opts.bzl"],
),
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
"opts.release.bzl": "opts.bzl",
},
deps = [
"//kotlin/internal/js:pkg",
Expand All @@ -47,8 +44,6 @@ bzl_library(
"//kotlin/internal/lint",
"//kotlin/internal/utils",
"//src/main/starlark",
] + [
"@%s//starlark" % v
for v in versions.CORE
"@com_github_jetbrains_kotlin//:capabilities_bzl",
],
)
4 changes: 2 additions & 2 deletions kotlin/internal/opts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.

load(
"@rkt_1_7//starlark/kotlin:opts.bzl",
":opts.kotlinc.bzl",
_KotlincOptions = "KotlincOptions",
_kotlinc_options_to_flags = "kotlinc_options_to_flags",
_kt_kotlinc_options = "kt_kotlinc_options",
)
load(
"@rkt_1_7//starlark/jvm:opts.bzl",
":opts.javac.bzl",
_JavacOptions = "JavacOptions",
_javac_options_to_flags = "javac_options_to_flags",
_kt_javac_options = "kt_javac_options",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
load("@dev_io_bazel_rules_kotlin//src/main/starlark/core/options:derive.bzl", "derive")
load("@dev_io_bazel_rules_kotlin//src/main/starlark/core/options:convert.bzl", "convert")
# Copyright 2022 The Bazel Authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to src/main/starlark and import from there.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//src/main/starlark/core/options:derive.bzl", "derive")
load("//src/main/starlark/core/options:convert.bzl", "convert")

_JOPTS = {
"warn": struct(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
load("@dev_io_bazel_rules_kotlin//src/main/starlark/core/options:convert.bzl", "convert")
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//src/main/starlark/core/options:convert.bzl", "convert")
load("@com_github_jetbrains_kotlin//:capabilities.bzl", _KOTLIN_OPTS = "KOTLIN_OPTS")

def _map_optin_class_to_flag(values):
return ["-opt-in=%s" % v for v in values]
Expand All @@ -13,7 +28,7 @@ def _map_jvm_target_to_flag(version):
return None
return ["-jvm-target=%s" % version]

_KOPTS = {
_KOPTS_ALL = {
"warn": struct(
args = dict(
default = "report",
Expand Down Expand Up @@ -41,6 +56,7 @@ _KOPTS = {
},
),
"x_skip_prerelease_check": struct(
flag = "-Xskip-prerelease-check",
args = dict(
default = False,
doc = "Suppress errors thrown when using pre-release classes.",
Expand All @@ -51,6 +67,7 @@ _KOPTS = {
},
),
"x_inline_classes": struct(
flag = "-Xinline-classes",
args = dict(
default = False,
doc = "Enable experimental inline classes",
Expand All @@ -61,6 +78,7 @@ _KOPTS = {
},
),
"x_allow_result_return_type": struct(
flag = "-Xallow-result-return-type",
args = dict(
default = False,
doc = "Enable kotlin.Result as a return type",
Expand All @@ -71,6 +89,7 @@ _KOPTS = {
},
),
"x_jvm_default": struct(
flag = "-Xjvm-default",
args = dict(
default = "off",
doc = "Specifies that a JVM default method should be generated for non-abstract Kotlin interface member.",
Expand All @@ -87,6 +106,7 @@ _KOPTS = {
},
),
"x_no_call_assertions": struct(
flag = "-Xno-call-assertions",
args = dict(
default = False,
doc = "Don't generate not-null assertions for arguments of platform types",
Expand All @@ -97,6 +117,7 @@ _KOPTS = {
},
),
"x_no_param_assertions": struct(
flag = "-Xno-param-assertions",
args = dict(
default = False,
doc = "Don't generate not-null assertions on parameters of methods accessible from Java",
Expand All @@ -107,6 +128,7 @@ _KOPTS = {
},
),
"x_no_receiver_assertions": struct(
flag = "-Xno-receiver-assertions",
args = dict(
default = False,
doc = "Don't generate not-null assertion for extension receiver arguments of platform types",
Expand All @@ -117,16 +139,18 @@ _KOPTS = {
},
),
"x_no_optimized_callable_references": struct(
flag = "-Xno-optimized-callable-references",
args = dict(
default = False,
doc = "Do not use optimized callable reference superclasses. Available from 1.4.",
),
type = attr.bool,
value_to_flag = {
True: ["-Xno-optimized-callable-reference"],
True: ["-Xno-optimized-callable-references"],
},
),
"x_explicit_api_mode": struct(
flag = "-Xexplicit-api",
args = dict(
default = "off",
doc = "Enable explicit API mode for Kotlin libraries.",
Expand All @@ -150,6 +174,7 @@ _KOPTS = {
},
),
"x_multi_platform": struct(
flag = "-Xmulti-platform",
args = dict(
default = False,
doc = "Enable experimental language support for multi-platform projects",
Expand All @@ -160,6 +185,7 @@ _KOPTS = {
},
),
"x_sam_conversions": struct(
flag = "-Xsam-conversions",
args = dict(
default = "class",
doc = "Change codegen behavior of SAM/functional interfaces",
Expand All @@ -172,6 +198,7 @@ _KOPTS = {
},
),
"x_lambdas": struct(
flag = "-Xlambdas",
args = dict(
default = "class",
doc = "Change codegen behavior of lambdas",
Expand All @@ -184,6 +211,7 @@ _KOPTS = {
},
),
"x_emit_jvm_type_annotations": struct(
flag = "-Xemit-jvm-type-annotations",
args = dict(
default = False,
doc = "Basic support for type annotations in JVM bytecode.",
Expand All @@ -202,7 +230,21 @@ _KOPTS = {
value_to_flag = None,
map_value_to_flag = _map_optin_class_to_flag,
),
"x_use_fir": struct(
# 1.6
flag = "-Xuse-fir",
args = dict(
default = False,
doc = "Compile using the experimental Kotlin Front-end IR. Available from 1.6.",
),
type = attr.bool,
value_to_flag = {
True: ["-Xuse-fir"],
},
),
"x_use_k2": struct(
# 1.7
flag = "-Xuse-k2",
args = dict(
default = False,
doc = "Compile using experimental K2. K2 is a new compiler pipeline, no compatibility guarantees are yet provided",
Expand All @@ -213,6 +255,7 @@ _KOPTS = {
},
),
"x_no_optimize": struct(
flag = "-Xno-optimize",
args = dict(
default = False,
doc = "Disable optimizations",
Expand All @@ -223,6 +266,8 @@ _KOPTS = {
},
),
"x_backend_threads": struct(
# 1.6.20, 1.7
flag = "-Xbackend-threads",
args = dict(
default = 1,
doc = "When using the IR backend, run lowerings by file in N parallel threads. 0 means use a thread per processor core. Default value is 1.",
Expand All @@ -232,6 +277,7 @@ _KOPTS = {
map_value_to_flag = _map_backend_threads_to_flag,
),
"x_report_perf": struct(
flag = "-Xreport-perf",
args = dict(
default = False,
doc = "Report detailed performance statistics",
Expand All @@ -253,6 +299,9 @@ _KOPTS = {
),
}

# Filters out options that are not available in current compiler release
_KOPTS = {attr: defn for (attr, defn) in _KOPTS_ALL.items() if not hasattr(defn, "flag") or defn.flag in _KOTLIN_OPTS}

KotlincOptions = provider(
fields = {
name: o.args["doc"]
Expand Down
Loading