Decouple Build And Packaging

by ADMIN 29 views

Introduction

In the current Kotlin Multiplatform DSL, the build options and packaging options are handled in a single CargoBuild block. However, this approach has several limitations and issues, especially when it comes to sandboxed Mac Apps, NodeJS libraries, and iOS dynamic libraries. In this article, we will propose a new DSL API to decouple build and packaging options, making it easier to manage and optimize Kotlin Multiplatform projects.

Problem Statement

The current DSL has several problems that need to be addressed:

Kotlin/JVM

  • Embedding Rust libraries as resources: Currently, we're embedding the Rust libraries as a resource, which is not ideal, especially for sandboxed Mac Apps. JNA tries to copy the resource to a temporary folder and open it, which can lead to issues.
  • Investigation of Project Panama and GraalVM: We still need to investigate the possibilities of Project Panama and GraalVM to improve the build and packaging process.

Kotlin/JS

  • WASM and native libraries: For libraries targeting NodeJS, both using WASM (via WebAssembly) and native libraries (via ffi) are possible. However, we need to provide a DSL to integrate them with bundlers.
  • Tools like wasm-bindgen: Some users may use tools like wasm-bindgen, which generates JS files, and we need to provide a DSL to integrate them with bundlers.

Kotlin/Native

  • Static linking: Static linking takes a lot of time, and some users may want to use dynamic libraries instead.
  • iOS dynamic libraries: iOS dynamic libraries need signing, which adds an extra step to the build process.

Miscellaneous

  • Inheritance relations of subtypes of CargoBuild: The inheritance relations of subtypes of CargoBuild are too complicated and may be simplified.

Proposed Solution

To address the issues mentioned above, we propose introducing a new block, packaging {} inside the cargo {} block, which exposes CargoPackaging as a receiver. This new API will allow us to decouple build and packaging options, making it easier to manage and optimize Kotlin Multiplatform projects.

cargo {
  packaging {
    android { ... }
    jvm { ... }
    native { ... }
    js { ... }
    wasm { ... }
  }
}

CargoPackaging will reference CargoTarget (or CargoBuild) and another new API, CargoPackagingTarget. CargoPackagingTarget may have a one-to-one relation with KotlinTarget.

Benefits of the Proposed Solution

The proposed solution has several benefits:

  • Decoupling build and packaging options: By introducing a new block for packaging options, we can decouple build and packaging options, making it easier to manage and optimize Kotlin Multiplatform projects.
  • Improved flexibility: The new API will provide more flexibility in terms of build and packaging options, allowing users to choose the best approach for their specific use case.
  • Simplified inheritance relations: The new API will simplify the inheritance relations of subtypes of CargoBuild, making it easier to understand and work with the DSL.

Conclusion

In conclusion, the proposed solution will improve the build and packaging process for Kotlin Multiplatform projects by decoupling build and packaging options. The new API will provide more flexibility, simplify the inheritance relations of subtypes of CargoBuild, and make it easier to manage and optimize Kotlin Multiplatform projects.

Future Work

Future work will focus on implementing the proposed solution and testing it thoroughly. We will also investigate the possibilities of Project Panama and GraalVM to improve the build and packaging process.

References

Introduction

In our previous article, we proposed a new DSL API to decouple build and packaging options in Kotlin Multiplatform projects. In this article, we will answer some frequently asked questions about the proposed solution.

Q&A

Q: What is the main problem with the current DSL?

A: The current DSL has several problems, including:

  • Embedding Rust libraries as resources, which is not ideal for sandboxed Mac Apps.
  • Limited flexibility in terms of build and packaging options.
  • Complicated inheritance relations of subtypes of CargoBuild.

Q: How will the proposed solution address these issues?

A: The proposed solution will address these issues by:

  • Introducing a new block, packaging {} inside the cargo {} block, which exposes CargoPackaging as a receiver.
  • Decoupling build and packaging options, making it easier to manage and optimize Kotlin Multiplatform projects.
  • Simplifying the inheritance relations of subtypes of CargoBuild.

Q: What are the benefits of the proposed solution?

A: The proposed solution has several benefits, including:

  • Improved flexibility in terms of build and packaging options.
  • Simplified inheritance relations of subtypes of CargoBuild.
  • Easier management and optimization of Kotlin Multiplatform projects.

Q: How will the proposed solution affect existing projects?

A: The proposed solution will not affect existing projects in a significant way. However, users will need to update their build scripts to use the new packaging {} block.

Q: What is the expected timeline for implementing the proposed solution?

A: We expect to implement the proposed solution in the near future, with a timeline of several months.

Q: How will the proposed solution be tested?

A: We will thoroughly test the proposed solution to ensure that it works as expected and does not introduce any new issues.

Q: What is the expected impact of the proposed solution on the Kotlin Multiplatform ecosystem?

A: We expect the proposed solution to have a positive impact on the Kotlin Multiplatform ecosystem, making it easier to manage and optimize projects and providing more flexibility in terms of build and packaging options.

Conclusion

In conclusion, the proposed solution will improve the build and packaging process for Kotlin Multiplatform projects by decoupling build and packaging options. We hope that this Q&A article has answered some of the questions you may have had about the proposed solution.

Future Work

Future work will focus on implementing the proposed solution and testing it thoroughly. We will also investigate the possibilities of Project Panama and GraalVM to improve the build and packaging process.

References