I have a multiplatform project where the JVM imple...
# kotlin-native
l
I have a multiplatform project where the JVM implementation embeds some datafiles (JSON files, in this particular case) as resources which I load using the classloader. I need to do the same in the native backend, but I can't find a good way to do it. Ideally, I'd want to just link it as an ELF object, but that doesn't actually seem possible. Is there some nice gradle way I can transform the content to a string that becomes accessible as a variable during runtime? Or is there some other solution? What I really don't want to do is to convert the (rather large, some 10's of MB) text file into a string and saving it as a
.kt
source file.
a
I've been curious about this. I saw that C has a new-ish #embed directive, and it's supported in llvm 19 which Kotlin 2.2.0 uses. It seems ideal for this use-case.
l
Oh, right. I wonder if I can use it from a .def file?
a
I think so. Going by the examples.... In the .def file, at the bottom after the
---
, use the
#embed
directive.
Copy code
# (k/n config)

---

const unsigned char arr[] = {
#embed <art.txt>
};
And in the compilation args specify the directory that contains `art.txt`:
-embed-dir=./path/to/media/
.
But I've yet to try it out!
l
I'll try it in my project after I commit the test cases I'm adding for another fix I was doing.
🤞 1