Skip to content

Commit

Permalink
Add experimental support for wasmJs & wasmWasi (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Mar 18, 2024
1 parent 6aff0e1 commit ff04c4e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 59 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
-PKMP_TARGETS="JVM,JS,MINGW_X64,WASM_JS,WASM_WASI"
emulator:
runs-on: macos-latest
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand All @@ -75,20 +75,27 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Setup JDK
uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: 19
java-version: 17

- name: Build
uses: gradle/gradle-build-action@v2

- name: Run Android Instrumented Tests
uses: reactivecircus/android-emulator-runner@v2
with:
emulator-boot-timeout: 300 # 5 minutes
api-level: ${{ matrix.api-level }}
script: ./gradlew :test-android:connectedCheck -PKMP_TARGETS="ANDROID,JVM"
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
![badge-platform-jvm]
![badge-platform-js]
![badge-platform-js-node]
![badge-platform-wasm]
![badge-platform-linux]
![badge-platform-macos]
![badge-platform-ios]
Expand All @@ -20,10 +21,6 @@
![badge-support-js-ir]
![badge-support-linux-arm]

<!--
![badge-platform-wasm]
-->

Low level core cryptographic components for Kotlin Multiplatform

NOTE: For Jvm, `Digest` extends `java.security.MessageDigest` and `Mac` extends `javax.crypto.Mac`
Expand Down Expand Up @@ -244,8 +241,8 @@ dependencies {
[badge-license]: https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat

<!-- TAG_DEPENDENCIES -->
[badge-kotlin]: https://img.shields.io/badge/kotlin-1.9.21-blue.svg?logo=kotlin
[badge-endians]: https://img.shields.io/badge/kotlincrypto.endians-0.2.0-blue.svg
[badge-kotlin]: https://img.shields.io/badge/kotlin-1.9.23-blue.svg?logo=kotlin
[badge-endians]: https://img.shields.io/badge/kotlincrypto.endians-0.3.0-blue.svg

<!-- TAG_PLATFORMS -->
[badge-platform-android]: http://img.shields.io/badge/-android-6EDB8D.svg?style=flat
Expand Down
26 changes: 24 additions & 2 deletions build-logic/src/main/kotlin/-KmpConfigurationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.matthewnelson.kmp.configuration.extension.KmpConfigurationExtension
import io.matthewnelson.kmp.configuration.extension.container.target.KmpConfigurationContainerDsl
import org.gradle.api.Action
import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

fun KmpConfigurationExtension.configureShared(
publish: Boolean = false,
Expand All @@ -32,8 +33,29 @@ fun KmpConfigurationExtension.configureShared(
}

js()
// wasmJs {}
// wasmWasi {}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
target {
browser {
testTask {
useMocha { timeout = "30s" }
}
}
nodejs {
testTask {
useMocha { timeout = "30s" }
}
}
}
}

@OptIn(ExperimentalWasmDsl::class)
wasmWasi {
target {
nodejs()
}
}

androidNativeAll()

Expand Down
52 changes: 15 additions & 37 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension

plugins {
alias(libs.plugins.multiplatform) apply(false)
alias(libs.plugins.android.library) apply(false)
alias(libs.plugins.binaryCompat)
alias(libs.plugins.gradleVersions)
}

allprojects {
Expand All @@ -39,44 +40,21 @@ plugins.withType<YarnPlugin> {
the<YarnRootExtension>().lockFileDirectory = rootDir.resolve(".kotlin-js-store")
}

apiValidation {
@Suppress("LocalVariableName")
val CHECK_PUBLICATION = findProperty("CHECK_PUBLICATION") as? String

if (CHECK_PUBLICATION != null) {
ignoredProjects.add("check-publication")
} else {
nonPublicMarkers.add("org.kotlincrypto.core.InternalKotlinCryptoApi")
plugins.withType<NodeJsRootPlugin> {
the<NodeJsRootExtension>().apply {
nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}

tasks.withType<DependencyUpdatesTask> {
// Example 1: reject all non stable versions
rejectVersionIf {
isNonStable(candidate.version)
}

// Example 2: disallow release candidates as upgradable versions from stable versions
rejectVersionIf {
isNonStable(candidate.version) && !isNonStable(currentVersion)
tasks.withType<KotlinNpmInstallTask>().configureEach {
args.add("--ignore-engines")
}
}

// Example 3: using the full syntax
resolutionStrategy {
componentSelection {
@Suppress("RedundantSamConstructor")
all(Action {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject("Release candidate")
}
})
}
apiValidation {
if (findProperty("CHECK_PUBLICATION") != null) {
ignoredProjects.add("check-publication")
} else {
nonPublicMarkers.add("org.kotlincrypto.core.InternalKotlinCryptoApi")
}
}
12 changes: 5 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[versions]
android = "8.1.4"
androidxTestRunner = "1.5.2"
binaryCompat = "0.13.2"
configuration = "0.1.5"
endians = "0.2.0"
gradleVersions = "0.50.0"
kotlin = "1.9.21"
publish = "0.25.3"
binaryCompat = "0.14.0"
configuration = "0.2.1"
endians = "0.3.0"
kotlin = "1.9.23"
publish = "0.27.0"

[libraries]
kotlincrypto-endians-endians = { module = "org.kotlincrypto.endians:endians", version.ref = "endians" }
Expand All @@ -21,4 +20,3 @@ androidx-test-runner = { module = "androidx.test:runner", version.ref = "android
android-library = { id = "com.android.library", version.ref = "android" }
binaryCompat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompat" }
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" }
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

# https://gradle.org/release-checksums/
distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionSha256Sum=85719317abd2112f021d4f41f09ec370534ba288432065f4b477b6a3b652910d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
3 changes: 0 additions & 3 deletions library/common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@ public abstract interface class org/kotlincrypto/core/Updatable {
public abstract fun update ([BII)V
}

public final class org/kotlincrypto/core/_AndroidSdkIntKt {
}

0 comments on commit ff04c4e

Please sign in to comment.