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

Support for Kotlin #520

Open
2 of 4 tasks
abrams27 opened this issue May 12, 2023 · 12 comments
Open
2 of 4 tasks

Support for Kotlin #520

abrams27 opened this issue May 12, 2023 · 12 comments

Comments

@abrams27
Copy link
Contributor

abrams27 commented May 12, 2023

Describe the use-case for this feature

we'd like to support kotlin in our plugin, and in order to do that we need to obtain some info about the used sdk in the project

What do you propose

in the near future we will create a kotlin extension and PR with changes, probably we will need only additional data field with sdk info, and maybe some info about relationship between targets (are they in the same kotlin module - e.g. bazel associates https://bazelbuild.github.io/rules_kotlin/kotlin.html#kt_jvm_library) (but we need to investigate it a bit anyway)

I've checked to make sure there isn't already a way to support this in the current protocol

  • I've checked the existing protocol and there isn't a way to do this currently

Maintainer approval (This is for the maintainers)

  • Jetbrains
  • Metals
  • Scala Center
@tpasternak
Copy link
Contributor

tpasternak commented May 12, 2023

Just for the future - associates is in some way similar to go's embed https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/rules.md#go_binary-embed

@agluszak agluszak changed the title support for kotlin Support for Kotlin May 19, 2023
@Arthurm1
Copy link

Arthurm1 commented Dec 7, 2023

Is the Kotlin extension spec here? And is that pretty much final?

Also - what exactly is in the associates field and how does it differ from BuildTarget#dependencies. The Go embed link seems to suggest it's packaging related - so is this for some kind of fat jar setup? And how would a BSP client use this information - I would have thought that would all be hidden in the build tool/server and the client wouldn't care.

@agluszak
Copy link
Collaborator

agluszak commented Dec 7, 2023

@abrams27

@abrams27
Copy link
Contributor Author

abrams27 commented Dec 7, 2023

associates means that the targets will be compiled together in one "module" so you can use symbols with internal visibility (https://bazelbuild.github.io/rules_kotlin/kotlin#kt_jvm_library) on the client side this info is required (at least in intellij) since we map 1-1 build targets so it's required to handle internal visibility properly

@Arthurm1
Copy link

Arthurm1 commented Dec 7, 2023

@abrams27 Ah thanks. I don't know Kotlin and didn't realise internal was a visibility keyword.

@abrams27
Copy link
Contributor Author

abrams27 commented Dec 7, 2023

Is the Kotlin extension spec here? And is that pretty much final?

I wouldnt say that this impl is final, it works for us, but possibly it should be adjusted to feel more consistent with other langs, so prob we can add some endpoints instead of putting everything into data field of the build target

@lefou
Copy link
Contributor

lefou commented Dec 7, 2023

This is interesting. How do you provide associates to the Kotlin compiler? I maintain a Kotlin plugin for Mill, and I'm not aware of such compiler option.

@abrams27
Copy link
Contributor Author

abrams27 commented Dec 7, 2023

we dont pass it directly to the complier, on the server side bazel takes care of that, on the client side we pass it to the lang support plugin which has a field called additionalVisibleModuleNames

anyway on slack someone mentioned -Xfriend-paths=<friend-module-output> as a compiler option suitable for it

@lefou
Copy link
Contributor

lefou commented Dec 7, 2023

Yeah, I guess I'm actually more interested in the server side then. It looks a bit strange to me to control the friendship between modules via a keyword from the one side, but via a compiler setting from the other.

From it's documentation (https://kotlinlang.org/docs/visibility-modifiers.html#modules) it looks to me, internal is supposed to be used only in the same module (same BSP build target), so they result to be compiled together.

@abrams27
Copy link
Contributor Author

abrams27 commented Dec 7, 2023

yes but there are cases when it's a "fictional" thing - for example library and test, in bazel it's impossible to compile them together, but the test in the same package should be able to see the symbols, and the "module" split caused by the design of bazel should not block it (it's similar in gradle support in intellij),

on top of that in bazel it's common to create a lot of build targets, just for the sake of performance which dont have a real "structure" reason, they are there just to make caching faster

@lefou
Copy link
Contributor

lefou commented Dec 7, 2023

@abrams27 Yeah, that makes sense. Out of curiosity: Do you need to explicitly mark those associate modules in Bazel or it this some implicit setup for tests? Can you share an example? If this is some automatic thing, it might make sense to also implement it in mill-kotlin.

@abrams27
Copy link
Contributor Author

abrams27 commented Dec 7, 2023

you need to set it explicitly,
we have a bit of them in our tests: https://github.com/JetBrains/bazel-bsp/blob/ec256a99f85e1df882439308a6dbeb6951e28cd2/executioncontext/workspacecontext/src/test/kotlin/org/jetbrains/bsp/bazel/workspacecontext/BUILD#L7

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

No branches or pull requests

5 participants