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

Revert "Remove Wasm JS support (#2207)" #2211

Merged
merged 1 commit into from
Jul 29, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ New:
- Nothing yet!

Changed:
- Removed Wasm JS targets for common Redwood modules. They are causing CI problems, and we're not ready for Wasm anyway.
- Nothing yet!

Fixed:
- Nothing yet!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodB
iosTargets()
modifiedGroup[JsTests, NodeJs].applyTo(js())
jvm()
wasmJs().nodejs()
}
// Needed for lint in downstream Android projects to analyze this dependency.
project.plugins.apply("com.android.lint")
Expand All @@ -313,6 +314,7 @@ private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodB
iosTargets()
modifiedGroup[JsTests, NodeJs].applyTo(js())
jvm()
wasmJs().nodejs()
}
}
Tooling -> {
Expand Down
2 changes: 1 addition & 1 deletion redwood-compose/api/redwood-compose.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Alias: ios => [iosArm64, iosSimulatorArm64, iosX64]
// Rendering settings:
// - Signature version: 2
Expand Down
2 changes: 1 addition & 1 deletion redwood-layout-api/api/redwood-layout-api.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-layout-compose/api/redwood-layout-compose.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-layout-testing/api/redwood-layout-testing.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-layout-widget/api/redwood-layout-widget.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-lazylayout-api/api/redwood-lazylayout-api.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-leak-detector/api/redwood-leak-detector.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
12 changes: 12 additions & 0 deletions redwood-leak-detector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ kotlin {
}
}
}
wasmJs {
nodejs {
testTask {
useMocha {
// We use up to 10s of wall clock time to test leaks.
timeout = '15s'
// Required for access to V8 GC function.
nodeJsArgs.add('--expose-gc')
}
}
}
}

sourceSets {
commonMain {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Square, Inc.
*
* 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.
*/
@file:Suppress("NOTHING_TO_INLINE")

package app.cash.redwood.leaks

internal actual typealias ConcurrentMutableList<T> = ArrayList<T>

internal actual inline fun <T> concurrentMutableListOf(): ConcurrentMutableList<T> {
return arrayListOf()
}

internal actual inline operator fun <T> ConcurrentMutableList<T>.plusAssign(element: T) {
add(element)
}

internal actual inline fun <T> ConcurrentMutableList<T>.removeIf(predicate: (element: T) -> Boolean) {
var i = 0
while (i < size) {
if (predicate(get(i))) {
removeAt(i)
} else {
i++
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2024 Square, Inc.
*
* 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 app.cash.redwood.leaks

private external val globalThis: GlobalThis

private external class GlobalThis {
fun hasOwnProperty(name: String): Boolean
fun gc()
}

internal actual fun detectGc(): Gc {
if (globalThis.hasOwnProperty("gc")) {
return GlobalThisGc()
}
return Gc.None
}

private class GlobalThisGc : Gc {
override suspend fun collect() {
globalThis.gc()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024 Square, Inc.
*
* 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.
*/
@file:Suppress("NOTHING_TO_INLINE")

package app.cash.redwood.leaks

internal actual inline fun hasWeakReference(): Boolean {
return true
}

internal actual class WeakReference<T : Any>
private constructor(
private val real: WeakRef<JsReference<T>>,
) {
actual constructor(referred: T) : this(WeakRef(referred.toJsReference()))

actual fun get(): T? {
return real.deref()?.get()
}
}

private external class WeakRef<T : JsAny>(reference: T) {
fun deref(): T?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2024 Square, Inc.
*
* 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 app.cash.redwood.leaks

import kotlin.time.Duration
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext

internal actual suspend fun delayForGc(duration: Duration) {
// Force a wall clock delay for JS Gc.
withContext(Dispatchers.Default) {
delay(duration)
}
}
2 changes: 1 addition & 1 deletion redwood-protocol-guest/api/redwood-protocol-guest.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-protocol-host/api/redwood-protocol-host.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-protocol/api/redwood-protocol.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-runtime/api/redwood-runtime.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Alias: ios => [iosArm64, iosSimulatorArm64, iosX64]
// Rendering settings:
// - Signature version: 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* 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 app.cash.redwood.ui

internal actual const val DENSITY_MULTIPLIER = 1.0
2 changes: 1 addition & 1 deletion redwood-testing/api/redwood-testing.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-widget-compose/api/redwood-widget-compose.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-widget-testing/api/redwood-widget-testing.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down
2 changes: 1 addition & 1 deletion redwood-widget/api/redwood-widget.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js]
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, wasmJs]
// Alias: ios => [iosArm64, iosSimulatorArm64, iosX64]
// Rendering settings:
// - Signature version: 2
Expand Down