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

Generic way to pass -Xopt-in #603

Closed
Kernald opened this issue Oct 19, 2021 · 2 comments
Closed

Generic way to pass -Xopt-in #603

Kernald opened this issue Oct 19, 2021 · 2 comments

Comments

@Kernald
Copy link
Contributor

Kernald commented Oct 19, 2021

Some libraries outside of Jetbrains' are beginning to make use of Kotlin's opt-in mechanism. Clients have two options to deal with those:

  • Adding a @OptIn(my.opt.InClass::class) or equivalent annotation to classes using features guarded by an opt-in requirement, or
  • Passing -Xopt-in=my.opt.InClass to kotlinc.

While the first one works fine, it results in potentially lots of clutter if a codebase decides to opt-in a library like kotlinx-datetime. More importantly, it doesn't work for generated code.

From what I understand, the current implementation of kt_kotlinc_options (https://github.com/bazelbuild/rules_kotlin/blob/master/src/main/starlark/rkt_1_5/kotlin/opts.bzl) doesn't allow free text values for flags, so it's not as simple as adding a x_opt_in entry there.

@pettermahlen
Copy link
Contributor

This would be awesome to get. Two comments, which may be obvious already (apologies if so):

  • based on my understanding, the 'normal' use of the -Xopt-in flag is to pass it multiple times to the compiler, meaning that it's usually additive (you can decide to opt in to ExperimentalSerializationApi separately from the kotlin.OptIn annotation). Not sure if that changes anything in the implementation or how to use it in BUILD.bazel files.
  • the kotlin.OptIn annotation itself requires opting in, see https://kotlinlang.org/docs/opt-in-requirements.html#experimental-status-of-the-opt-in-requirements. So at a minimum, if you want to opt in to an experimental library, you need to pass two annotations.

@restingbull
Copy link
Collaborator

Fixed by #676

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants