Skip to content

Commit

Permalink
Add linuxArm64 and wasmJs targets (#166)
Browse files Browse the repository at this point in the history
Kotest added support for wasm a whiel ago, but hasn't made a release since then. Rather than waiting any longer, we use a snapshot build of kotest for now. It's only a test dependency, so it doesn't affect the published mordant artifacts.

Wasm was a bit of a pain: you can't share much code between it and JS, because wasm introduces a `JsAny`, while js uses `dynamic`. The `js()` function also works differently between the two targets. Finally, wasm seems to translate `\r` to `\r\n` when printing, so I had to work around that for animations.
  • Loading branch information
ajalt authored Apr 24, 2024
1 parent c196aae commit 63fa456
Show file tree
Hide file tree
Showing 28 changed files with 423 additions and 199 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ jobs:
test:
strategy:
matrix:
os: [macos-latest, macos-14, windows-latest, ubuntu-latest]
os: [macos-latest, windows-latest, ubuntu-latest]
include:
- os: ubuntu-latest
EXTRA_GRADLE_ARGS: :test:graalvm:nativeTest apiCheck
- os: macos-latest
env:
# macos-latest is now macos-14 and has less than half as much memory available as other runners
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx6g -Dfile.encoding=UTF-8" -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=false -Dkotlin.incremental=false -Dorg.gradle.project.kotlin.incremental.multiplatform=false -Dorg.gradle.project.kotlin.native.disableCompilerDaemon=true
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: 17
java-version: 21
distribution: 'graalvm-community'
set-java-home: false
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
arguments: |
Expand Down Expand Up @@ -74,4 +78,4 @@ jobs:
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }}
env:
GRADLE_OPTS: -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=false -Dkotlin.incremental=false -Dorg.gradle.project.kotlin.incremental.multiplatform=false -Dorg.gradle.project.kotlin.native.disableCompilerDaemon=true -Dorg.gradle.jvmargs="-Dfile.encoding=UTF-8"
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx12g -Dfile.encoding=UTF-8" -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=false -Dkotlin.incremental=false -Dorg.gradle.project.kotlin.incremental.multiplatform=false -Dorg.gradle.project.kotlin.native.disableCompilerDaemon=true
3 changes: 2 additions & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ on:
- 'gradlew.bat'
- 'gradle/wrapper/'


jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v2
- uses: gradle/actions/wrapper-validation@v3
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
java-version: 21
- uses: actions/setup-python@v5
with:
python-version: '3.12'
Expand Down Expand Up @@ -43,3 +43,6 @@ jobs:
with:
branch: gh-pages
folder: site
env:
# macos-latest is now macos-14 and has less than half as much memory available as other runners
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx6g -Dfile.encoding=UTF-8" -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=false -Dkotlin.incremental=false -Dorg.gradle.project.kotlin.incremental.multiplatform=false -Dorg.gradle.project.kotlin.native.disableCompilerDaemon=true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ docs/changelog.md
docs/index.md
site/
kotlin-js-store/
.kotlin/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## Unreleased
### Added
- Publish `linuxArm64` and `wasmJs` targets.

## 2.4.0
This release includes a complete rewrite of the progress bar system. The new system is more
performant and flexible, and allows for more complex progress animations. The old progress bar APIs
Expand Down
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask

plugins {
alias(libs.plugins.kotlinBinaryCompatibilityValidator)
Expand All @@ -21,3 +23,8 @@ tasks.withType<DokkaMultiModuleTask>().configureEach {
)
)
}

// https://youtrack.jetbrains.com/issue/KT-63014
tasks.withType<KotlinNpmInstallTask>().configureEach {
args.add("--ignore-engines")
}
21 changes: 21 additions & 0 deletions buildSrc/src/main/kotlin/mordant-js-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension

plugins {
kotlin("multiplatform")
}
Expand All @@ -8,4 +11,22 @@ kotlin {
nodejs()
browser()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
browser()
}

sourceSets {
val jsCommonMain by creating { dependsOn(commonMain.get()) }
jsMain.get().dependsOn(jsCommonMain)
getByName("wasmJsMain").dependsOn(jsCommonMain)
}
}

// Need to compile using a canary version of Node due to
// https://youtrack.jetbrains.com/issue/KT-63014
rootProject.the<NodeJsRootExtension>().apply {
nodeVersion = "21.0.0-v8-canary2023091837d0630120"
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ kotlin {
macosX64()
macosArm64()
linuxX64()
linuxArm64()
mingwX64()

applyDefaultHierarchyTemplate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ class CoroutinesAnimatorTest {
a.stop()
advanceTimeBy(1.0.seconds)
job.isActive shouldBe false
vt.output() shouldBe "$HIDE_CURSOR 0/10\n$SHOW_CURSOR"
vt.fullNormalizedOutput() shouldBe "$HIDE_CURSOR 0/10\n$SHOW_CURSOR"

vt.clearOutput()
job = backgroundScope.launch { a.execute() }
advanceTimeBy(0.1.seconds)
a.clear()
advanceTimeBy(1.0.seconds)
job.isActive shouldBe false
vt.output() shouldBe "$HIDE_CURSOR 0/10\r${CSI}0J$SHOW_CURSOR"
vt.fullNormalizedOutput() shouldBe "$HIDE_CURSOR 0/10\r${CSI}0J$SHOW_CURSOR"
}

@Test
Expand Down Expand Up @@ -125,7 +125,12 @@ class CoroutinesAnimatorTest {
vt.output().shouldContain(" 10/10\n 10/10")
}

// This handles the difference in wasm movements and the other targets
private fun TerminalRecorder.fullNormalizedOutput(): String {
return output().replace("${CSI}1A", "")
}

private fun TerminalRecorder.normalizedOutput(): String {
return output().substringAfter("\r").trimEnd()
return output().replace("${CSI}1A", "").substringAfter("\r").trimEnd()
}
}
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
kotlin = "1.9.21"
kotlin = "1.9.23"
coroutines = "1.8.0"

[libraries]
colormath = "com.github.ajalt.colormath:colormath:3.3.1"
markdown = "org.jetbrains:markdown:0.5.2"
jna-core = "net.java.dev.jna:jna:5.13.0"
colormath = "com.github.ajalt.colormath:colormath:3.5.0"
markdown = "org.jetbrains:markdown:0.7.0"
jna-core = "net.java.dev.jna:jna:5.14.0"

# compileOnly
graalvm-svm = "org.graalvm.nativeimage:svm:23.1.0"
Expand All @@ -14,15 +14,15 @@ graalvm-svm = "org.graalvm.nativeimage:svm:23.1.0"
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }

# used in tests
kotest = "io.kotest:kotest-assertions-core:5.8.0"
kotest = "io.kotest:kotest-assertions-core:5.9.0.1440-SNAPSHOT"
systemrules = "com.github.stefanbirkner:system-rules:1.19.0"
r8 = "com.android.tools:r8:8.3.37"
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }

# build logic
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.9.10" }
publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.27.0" }
dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.9.20" }
publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.28.0" }

[plugins]
graalvm-nativeimage = "org.graalvm.buildtools.native:0.9.28"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
9 changes: 9 additions & 0 deletions mordant/api/mordant.api
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public final class com/github/ajalt/mordant/rendering/Line : java/util/List, kot
public synthetic fun add (Ljava/lang/Object;)Z
public fun addAll (ILjava/util/Collection;)Z
public fun addAll (Ljava/util/Collection;)Z
public fun addFirst (Lcom/github/ajalt/mordant/rendering/Span;)V
public synthetic fun addFirst (Ljava/lang/Object;)V
public fun addLast (Lcom/github/ajalt/mordant/rendering/Span;)V
public synthetic fun addLast (Ljava/lang/Object;)V
public fun clear ()V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Lcom/github/ajalt/mordant/rendering/TextStyle;
Expand Down Expand Up @@ -290,6 +294,10 @@ public final class com/github/ajalt/mordant/rendering/Line : java/util/List, kot
public synthetic fun remove (I)Ljava/lang/Object;
public fun remove (Ljava/lang/Object;)Z
public fun removeAll (Ljava/util/Collection;)Z
public fun removeFirst ()Lcom/github/ajalt/mordant/rendering/Span;
public synthetic fun removeFirst ()Ljava/lang/Object;
public fun removeLast ()Lcom/github/ajalt/mordant/rendering/Span;
public synthetic fun removeLast ()Ljava/lang/Object;
public fun replaceAll (Ljava/util/function/UnaryOperator;)V
public fun retainAll (Ljava/util/Collection;)Z
public fun set (ILcom/github/ajalt/mordant/rendering/Span;)Lcom/github/ajalt/mordant/rendering/Span;
Expand Down Expand Up @@ -366,6 +374,7 @@ public final class com/github/ajalt/mordant/rendering/TextColors : java/lang/Enu
public static final field red Lcom/github/ajalt/mordant/rendering/TextColors;
public static final field white Lcom/github/ajalt/mordant/rendering/TextColors;
public static final field yellow Lcom/github/ajalt/mordant/rendering/TextColors;
public fun clamp ()Lcom/github/ajalt/colormath/Color;
public fun getAlpha ()F
public fun getBg ()Lcom/github/ajalt/mordant/rendering/TextStyle;
public fun getBgColor ()Lcom/github/ajalt/colormath/Color;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ajalt.mordant.animation

import com.github.ajalt.mordant.internal.*
import com.github.ajalt.mordant.internal.FAST_ISATTY
import com.github.ajalt.mordant.internal.MppAtomicRef
import com.github.ajalt.mordant.internal.Size
Expand Down Expand Up @@ -173,6 +174,7 @@ abstract class Animation<T>(
if (firstDraw || lastSize == null) return null
return terminal.cursor.getMoves {
startOfLine()
if (CR_IMPLIES_LF) up(1)

if (terminal.info.crClearsLine) {
// IntelliJ doesn't support cursor moves, so this is all we can do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ internal expect fun sendInterceptedPrintRequest(
)

internal expect val FAST_ISATTY: Boolean

internal expect val CR_IMPLIES_LF: Boolean
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private fun resizeLine(
endIndex = j
if (width < newWidth) {
endSpan = span.take(newWidth - width)
width += endSpan.cellWidth
width = newWidth
}
break
}
Expand Down
Loading

0 comments on commit 63fa456

Please sign in to comment.