Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add very basic Kotlin/JS support: ability to compile the binary (#3678)
Another part for #3611. This PR adds a very basic foundation for the Kotlin/JS support. The code provided allows to: * Build code with `org.jetbrains` (most likely) dependencies only * Run it with Node (no browser support) * Execute tests (using `kotlinx-test` so far), but without any test results collection/tests selector, etc. However, I think that full Kotlin/JS support **will take a lot of time**, because even if there is a Scala.JS counterpart available, the way these technologies work is very different (distribution, format, etc.) Issues I've encountered: * Kotlin 2+ is not supported, because with Kotlin 2+ jars are not published anymore and there is only `klib` file available (see https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/2.0.0/). When Gradle is used, it is able to fetch it using attributes declared in `.module` file, but Coursier is not able to recognize and fetch it. * Kotlin versions below 1.8.20 are not supported, because of the different set of compiler arguments. With the certain effort it is possible to go further in supporting older versions, but I'm not sure if it is needed: since Mill is somewhat experimental, probably there is no need for the users to use old Kotlin versions. * Even if some Kotlin/JS library has `jar` file published with Kotlin/JS library inside, it may be rejected by the compiler. For example, this https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-html-js/0.8.0/ has the necessary `jar` file with `.meta.js` / `.kjsm` files inside, but it is rejected by the compiler of Kotlin 1.8/1.9. Here https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/1.9.24/, for example, nothing is rejected, so I suppose there is an issue in the ABI/metadata version. Not sure how it can be solved (maybe by relying only on `klib`? But `klib` cannot be fetched by Coursier). * Gradle Kotlin plugin is utilizing NPM dependencies to generate `package.json` and add the necessary JS test frameworks/runners there if executed in Node environment, or even webpack for Browser environment. This is also a big chunk of work to be done. For now I've added only test binary execution, but there is no test results collection / test selector. * Kotest cannot be used, because with version 5 only `klib` is published, and `jar` of version 4 is not compatible with the 1.8/1.9 IR compiler. * ~~Kotlin/JS IR compiler has different modes: it can output either IR/Klib or can produce final JS (basically IR+linking). Kotlin Gradle plugin is using 2 passes: to generate IR and then produce final JS. I guess it is done for the better performance / better incremental support, but I, for the initial drop, rely on a single pass (IR+linking in a single compiler invocation) => **need to make `compile` task to produce only IR code and add kind of `link` task to produce executable in the future.**~~ => addressed in the 2nd commit. --------- Co-authored-by: 0xnm <[email protected]> Co-authored-by: Li Haoyi <[email protected]>
- Loading branch information