diff --git a/src/main/kotlin/api/klib/KlibAbiDumpFileMerger.kt b/src/main/kotlin/api/klib/KlibAbiDumpFileMerger.kt index 529c670f..4805c41c 100644 --- a/src/main/kotlin/api/klib/KlibAbiDumpFileMerger.kt +++ b/src/main/kotlin/api/klib/KlibAbiDumpFileMerger.kt @@ -49,6 +49,7 @@ private const val INDENT_WIDTH = 4 private const val ALIAS_PREFIX = "// Alias: " private const val PLATFORM_PREFIX = "// Platform: " private const val NATIVE_TARGETS_PREFIX = "// Native targets: " +private const val WASM_TARGETS_PREFIX = "// WASM targets: " private const val LIBRARY_NAME_PREFIX = "// Library unique name:" private fun String.depth(): Int { @@ -263,7 +264,8 @@ internal class KlibAbiDumpMerger { platform = next.split(": ")[1].trim() } - next.startsWith(NATIVE_TARGETS_PREFIX) -> { + next.startsWith(NATIVE_TARGETS_PREFIX) || next.startsWith(WASM_TARGETS_PREFIX) -> { + check(targets == null) { "Targets list was already parsed" } targets = next.split(": ")[1].trim() } } @@ -285,12 +287,12 @@ internal class KlibAbiDumpMerger { "The dump does not contain platform name. Please make sure that the manifest was included in the dump" } - if (platformString == "WASM") { - // Currently, there's no way to distinguish Wasm targets without explicitly specifying a target name + if (platformString == "WASM" && targetsString == null) { + // For older dumps, there's no way to distinguish Wasm targets without explicitly specifying a target name check(configurableTargetName != null) { "targetName has to be specified for a Wasm target" } return setOf(KlibTarget(configurableTargetName)) } - if (platformString != "NATIVE") { + if (platformString != "NATIVE" && platformString != "WASM") { val platformStringLc = platformString.toLowerCase(Locale.ROOT) return if (configurableTargetName == null) { setOf(KlibTarget(platformStringLc)) diff --git a/src/main/kotlin/api/klib/TargetHierarchy.kt b/src/main/kotlin/api/klib/TargetHierarchy.kt index fe5aac63..0bdd3336 100644 --- a/src/main/kotlin/api/klib/TargetHierarchy.kt +++ b/src/main/kotlin/api/klib/TargetHierarchy.kt @@ -134,5 +134,7 @@ internal val konanTargetNameMapping = mapOf( "ios_arm32" to "iosArm32", "watchos_x86" to "watchosX86", "linux_arm32_hfp" to "linuxArm32Hfp", - "mingw_x86" to "mingwX86" + "mingw_x86" to "mingwX86", + "wasm-wasi" to "wasmWasi", + "wasm-js" to "wasmJs" ) diff --git a/src/test/kotlin/tests/KlibAbiMergingTest.kt b/src/test/kotlin/tests/KlibAbiMergingTest.kt index 0c557530..b9d52429 100644 --- a/src/test/kotlin/tests/KlibAbiMergingTest.kt +++ b/src/test/kotlin/tests/KlibAbiMergingTest.kt @@ -247,6 +247,41 @@ class KlibAbiMergingTest { ) } + @Test + fun explicitWasmTargets() { + val klib = KlibAbiDumpMerger() + klib.merge(file("/merge/explicitWasmTargets/wasmWasi.abi")) + klib.merge(file("/merge/explicitWasmTargets/wasmJs.abi")) + + val merged = dumpToFile(klib) + + assertContentEquals( + lines("/merge/explicitWasmTargets/merged.abi"), + Files.readAllLines(merged.toPath()).asSequence() + ) + } + + @Test + fun renameWasmTargetHavingNameInManifest() { + val klib = KlibAbiDumpMerger() + klib.merge(file("/merge/explicitWasmTargets/wasmWasi.abi"), "wasm") + assertEquals(setOf(KlibTarget.parse("wasmWasi.wasm")), klib.targets) + } + + @Test + fun wasmDumpWithMultipleTargets() { + val klib = KlibAbiDumpMerger() + assertFailsWith{ + klib.merge(file("/merge/explicitWasmTargets/wasmMulti.abi"), "wasm") + } + + klib.merge(file("/merge/explicitWasmTargets/wasmMulti.abi")) + assertContentEquals( + lines("/merge/explicitWasmTargets/merged.abi"), + Files.readAllLines(dumpToFile(klib).toPath()).asSequence() + ) + } + @Test fun unqualifiedWasmTarget() { // currently, there's no way to distinguish wasmWasi from wasmJs diff --git a/src/test/resources/merge/explicitWasmTargets/merged.abi b/src/test/resources/merge/explicitWasmTargets/merged.abi new file mode 100644 index 00000000..0525f2c0 --- /dev/null +++ b/src/test/resources/merge/explicitWasmTargets/merged.abi @@ -0,0 +1,15 @@ +// Klib ABI Dump +// Targets: [wasmJs, wasmWasi] +// Rendering settings: +// - Signature version: 2 +// - Show manifest properties: false +// - Show declarations: true + +// Library unique name: +final class org.example/ShardedClass { // org.example/ShardedClass|null[0] + constructor (kotlin/Int) // org.example/ShardedClass.|(kotlin.Int){}[0] + final fun add(kotlin/Int): kotlin/Int // org.example/ShardedClass.add|add(kotlin.Int){}[0] + final val value // org.example/ShardedClass.value|{}value[0] + final fun (): kotlin/Int // org.example/ShardedClass.value.|(){}[0] +} +final fun org.example/ShardedClass(kotlin/Int, kotlin/Float, kotlin/Long): org.example/ShardedClass // org.example/ShardedClass|ShardedClass(kotlin.Int;kotlin.Float;kotlin.Long){}[0] diff --git a/src/test/resources/merge/explicitWasmTargets/wasmJs.abi b/src/test/resources/merge/explicitWasmTargets/wasmJs.abi new file mode 100644 index 00000000..646086f3 --- /dev/null +++ b/src/test/resources/merge/explicitWasmTargets/wasmJs.abi @@ -0,0 +1,17 @@ +// Rendering settings: +// - Signature version: 2 +// - Show manifest properties: false +// - Show declarations: true + +// Library unique name: +// Platform: WASM +// WASM targets: wasm-js +// Compiler version: 2.0.255-SNAPSHOT +// ABI version: 1.8.0 +final class org.example/ShardedClass { // org.example/ShardedClass|null[0] + final val value // org.example/ShardedClass.value|{}value[0] + final fun (): kotlin/Int // org.example/ShardedClass.value.|(){}[0] + constructor (kotlin/Int) // org.example/ShardedClass.|(kotlin.Int){}[0] + final fun add(kotlin/Int): kotlin/Int // org.example/ShardedClass.add|add(kotlin.Int){}[0] +} +final fun org.example/ShardedClass(kotlin/Int, kotlin/Float, kotlin/Long): org.example/ShardedClass // org.example/ShardedClass|ShardedClass(kotlin.Int;kotlin.Float;kotlin.Long){}[0] diff --git a/src/test/resources/merge/explicitWasmTargets/wasmMulti.abi b/src/test/resources/merge/explicitWasmTargets/wasmMulti.abi new file mode 100644 index 00000000..0b05dac2 --- /dev/null +++ b/src/test/resources/merge/explicitWasmTargets/wasmMulti.abi @@ -0,0 +1,17 @@ +// Rendering settings: +// - Signature version: 2 +// - Show manifest properties: false +// - Show declarations: true + +// Library unique name: +// Platform: WASM +// WASM targets: wasm-wasi, wasm-js +// Compiler version: 2.0.255-SNAPSHOT +// ABI version: 1.8.0 +final class org.example/ShardedClass { // org.example/ShardedClass|null[0] + final val value // org.example/ShardedClass.value|{}value[0] + final fun (): kotlin/Int // org.example/ShardedClass.value.|(){}[0] + constructor (kotlin/Int) // org.example/ShardedClass.|(kotlin.Int){}[0] + final fun add(kotlin/Int): kotlin/Int // org.example/ShardedClass.add|add(kotlin.Int){}[0] +} +final fun org.example/ShardedClass(kotlin/Int, kotlin/Float, kotlin/Long): org.example/ShardedClass // org.example/ShardedClass|ShardedClass(kotlin.Int;kotlin.Float;kotlin.Long){}[0] diff --git a/src/test/resources/merge/explicitWasmTargets/wasmWasi.abi b/src/test/resources/merge/explicitWasmTargets/wasmWasi.abi new file mode 100644 index 00000000..0b68d060 --- /dev/null +++ b/src/test/resources/merge/explicitWasmTargets/wasmWasi.abi @@ -0,0 +1,17 @@ +// Rendering settings: +// - Signature version: 2 +// - Show manifest properties: false +// - Show declarations: true + +// Library unique name: +// Platform: WASM +// WASM targets: wasm-wasi +// Compiler version: 2.0.255-SNAPSHOT +// ABI version: 1.8.0 +final class org.example/ShardedClass { // org.example/ShardedClass|null[0] + final val value // org.example/ShardedClass.value|{}value[0] + final fun (): kotlin/Int // org.example/ShardedClass.value.|(){}[0] + constructor (kotlin/Int) // org.example/ShardedClass.|(kotlin.Int){}[0] + final fun add(kotlin/Int): kotlin/Int // org.example/ShardedClass.add|add(kotlin.Int){}[0] +} +final fun org.example/ShardedClass(kotlin/Int, kotlin/Float, kotlin/Long): org.example/ShardedClass // org.example/ShardedClass|ShardedClass(kotlin.Int;kotlin.Float;kotlin.Long){}[0]