Skip to content

Commit

Permalink
Add wasm target
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt committed Jan 25, 2024
1 parent ca4c218 commit 52829f7
Show file tree
Hide file tree
Showing 42 changed files with 96 additions and 31 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
arguments: |
:colormath:jsNodeTest
:colormath:jvmTest
:colormath:linuxX64Test
:colormath:test:jsNodeTest
:colormath:test:jvmTest
:colormath:test:linuxX64Test
:colormath:compileKotlinLinuxArm64
:extensions:colormath-ext-jetpack-compose:check
:extensions:colormath-ext-android-colorint:check
:colormath:wasmJsTest
:extensions:colormath-ext-jetpack-compose:check
:extensions:colormath-ext-android-colorint:check
:extensions:colormath-ext-android-color:check
--stacktrace
- name: Bundle the build report
Expand All @@ -44,7 +45,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
arguments: |
Expand All @@ -63,7 +64,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
arguments: mingwX64Test --stacktrace
Expand All @@ -76,7 +77,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
java-version: 21
- name: Fetch git tags
run: git fetch origin +refs/tags/*:refs/tags/*
- name: Deploy to sonatype
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
arguments: |
:colormath:jsNodeTest
:colormath:jvmTest
:colormath:linuxX64Test
:colormath:test:jsNodeTest
:colormath:test:jvmTest
:colormath:test:linuxX64Test
:colormath:compileKotlinLinuxArm64
:colormath:wasmJsTest
:extensions:colormath-ext-jetpack-compose:check
:extensions:colormath-ext-android-colorint:check
:extensions:colormath-ext-android-color:check --stacktrace
:extensions:colormath-ext-android-color:check
--stacktrace
- name: Bundle the build report
if: failure()
run: find . -type d -name 'reports' | zip -@ -r build-reports.zip
Expand All @@ -41,14 +43,17 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
arguments: |
macosX64Test
:colormath:compileKotlinMacosArm64
tvosX64Test
iosX64Test
tvosX64Test
iosSimulatorArm64Test
tvosSimulatorArm64Test
watchosSimulatorArm64Test
--stacktrace
windows-tests:
runs-on: windows-latest
Expand All @@ -57,7 +62,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
arguments: mingwX64Test --stacktrace
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ dependencies {

#### Multiplatform

Colormath supports the following targets: `jvm`, `mingwX64`, `linuxX64`, `macosX64`, `ios`,
`watchos`, `tvos`, and `js` (for both NodeJS and Browsers). You'll need to use Gradle 6 or newer.
Artifacts for `macosArm64` and `linuxArm64` are also published, but not tested with CI.
Colormath publishes artifacts for all
[Tier 1 and Tier 2](https://kotlinlang.org/docs/native-target-support.html)
targets, as well as `mingwX64` and `wasm`.

`wasm` and the `arm64` targets are not tested on CI.

#### Snapshots

Expand Down
4 changes: 3 additions & 1 deletion colormath/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ kotlin {
jvm()
js { nodejs() }

@OptIn(ExperimentalWasmDsl::class)
wasmJs { nodejs() }

linuxX64()
linuxArm64()
mingwX64()
Expand All @@ -32,7 +35,6 @@ kotlin {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.kotest)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.ajalt.colormath.internal

import io.kotest.matchers.shouldBe
import kotlin.js.JsName
import kotlin.test.Test
import kotlin.test.assertEquals

class MatrixTest {
@Test
Expand Down Expand Up @@ -56,3 +56,8 @@ class MatrixTest {
l.dot(10f, 20f, 30f).values shouldBe floatArrayOf(140f, 320f, 500f)
}
}

// TODO(kotest): go back to kotest once is supports wasm
private infix fun Any?.shouldBe(other: Any?) {
assertEquals(other, this)
}
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
kotlin = "1.9.20"
jbCompose = "1.5.10"
kotlin = "1.9.21"
jbCompose = "1.5.11"

[libraries]
# used in tests
kotest = "io.kotest:kotest-assertions-core:5.7.2"
kotest = "io.kotest:kotest-assertions-core:5.8.0"
compose-ui-graphics = { module = "org.jetbrains.compose.ui:ui-graphics", version.ref = "jbCompose" }
androidx-annotation = "androidx.annotation:annotation:1.7.0"
junit = "junit:junit:4.13.2"
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("colormath")
include("test")
include("extensions:colormath-ext-android-color")
include("extensions:colormath-ext-android-colorint")
include("extensions:colormath-ext-jetpack-compose")
Expand Down
46 changes: 46 additions & 0 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
kotlin("multiplatform")
alias(libs.plugins.publish)
}

repositories {
mavenCentral()
}

kotlin {
jvm()
js { nodejs() }

linuxX64()
linuxArm64()
mingwX64()
macosX64()
macosArm64()
iosX64()
iosArm64()
iosSimulatorArm64()
tvosX64()
tvosArm64()
tvosSimulatorArm64()
watchosX64()
watchosArm64()
watchosSimulatorArm64()

sourceSets {
val commonTest by getting {
dependencies {
api(project(":colormath"))
implementation(libs.kotest)
implementation(kotlin("test"))
}
}
}
}

tasks.withType<Jar>().configureEach {
manifest {
attributes("Automatic-Module-Name" to "com.github.ajalt.colormath")
}
}
2 changes: 2 additions & 0 deletions test/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POM_ARTIFACT_ID=colormath
POM_NAME=Colormath
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.ajalt.colormath.model

import com.github.ajalt.colormath.internal.CAT02_LMS_TO_XYZ
import com.github.ajalt.colormath.internal.CAT02_XYZ_TO_LMS
import com.github.ajalt.colormath.model.LABColorSpaces.LAB50
import com.github.ajalt.colormath.model.LUVColorSpaces.LUV50
import com.github.ajalt.colormath.model.XYZColorSpaces.XYZ50
Expand Down Expand Up @@ -51,10 +49,13 @@ class XYZTest {
XYZ(0.40, 0.50, 0.60) to Oklab(0.78539542, -0.06758384, -0.01449969),
XYZ(1.00, 1.00, 1.00) to Oklab(1.00324405, 0.02673522, 0.0147436),
XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50) to Oklab(0.56645328, 0.01509528, 0.00832456),
XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS.rowMajor) to Oklab(0.56645328, 0.01509528, 0.00832456),
XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS.rowMajor, CAT02_LMS_TO_XYZ.rowMajor) to Oklab(0.56645328,
0.01509528,
0.00832456),
// TODO(kotest): reenable this when kotest supports wasm
// XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS) to Oklab(
// 0.56645328, 0.01509528, 0.00832456
// ),
// XYZ(0.18, 0.18, 0.18).adaptTo(XYZ50, CAT02_XYZ_TO_LMS, CAT02_LMS_TO_XYZ.rowMajor) to Oklab(
// 0.56645328, 0.01509528, 0.00832456
// ),
)

@Test
Expand Down

0 comments on commit 52829f7

Please sign in to comment.