Skip to content

Commit

Permalink
Make some start at wasm support (behind property). It doesn't work yet
Browse files Browse the repository at this point in the history
due to some runtime error with node. It is not clear why it fails (there
is no error message)
  • Loading branch information
pdvrieze committed Jul 9, 2023
1 parent 06fabc3 commit 5ab5e3e
Show file tree
Hide file tree
Showing 58 changed files with 330 additions and 143 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ allprojects {
mavenLocal()
mavenCentral()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") }
maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")}
google()
}

Expand Down
14 changes: 8 additions & 6 deletions buildSrc/src/main/kotlin/nativeTargets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.gradle.kotlin.dsl.getByName
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.konan.target.HostManager
Expand Down Expand Up @@ -105,22 +106,21 @@ fun Project.addNativeTargets() {

if (nativeState != NativeState.HOST || host == Host.Macos) {
macosX64 { addSourceSets() }
macosArm64 { addSourceSets() }
iosArm64 { addSourceSets() }
iosArm32 { addSourceSets() }
iosSimulatorArm64 { addSourceSets() }
iosX64 { addSourceSets() }
iosArm32 { addSourceSets() }

watchosX86 { addSourceSets() }
watchosSimulatorArm64() { addSourceSets() }
watchosX64 { addSourceSets() }
watchosArm32 { addSourceSets() }
watchosArm64 { addSourceSets() }

tvosSimulatorArm64 { addSourceSets() }
tvosArm64 { addSourceSets() }
tvosX64 { addSourceSets() }

addTarget("iosSimulatorArm64")
addTarget("watchosSimulatorArm64")
addTarget("tvosSimulatorArm64")
addTarget("macosArm64")
}

if (nativeState != NativeState.HOST || host == Host.Windows) {
Expand Down Expand Up @@ -155,3 +155,5 @@ private fun KotlinMultiplatformExtension.targets(configure: Action<Any>): Unit =

private fun KotlinMultiplatformExtension.sourceSets(configure: Action<org.gradle.api.NamedDomainObjectContainer<KotlinSourceSet>>): Unit =
(this as ExtensionAware).extensions.configure("sourceSets", configure)

val Project.isWasmSupported: Boolean get() = extraProperties.get("xmlutil.wasmEnabled")?.toString()?.toLowerCase() == "true"
24 changes: 21 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ kotlin {
}
}
}
js(BOTH) {
js {
browser()
compilations.all {
kotlinOptions {
Expand All @@ -120,6 +120,18 @@ kotlin {
}
}
}
if (isWasmSupported) {
wasm {
nodejs()
browser()
compilations.all {
kotlinOptions {
sourceMap = true
verbose = true
}
}
}
}
}

targets.forEach { target ->
Expand Down Expand Up @@ -148,7 +160,7 @@ kotlin {
}

val javaShared by creating {
dependsOn(commonDom)
dependsOn(commonMain)
}

val jvmMain by getting {
Expand Down Expand Up @@ -190,7 +202,6 @@ kotlin {
}

val jsMain by getting {
dependsOn(commonDom)
}

val jsTest by getting {
Expand All @@ -209,6 +220,13 @@ kotlin {
implementation(kotlin("test"))
}
}
if (isWasmSupported) {
val wasmMain by getting {
dependsOn(commonDom)
dependencies {
}
}
}
}
sourceSets.all {
languageSettings.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021.
* Copyright (c) 2023.
*
* This file is part of xmlutil.
*
Expand Down Expand Up @@ -42,15 +42,15 @@ public actual object XmlStreaming {
}

public actual fun newReader(input: CharSequence): XmlReader {
return KtXmlReader(StringReader(input))
return KtXmlReader(StringReader(input.toString()))
}

public actual fun newReader(reader: Reader): XmlReader {
return newGenericReader(reader)
}

public actual fun newGenericReader(input: CharSequence): XmlReader =
newGenericReader(StringReader(input))
newGenericReader(StringReader(input.toString()))

public actual fun newGenericReader(reader: Reader): XmlReader = KtXmlReader(reader)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (c) 2023.
*
* This file is part of xmlutil.
*
* This file is licenced to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You should have received a copy of the license with the source distribution.
* Alternatively, you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package nl.adaptivity.xmlutil.core.impl.multiplatform

import kotlin.reflect.KClass

public actual abstract class Reader {
public actual open fun read(): Int {
val b = CharArray(1)
if (read(b, 0, 1) < 0) return -1
return b[0].code
}

public actual abstract fun read(buf: CharArray, offset: Int, len: Int): Int
}

public actual interface AutoCloseable {
public actual fun close()
}

public actual interface Closeable : AutoCloseable

public actual inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
var exception: Throwable? = null
try {
return block(this)
} catch (e: Throwable) {
exception = e
throw e
} finally {
when {
this == null -> {}
exception == null -> close()
else ->
try {
close()
} catch (closeException: Throwable) {
// cause.addSuppressed(closeException) // ignored here
}
}
}
}

public actual val KClass<*>.maybeAnnotations: List<Annotation> get() = emptyList()

public actual abstract class Writer : Appendable {
public open fun write(text: String) {
append(text)
}

override fun append(value: CharSequence?): Appendable {
return append(value, 0, value?.length ?: 0)
}

/** Write buffers to the underlying file (where valid). */
public open fun flush() {}
}

public actual open class StringWriter : Writer() {
private val buffer = StringBuilder()
override fun write(text: String) {
buffer.append(text)
}

override fun toString(): String {
return buffer.toString()
}

override fun append(value: Char): Appendable = apply {
buffer.append(value)
}

override fun append(value: CharSequence?): Appendable = apply {
buffer.append(value)
}

override fun append(
value: CharSequence?,
startIndex: Int,
endIndex: Int
): Appendable = apply {
buffer.append(value, startIndex, endIndex)
}
}

/*
public actual abstract class Reader {
public actual open fun read(): Int {
val b = CharArray(1)
if (read(b, 0, 1) < 0) return -1
return b[0].code
}
public actual abstract fun read(buf: CharArray, offset: Int, len: Int): Int
}
*/

public actual open class StringReader(private val source: CharSequence) : Reader() {

public actual constructor(source: String) : this(source as CharSequence)

private var pos: Int = 0

override fun read(): Int = when {
pos >= source.length -> -1
else -> source[pos++].code
}

override fun read(buf: CharArray, offset: Int, len: Int): Int {
if (pos >= source.length) return -1
val count = minOf(len, source.length - pos)
for (i in 0 until count) {
buf[offset + i] = source[pos + i]
}
pos += count
return count
}
}

public actual annotation class Language actual constructor(
actual val value: String,
actual val prefix: String,
actual val suffix: String
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021.
* Copyright (c) 2023.
*
* This file is part of xmlutil.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021.
* Copyright (c) 2023.
*
* This file is part of xmlutil.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import nl.adaptivity.xmlutil.XMLConstants.XMLNS_ATTRIBUTE
import nl.adaptivity.xmlutil.XMLConstants.XMLNS_ATTRIBUTE_NS_URI
import nl.adaptivity.xmlutil.XMLConstants.XML_NS_PREFIX
import nl.adaptivity.xmlutil.XMLConstants.XML_NS_URI
import nl.adaptivity.xmlutil.core.impl.multiplatform.name
import kotlin.collections.set
import kotlin.jvm.JvmName

Expand Down Expand Up @@ -239,7 +238,7 @@ public open class SimpleNamespaceContext internal constructor(public val buffer:

@OptIn(ExperimentalSerializationApi::class)
override val descriptor: SerialDescriptor =
SerialDescriptor(SimpleNamespaceContext::class.name, actualSerializer.descriptor)
SerialDescriptor("nl.adaptivity.xmlutil.SimpleNamespaceContext", actualSerializer.descriptor)

public fun from(originalNSContext: Iterable<Namespace>): SimpleNamespaceContext = when (originalNSContext) {
is SimpleNamespaceContext -> originalNSContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package nl.adaptivity.xmlutil.core.impl.multiplatform

import nl.adaptivity.xmlutil.XmlUtilInternal
import kotlin.Throws
import kotlin.reflect.KClass

@Target(
Expand Down
Loading

0 comments on commit 5ab5e3e

Please sign in to comment.