Skip to content
Dmitry Savvinov edited this page Nov 9, 2022 · 12 revisions

Setting up the environment

  1. Download the latest Kotlin Distribution kotlin-compiler-<version> (I've checked everything on 1.7.20 version) from GitHub Releases page and unpack its content (kotlinc) to buildInfra/tools.

    Note that there are kotlinc-metadata and kotlinc-metadata.bat shellscripts in buildInfra/tools/kotlinc/bin already. This is because we don't distribute them for now. This will be fixed in future updates.

  2. Currently. Kotlin Distribution doesn't ship with kotlin-stdlib-common.jar. This will be fixed in further updates. For now, kotlin-stdlib-common.jar from Kotlin 1.7.20 is pre-packed to the repo. If you need a different version, just download it manually from Maven and replace kotlin-stdlib-common.jar in buildInfra/tools/kotlinc/lib

  3. From the same release, download the kotlin-native-<your-host>-<version>.zip (I've used macos-aarch64 for testing), unpack its contents to buildInfra/tools and rename it to just kotlin-native.

  4. Sometimes, macOS might be over-paranoid and forbid to use .dylibs in the buildInfra/tools/kotlin-native/konan/nativeLib. You will see that as macOS warning <Binary name> can't be opened because Apple cannot check it for malicious software. This software needs to be updated. Contact the developer for more information. All the generic fixes from internet should work, the one I used: open binary manually from Finder, macOS will properly prompt you if you want to open it. Choose "Open" and it will be remembered as an exception

There's the resulting file structure you should get:

buildInfra
├── logic
├── output
└── tools
    ├── kotlin-native
    └── kotlinc
        ├── bin
        │   ├── ...
        │   ├── kotlinc-metadata
        │   ├── kotlinc-metadata.bat
        │   └── ...
        ├── build.txt
        ├── lib
        │   ├── ...
        │   ├── kotlin-stdlib-common.jar
        │   └── ...
        └── license

Usage of kmmBuilder

This project provides a simple program, called kmmBuilder, written in Kotlin, which invokes Kotlin Compiler and other low-level tools, on a simple dummy projects. Basically, you can see it as an extremely stupid build script. Read here how to play with it

⚠️ NB! Provided tasks don't check their dependencies. E.g. if you try to PACK_JVM before ASSEMBLE_JVM, build will fail with some error or exception. If you want to learn about tasks dependencies, check test-folder in logic project

Option 1. Assemble and use CLI

  1. Navigate to buildInfra/logic folder

  2. Build the CLI for kmmBuilder:

~/barebones-kotlin-multiplatform/buildInfra/logic
❯ ./gradlew installDist
  1. Go to assembled CLI distribution:
~/barebones-kotlin-multiplatform/buildInfra/logic
❯ cd build/install/kmmBuilder/bin
  1. Launch kmmBuilder executable
~/barebones-kotlin-multiplatform/buildInfra/logic/build/install/kmmBuilder/bin default ⇡
❯ ./kmmBuilder
Error: No project specified

Usage:
    kmmBuilder <PROJECT> <TASK>

Available projects:
   <... read about CLI invocation here ...>

Option 2. Launch application via Gradle

  1. Navigate to buildInfra/logic folder

  2. Launch application via Gradle ./gradlew run --args="<USUAL CLI ARGS GO HERE>", example:

~/barebones-kotlin-multiplatform/buildInfra/logic
❯ ./gradlew run --args="TRANSITIVE ASSEMBLE_JVM"

> Task :run
Invoking KotlincJvm with -Xcommon-sources=/Users/dmitry.savvinov/Repos/barebones-kotlin-multiplatform/sources/TransitiveDependency/src/commonMain -Xmulti-platform -classpath /Users/dmitry.savvinov/Repos/barebones-kotlin-multiplatform/buildInfra/tools/kotlinc/lib/kotlin-stdlib.jar:/Users/dmitry.savvinov/Repos/barebones-kotlin-multiplatform/buildInfra/tools/kotlinc/lib/kotlin-stdlib-jdk7.jar:/Users/dmitry.savvinov/Repos/mbarebones-kotlin-multiplatform/buildInfra/tools/kotlinc/lib/kotlin-stdlib-jdk8.jar -d /Users/dmitry.savvinov/Repos/barebones-kotlin-multiplatform/buildInfra/output/TransitiveDependency/assembly/jvmMain /Users/dmitry.savvinov/Repos/barebones-kotlin-multiplatform/sources/TransitiveDependency/src/jvmMain /Users/dmitry.savvinov/Repos/barebones-kotlin-multiplatform/sources/TransitiveDependency/src/commonMain

BUILD SUCCESSFUL in 2s
2 actionable tasks: 1 executed, 1 up-to-date

Option 3. Run tests from IDE

  1. Open the logic project in IntelliJ IDEA or any IDE of your choice
  2. There are classes AssembleTests and PackTests with runnable "test"-methods inside, you can launch them as usual tests.

Those "tests" don't assert anything, they are used just as simple entry points