https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
j

jmfayard

07/31/2022, 5:14 PM
Bonjour, how do you distribute on multiple platforms a CLI tool written with Kotlin-native? Last time I checked it was easier to publish via Kotlin-JS on npm... Or do you use your custom brew tap?
m

mbonnin

07/31/2022, 5:21 PM
I guess this is more a question for #cli but the audience there is super limited so here is certainly better 👍. Overall, my favourite solution so far has been shipping a small *.main.kts file that wraps the cli. More recently, I've had some success with HomeBrew. But this is obviously only macos...
@Big Chungus has been exploring a
npx
equivalent for Kotlin clis (cf gradle community discussion)
I wish there was something more simple but looks like npm is still your best bet when it comes to cross-platform distribution
j

jmfayard

07/31/2022, 5:24 PM
I have seen the
kscript <http://example.com/xxx/script.main.kts>
thing but I would like to call my tool frequently with just
$ goto
I think I will try brew + install.sh for people on Linux
m

mbonnin

07/31/2022, 5:29 PM
I've been contemplating the idea of doing "distribution as a library". Basically something like: • a minimal
install.sh
shell script that you can pipe from curl and: ◦ selects the correct distZip for a given architecture ◦ unzips it. ◦ calls it in bootstrap mode
./mycli bootstrap
./mycli bootstrap
would then: ◦ set the PATH ◦ set the autocompletion ◦ run any other install hooks • Later on,
./mycli update
would perform selfupdate
The beauty of this is that it doesn't need a separate package manager, it's all standalone. Just requires a
~/.mycli
folder where to do the install
j

jmfayard

07/31/2022, 5:34 PM
that works if we never need to add features to install.sh but if do then we won't be able to modify all forks of install.sh and regret to not have a proper package manager
I think I would prefer
kscript install jmfayard/kotlin-cli-starter
obviously that's a lot of work so I will try brew in the meantime
m

mbonnin

07/31/2022, 5:36 PM
Still requires your users to install
kscript
While curl is on each and every computer
j

jmfayard

07/31/2022, 5:37 PM
yes but each language community has its package manager, there is probably a good reason for that 🙂
m

mbonnin

07/31/2022, 5:37 PM
Except Kotlin 😞
j

jmfayard

07/31/2022, 5:37 PM
let say you want to auto-configure shell completion then you have to reinvent the wheel in
install.sh
while brew and clikt have you covered
m

mbonnin

07/31/2022, 5:38 PM
That's the thing!
install.sh
would delegate to your own CLI
The CLI would know how to bootstrap/auto-configure itself
install.sh
is a very simple script that just needs to detect the current arch, select the appropriate file and run it
j

jmfayard

07/31/2022, 5:39 PM
mmh then you can centralize installing shell completion in clikt that makes sense
m

mbonnin

07/31/2022, 5:41 PM
Yea, and dealing with zsh vs bash vs fish, unzipping a newer version, checking when a newer version is available in the background, etc.. all of that logic could be in a lib.
j

jmfayard

07/31/2022, 5:41 PM
I like it
maybe that could be proposed to the CliKt project?
m

mbonnin

07/31/2022, 5:44 PM
I wonder if there's value in not binding it to Clikt
j

jmfayard

07/31/2022, 5:45 PM
it could be a separate repo reusable by others
m

mbonnin

07/31/2022, 5:45 PM
Yea, I do love CliKt myself but if someone wants to use kotlinx.cli or nothing at all I don't see any reason they couldn't reuse the bootstraping lib
Now we just need the hardest part...
...a name 😅
j

jmfayard

07/31/2022, 7:50 PM
The only requirement is that it starts with a K no?
=>
kickstart
m

mbonnin

07/31/2022, 7:52 PM
kickstand
🚲
b

Big Chungus

07/31/2022, 10:25 PM
Native bin should use native distribution platforms, just like js bin uses js distribution platform (npm). Windows: winget package or msi installer Linux: rpm, deb or flatpak to cover all distros Mac: mainly brew
What would be useful here, is some cli tool to package native binary (not necessarily from k/n) into winget, flatpak and tap distributables. Surely there must be something out there already for that (seeing as c app would likely use the same tooling for this)
j

jmfayard

08/01/2022, 6:37 AM
@Big Chungus but that's way more work for the maker of the CLI tool last year I tried to make a brew recipe here and had to learn a ton of stuff for it to work https://github.com/jmfayard/kotlin-cli-starter/blob/main/kotlin-cli-starter.rb and then it got reject because I didn't realize you should make your own tap instead to contribute to homebrew directly For large CLI tools that's probably the best option but that would raise significantly the bar of when it's worth the effort to write a CLI tool in Kotlin you would spend more time on packaging than actually programming CLI tools in Python/Typescript many other use the package manager of their language instead of the native package installer and that's probably why
m

mbonnin

08/01/2022, 7:57 AM
Also if I'm going to install a cli, I don't want to double click a msi or dmg, I just want to stay in my terminal
b

Big Chungus

08/01/2022, 8:19 AM
That's just the burden of native world
j

jmfayard

08/01/2022, 8:20 AM
Why does it matter if it's native or not? When I use
tldr
from the command line, I have no idea if it's interpreted or compiled
b

Big Chungus

08/01/2022, 8:21 AM
Because the whole point of native is that it can run and install on it's own without assuming extra runtimes
j

jmfayard

08/01/2022, 8:23 AM
with a kickstart.sh script that uses curl you can run and install it without assuming extra runtimes
b

Big Chungus

08/01/2022, 8:24 AM
Yes, but you cannot install and update via "native" package managers for the platform
i.e. no auto updates and maintenance
j

jmfayard

08/01/2022, 8:24 AM
that's a good point yes
What would be useful here, is some cli tool to package native binary (not necessarily from k/n) into winget, flatpak and tap distributables. Surely there must be something out there already for that (seeing as c app would likely use the same tooling for this)
then I guess the question is whether other language communities comipling to native already have something to distribute executables that we could steal 🙂
b

Big Chungus

08/01/2022, 8:25 AM
If easy distribution is your must-have, stick with higher level runtimes. There's absolutely nothing wrong with that
Flatpak has a lot of helpful docs and tooling for sure
No clue about winget and brew
j

jmfayard

08/01/2022, 8:27 AM
kotlin.js with npm is actually pretty straigthforward
b

Big Chungus

08/01/2022, 8:27 AM
Yep, the benefit of runtime
j

jmfayard

08/01/2022, 8:28 AM
Flatpack + a guide about homebrew tap might do it
b

Big Chungus

08/01/2022, 8:29 AM
Or be a bit cheezy and only publish to homebrew (as it supports linux headless apps too)
Not many folks on linux have linuxbrew installed though
j

jmfayard

08/01/2022, 8:32 AM
it would also probably be helpful to have a homebrew tap for Kotlin CLI apps instead of everyone creating its own tap of one recipe
b

Big Chungus

08/01/2022, 8:33 AM
You mean like a template yml config (not familiar with how homebrew works at all)
j

jmfayard

08/01/2022, 8:34 AM
Homebrew doesn't allow you to self-publish your stuff, so you have to create your own repository. Usually with one recipe. Would be better to have a community one https://github.com/jmfayard/homebrew-tap
m

mbonnin

08/01/2022, 8:42 AM
I don't know about a community brew tap. It's pretty straightforward to download from a user tap:
brew install jmfayard/super-cli
What's the value of doing
brew install kotlincommunity/super-cli
instead?
Curation maybe? But that is some work
j

jmfayard

08/01/2022, 8:43 AM
one repository instead of 10 repositories ? discoverability helpful docs on how to do it
m

mbonnin

08/01/2022, 8:44 AM
How to do what? Installing the cli?
I always go to the project homepage and get the instructions from there
Agree on discoverability albeit it comes with a high price (having maintainers to maintain the community repo)
j

jmfayard

08/01/2022, 8:45 AM
how to produce the Ruby recipe for a Kotlin tool specifically instead to read the complete huge doc
just trying to lower the barrier to entry
m

mbonnin

08/01/2022, 8:45 AM
Ah yes, that is cool. But that can be a separate repo
It's mostly doc
j

jmfayard

08/01/2022, 8:45 AM
totally
44 Views