Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wasm support #374

Merged
merged 8 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:
strategy:
matrix:
os: [macOS-latest, windows-latest]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little uncomfortable turning this off but I'm also not clear anymore what this was originally doing, since there's very little windows-specific code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's temporary for this PR to pass the checks. There is PR open to re-enable it #375

os: [macOS-latest]
runs-on: ${{matrix.os}}
steps:
- name: Checkout the repo
Expand Down
4 changes: 3 additions & 1 deletion extensions/kermit-bugsnag/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* the License.
*/

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -21,6 +22,7 @@ plugins {

apply(from = "../../gradle/configure-crash-logger.gradle")
kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
targetHierarchy.default()
androidTarget {
publishAllLibraryVariants()
Expand Down Expand Up @@ -49,4 +51,4 @@ android {

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
}
4 changes: 3 additions & 1 deletion extensions/kermit-crashlytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* the License.
*/

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -22,6 +23,7 @@ plugins {
apply(from = "../../gradle/configure-crash-logger.gradle")

kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
targetHierarchy.default()
androidTarget {
publishAllLibraryVariants()
Expand Down Expand Up @@ -50,4 +52,4 @@ android {

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
}
4 changes: 3 additions & 1 deletion extensions/kermit-koin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* the License.
*/

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -20,6 +21,7 @@ plugins {
}

kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
targetHierarchy.default()
androidTarget {
publishAllLibraryVariants()
Expand Down Expand Up @@ -76,4 +78,4 @@ android {

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx4g
SONATYPE_HOST=DEFAULT
RELEASE_SIGNING_ENABLED=true
GROUP=co.touchlab
VERSION_NAME=2.0.1
VERSION_NAME=2.0.2

POM_NAME=Kermit
POM_DESCRIPTION=Kermit The Log
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ android-test-runner = "1.5.2"

google-services = "4.3.15"

stately = "2.0.3"
testhelp = "0.6.9"
stately = "2.0.4"
testhelp = "0.6.11"

crashkios = "0.8.3"
crashkios = "0.8.5"
bugsnag = "5.31.1"
bugsnag-gradle-plugin = "8.0.1"

Expand Down
29 changes: 26 additions & 3 deletions kermit-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* the License.
*/

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -20,6 +23,7 @@ plugins {
}

kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
targetHierarchy.default()
androidTarget {
publishAllLibraryVariants()
Expand All @@ -29,6 +33,13 @@ kotlin {
browser()
nodejs()
}
@OptIn(ExperimentalWasmDsl::class)
wasm {
browser()
nodejs()
d8()
binaries.executable()
}

macosX64()
macosArm64()
Expand Down Expand Up @@ -106,6 +117,17 @@ kotlin {
dependsOn(nativeTest)
}

val jsAndWasmMain by creating {
dependsOn(commonMain)
getByName("jsMain").dependsOn(this)
findjigar marked this conversation as resolved.
Show resolved Hide resolved
getByName("wasmMain").dependsOn(this)
}
val jsAndWasmTest by creating {
dependsOn(commonTest)
getByName("jsTest").dependsOn(this)
getByName("wasmTest").dependsOn(this)
}

targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>().all {
val mainSourceSet = compilations.getByName("main").defaultSourceSet
val testSourceSet = compilations.getByName("test").defaultSourceSet
Expand All @@ -117,17 +139,14 @@ kotlin {
val linuxMain by getting
linuxMain
}

konanTarget.family == org.jetbrains.kotlin.konan.target.Family.MINGW -> {
val mingwMain by getting
mingwMain
}

konanTarget.family == org.jetbrains.kotlin.konan.target.Family.ANDROID -> {
val androidNativeMain by getting
androidNativeMain
}

else -> nativeMain
}
)
Expand Down Expand Up @@ -158,3 +177,7 @@ android {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

rootProject.the<NodeJsRootExtension>().apply {
nodeVersion = "20.4.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,10 @@ class ConsoleWriter internal constructor(
}

internal interface ConsoleIntf {
fun error(vararg o: Any?)
fun warn(vararg o: Any?)
fun info(vararg o: Any?)
fun log(vararg o: Any?)
fun error(output: String)
fun warn(output: String)
fun info(output: String)
fun log(output: String)
}

private object ConsoleActual : ConsoleIntf {
override fun error(vararg o: Any?) {
console.error(*o)
}

override fun warn(vararg o: Any?) {
console.warn(*o)
}

override fun info(vararg o: Any?) {
console.info(*o)
}

override fun log(vararg o: Any?) {
console.log(*o)
}
}
internal expect object ConsoleActual : ConsoleIntf
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ class ConsoleCollector : ConsoleIntf {
val warnings = mutableListOf<String>()
val infos = mutableListOf<String>()
val logs = mutableListOf<String>()
override fun error(vararg o: Any?) {
errors.addAll(o.filterNotNull().map { it.toString() })
override fun error(output: String) {
errors.add(output)
}

override fun warn(vararg o: Any?) {
warnings.addAll(o.filterNotNull().map { it.toString() })
override fun warn(output: String) {
warnings.add(output)
}

override fun info(vararg o: Any?) {
infos.addAll(o.filterNotNull().map { it.toString() })
override fun info(output: String) {
infos.add(output)
}

override fun log(vararg o: Any?) {
logs.addAll(o.filterNotNull().map { it.toString() })
override fun log(output: String) {
logs.add(output)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 Touchlab
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* 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 co.touchlab.kermit

internal actual object ConsoleActual : ConsoleIntf {
override fun error(output: String) {
console.error(output)
}

override fun warn(output: String) {
console.warn(output)
}

override fun info(output: String) {
console.info(output)
}

override fun log(output: String) {
console.log(output)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2023 Touchlab
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* 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 co.touchlab.kermit

@JsFun("(output) => console.error(output)")
external fun consoleError(output: String)

@JsFun("(output) => console.warn(output)")
external fun consoleWarn(output: String)

@JsFun("(output) => console.info(output)")
external fun consoleInfo(output: String)

@JsFun("(output) => console.log(output)")
external fun consoleLog(output: String)

internal actual object ConsoleActual : ConsoleIntf {
override fun error(output: String) {
consoleError(output)
}

override fun warn(output: String) {
consoleWarn(output)
}

override fun info(output: String) {
consoleInfo(output)
}

override fun log(output: String) {
consoleLog(output)
}
}
22 changes: 22 additions & 0 deletions kermit-simple/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension

/*
* Copyright (c) 2021 Touchlab
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
Expand All @@ -17,11 +21,19 @@ plugins {
}

kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
targetHierarchy.default()
js {
browser()
nodejs()
}
@OptIn(ExperimentalWasmDsl::class)
wasm {
browser()
nodejs()
d8()
binaries.executable()
}

macosX64()
macosArm64()
Expand Down Expand Up @@ -73,6 +85,12 @@ kotlin {
val jsTest by getting {
dependsOn(nonKotlinTest)
}
val wasmMain by getting {
dependsOn(nonKotlinMain)
}
val wasmTest by getting {
dependsOn(nonKotlinTest)
}
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>().all {
val mainSourceSet = compilations.getByName("main").defaultSourceSet
val testSourceSet = compilations.getByName("test").defaultSourceSet
Expand All @@ -82,3 +100,7 @@ kotlin {
}
}
}

rootProject.the<NodeJsRootExtension>().apply {
nodeVersion = "20.4.0"
}
Loading
Loading