Not sure where to ask this: what's the biggest pos...
# multiplatform
m
Not sure where to ask this: what's the biggest possible
String
literal in Kotlin? Given multiplatform resources are not really a thing, how bad of an idea is it to store large texts/images in
String
literals?
πŸ‘€ 1
j
On the JVM it'll be 65536
m
Doesn't Kotlin have some compiler magic to split large strings though?
I think I saw this somewhere but can't find the reference anymore so maybe I just smoked it
j
Not that I'm aware of. That would break
const
usages such as passing as annotation values
I would be surprised to see a maximum length for native or JS
Beyond the normal maximum of like 2^53-1 or something
m
I can compile a 100k String so that seems to work
I guess I cannot make it a
@JvmField
I can actually, the
StringBuilder
magic is done in the initializer for something like this:
Copy code
val hugeString = """
  // very long string
"""
Back to my initial point about storing resources in there, it looks like I'll pay a small performance price but the convenience of it might be worth it
If anyone's curious about large string splitting for the JVM (and also for my future self), this is where it's done in the compiler
m
What is your primary intention to consider that? Wouldn’t the second option mentioned here https://kotlinlang.slack.com/archives/C01D6HTPATV/p1674811279172749?thread_ts=1674787761.307139&cid=C01D6HTPATV not be the better option if it works?
m
Thanks! Didn't know about
compose-jb
resources! My needs is that I need to ship these resources as part as a library so I need a multiplatform way to embed them in .jars, .klibs, etc... I wasn't sure the formats allowed this but I'll investigate πŸ•΅οΈ
d
Given multiplatform resources are not really a thing
MokoResources is my go-to for this; it's rather useful, covering mobiles, Desktop and JS
m
@darkmoon_uk MokoResources is not really what I'm looking for. From what I understand, it's mostly for app developers, I'd like something for lib developers. I don't think MR can embedded strings in a
.klib
, right? Only frameworks?
m
@mbonnin have you found a solution? Currently having the same problem while building a library and trying to somehow add needed resources into
klib
.
m
@MJegorovas not really, I gave up on this idea for now. Might come back to it at some point
m
Sorry to necro-bump this thread, but did you ever find a solution for packaging resources in a
.klib
@mbonnin? I have a prebuilt executable that I wish to ship with my library for darwin/linux targets, so it can be extracted and then executed at runtime.
m
No solution, sorry. "Base64 encode your executable and add it as a string" is the only thing that comes to mind right now. This will put your whole executable in RAM but given that any binary allocates gigabytes now, it's probably ok
m
I considered doing that, but each file is 5-8mb sad panda
m
Slack allocates gigabytes. It's probably OK for your app to allocate 8MB. It's not even the size of a picture these days
m
Well, it'll be 1 file for every target (they're executables compiled for each platform/arch)
m
But you're not going to decompress them in parallel, do you? It's only going to allocate when you extract and copy/execute
I would expect the mach-O/elf binary to be mmaped so the .data section is on storage, not RAM (no idea if it's actually working like that under the hood but that'd be my assumption)
I'm curious if you try it, let us know how that goes
m
So, β€’ compile the platform specific executables β€’ codesign/notarize darwin targets β€’ gradle task reads and writes base64 chunks to a
.kt
file β€’ At runtime that gets written to specified directory. Insanity, but doable
m
Yep, something like so. Write a blog post if you do πŸ™‚
m
Yeah I saw that. Doesn't seem like a high priority at the moment.
nod 1
Finally able to start in on tackling this. Any suggestions or ideas would be much appreciated! https://github.com/05nelsonm/kmp-tor-binary/issues/120#issue-2001297235
There she is @mbonnin https://github.com/05nelsonm/kmp-tor-binary/pull/136 Command line tool for converting any file into a
NativeResource
. Still have work to do on extraction of that resource to the application filesystem, but it's pretty slick (i think at least)
πŸŽ‰ 1
Lmao, finally wrapped up that work (had to build another library for something else). Native resources decompression and writing to the filesystem. https://github.com/05nelsonm/kmp-tor-binary/pull/155
πŸ‘€ 1
So, the static
.a
binaries include the shared libs which can now be extracted to the filesystem and be executed in a child process. Jesus what a headache.
m
mind blown
πŸ˜„ 1
OMG, this is both scary and genius πŸ™‚
Might be worth not checking in as source files in source control (ie keep the binary checked in, generate the
.kt
at build time?)
m
Yeah, need to think of something. Primary thing I want to do is maintain build reproducability (so others running
tor
will be able to easily verify with like, 3 shell commands + docker).
πŸ‘ 1
It's a pretty multi-faceted coordination problem
Hey how do I purge this from the git history, lol? Anyone cloning this repo is going to hate life.
just force push to master πŸ˜† ?
m
WE have a couple of .jar files from 2015 that account for half the size of the repo πŸ˜…
Since you just pushed, I assume force push now is better than in 5 years from now
πŸ’― 1
m
πŸ˜…
πŸŽ‰ 1