Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/v79/knworld
Kotlin Native for Pi
https://github.com/v79/knworld
Last synced: 6 days ago
JSON representation
Kotlin Native for Pi
- Host: GitHub
- URL: https://github.com/v79/knworld
- Owner: v79
- Created: 2020-11-01T13:06:13.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-05T21:16:50.000Z (about 4 years ago)
- Last Synced: 2024-12-25T05:52:41.340Z (10 days ago)
- Language: Kotlin
- Size: 479 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# KNWorld - Experiments in Cross-Compilation
This is a test project for Kotlin Native. I've written a simple Kotlin program (inspired by the code at https://kotlinlang.org/docs/tutorials/native/using-intellij-idea.html) and modified it to work. My goal is to cross-compile from Windows to Raspberry Pi.
### Sources
I've duplicated the source code in `src\main\nativeMain` and `src\mainPiMain` - the only difference is the output, which states whether the compilation was from `native` or `pi`.
### Gradle
I've modified `build.gradle.kts` a little, as the examples on Kotlin's website did not work for me. I have added a new target called *Pi*, like this:
```kotlin
linuxArm32Hfp("Pi") {
binaries {
executable {
entryPoint = "main"
}
}
}
```### Compilation
To build the 'native' binary (i.e. an executable for the machine you are currently running), just run `gradle nativeBinaries`.
To build for the Raspberry Pi, execute `gradle PiBinaries`.
The resulting executable file called 'KNWorld.kexe' can be found in `build\bin\native\releaseExecutable` and `build\bin\Pi\releaseExecutable`.
Copy the Pi version of KNWorld.kexe to your Raspberry Pi. I've even added extra steps to verify this is a Linux binary build from my host - Windows - machine.
```shell script
pi@raspberrypi:~/PiShare $ uname -a
Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux
pi@raspberrypi:~/PiShare $
pi@raspberrypi:~/PiShare $ file KNWorld.kexe
KNWorld.kexe: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[xxHash]=a487af0917a9a720, not stripped
pi@raspberrypi:~/PiShare $ ./KNWorld.kexe
PiMain: Hello, enter your name:
Liam Davison
Your name contains 11 letters
Your name contains 9 unique letters
pi@raspberrypi:~/PiShare $
```Voila, cross-compilation from MS Windows X64 to Raspbian ARM 32Hfp Pi code. No Windows Subsystem for Linux was used in this code.
The next step is to start integrating C libraries _from the Pi_ into the build process, but that's tearing my hair out and is, apparently, not possible from Windows.