https://kotlinlang.org logo
#webassembly
Title
# webassembly
k

K J

11/08/2023, 8:22 PM
How would I go about making a common module that both
js
and
wasmJs
targets depend on? I want to make a class that can be accessed via both
js
and
wasmJs
modules (since it uses Float64Array), but not put it in the
common
module, since Float64Array wouldn't be accessible for my
jvm
module.
o

Oliver.O

11/08/2023, 8:24 PM
You’re using Kotlin 1.9.20?
k

K J

11/08/2023, 8:25 PM
Yep!
o

Oliver.O

11/08/2023, 8:31 PM
Then it's probably this (untested):
Copy code
@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyDefaultHierarchyTemplate {
    common {
        group("commonJs") {
            group("js")
            group("wasmJs")
        }
    }
}
Background: https://twitter.com/Sellmair/status/1717273638901006774
k

K J

11/08/2023, 8:40 PM
I managed to get it to show up! I think that it technically works, but Float64Array isn't recognized, since it's a 'blank' module with no dependencies. I read on the Multiplatform Heirarchy page on Kotlin's docs that sharing a source set between several JS targets is not possible, assuming they're including WASM as a JS target..
When I put my class in the JS module, it pulls Float64 array from
kotlin-dom-api-compat
, but in the WASM module it pulls from
kotlin-stdlib-wasm-js
, which makes me think this is frustratingly not possible as they're two different classes
o

Oliver.O

11/08/2023, 8:51 PM
Hmm, I haven't tried that combination myself. Maybe Wasm is not yet fully integrated with the other targets. (I'm using separate Gradle configurations for
wasmJs
and
js
as I'm using different Compose versions with those.)
👍 1
3 Views