-
-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #940 from mikepenz/feature/explore_wasm_compatiblity
Wasm compatiblity
- Loading branch information
Showing
17 changed files
with
3,161 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Usage | ||
|
||
### Generate Dependency Information | ||
|
||
```bash | ||
./gradlew app-wasm:exportLibraryDefinitions -PaboutLibraries.exportPath=src/wasmJsMain/resources/ | ||
``` | ||
|
||
### Run Wasm app | ||
|
||
``` | ||
./gradlew :app-wasm:wasmJsRun | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.compose") | ||
id("com.mikepenz.aboutlibraries.plugin") | ||
} | ||
|
||
// val copyWasmResources = tasks.create("copyWasmResourcesWorkaround", Copy::class.java) { | ||
// from(project(":shared").file("src/commonMain/resources")) | ||
// into("build/processedResources/wasm/main") | ||
// } | ||
// | ||
// afterEvaluate { | ||
// project.tasks.getByName("wasmProcessResources").finalizedBy(copyWasmResources) | ||
// } | ||
|
||
kotlin { | ||
wasmJs { | ||
moduleName = "aboutlibraries" | ||
browser { | ||
commonWebpackConfig { | ||
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).copy( | ||
open = mapOf( | ||
"app" to mapOf( | ||
"name" to "google chrome canary", | ||
"arguments" to listOf("--js-flags=--experimental-wasm-gc ") | ||
) | ||
), | ||
static = (devServer?.static ?: mutableListOf()).apply { | ||
add(project.rootDir.path) | ||
add(project.rootDir.path + "/common/") | ||
add(project.rootDir.path + "/nonAndroidMain/") | ||
add(project.rootDir.path + "/web/") | ||
}, | ||
) | ||
} | ||
} | ||
binaries.executable() | ||
} | ||
|
||
sourceSets { | ||
val wasmJsMain by getting { | ||
dependencies { | ||
implementation(compose.runtime) | ||
implementation(compose.ui) | ||
implementation(compose.foundation) | ||
implementation(compose.material) | ||
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) | ||
implementation(compose.components.resources) | ||
|
||
implementation(project(":aboutlibraries-core")) | ||
implementation(project(":aboutlibraries-compose")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
compose.experimental { | ||
web.application {} | ||
} | ||
|
||
compose { | ||
kotlinCompilerPlugin.set(libs.versions.composeCompilerJb.get()) | ||
// kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=${libs.versions.kotlinCore.get()}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import androidx.compose.ui.graphics.Color | ||
|
||
val Green = Color(0xff09B3AF) | ||
val GreenDark = Color(0xff008380) | ||
val GreenLight = Color(0x5de6e1) | ||
|
||
val Red200 = Color(0xfff297a2) | ||
val Red800 = Color(0xffd00036) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TopAppBar | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.window.CanvasBasedWindow | ||
import com.mikepenz.aboutlibraries.Libs | ||
import com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer | ||
import com.mikepenz.aboutlibraries.ui.compose.util.StableLibs | ||
import com.mikepenz.aboutlibraries.ui.compose.util.stable | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.jetbrains.compose.resources.ExperimentalResourceApi | ||
import org.jetbrains.compose.resources.resource | ||
|
||
@OptIn(ExperimentalComposeUiApi::class, ExperimentalResourceApi::class) | ||
fun main() { | ||
CanvasBasedWindow("AboutLibraries", canvasElementId = "aboutLibsCanvas") { | ||
SampleTheme { | ||
Scaffold( | ||
topBar = { TopAppBar(title = { Text("AboutLibraries Compose Desktop Sample") }) } | ||
) { | ||
val libraries = produceState<StableLibs?>(null) { | ||
value = withContext(Dispatchers.Default) { | ||
Libs.Builder() | ||
.withJson(resource("aboutlibraries.json").readBytes().decodeToString()) | ||
.build().stable | ||
} | ||
} | ||
|
||
LibrariesContainer( | ||
libraries.value, | ||
Modifier.fillMaxSize() | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.darkColors | ||
import androidx.compose.material.lightColors | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
|
||
private val DarkColorPalette = darkColors( | ||
primary = Green, | ||
primaryVariant = GreenDark, | ||
onPrimary = Color.White, | ||
secondary = Green, | ||
onSecondary = Color.White, | ||
error = Red200 | ||
) | ||
|
||
private val LightColorPalette = lightColors( | ||
primary = Green, | ||
primaryVariant = GreenDark, | ||
onPrimary = Color.White, | ||
secondary = Green, | ||
secondaryVariant = GreenDark, | ||
onSecondary = Color.White, | ||
error = Red800 | ||
) | ||
|
||
@Composable | ||
fun SampleTheme( | ||
darkTheme: Boolean = isSystemInDarkTheme(), | ||
content: @Composable() () -> Unit, | ||
) { | ||
val colors = if (darkTheme) { | ||
DarkColorPalette | ||
} else { | ||
LightColorPalette | ||
} | ||
|
||
MaterialTheme( | ||
colors = colors, | ||
content = content | ||
) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<!-- http://localhost:80 --> | ||
<meta http-equiv="origin-trial" content="AjytAe1FWUIWH/RzqsOWlXYw7kGwt11ejbvR/ArmAU4QbXIPg69wzpniDhPByiOZ9pdNqsdMsXsoxggVtfGhwwMAAABOeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwIiwiZmVhdHVyZSI6IldlYkFzc2VtYmx5R0MiLCJleHBpcnkiOjE2OTg5Njk1OTl9"> | ||
<!-- http://localhost:8080 --> | ||
<meta http-equiv="origin-trial" content="AtSRFRWKTCcQHDFUUQL1VaVz9mjmsK1xm5k0S8etkmvMLa5TsiNeQsle/eDgdZVkm1PM1WmrSMx52kI8yAP2UgEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0="> | ||
<!-- http://localhost:8081 --> | ||
<meta http-equiv="origin-trial" content="AspyK9xe4tO2aIvJWnr5HTRT9GqpGJID2qZjj+0OvhKHp9JrUP+92PF+Rt11Tyi7cKSEB7OFFGdeVs7Ns5TMhAUAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODEiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0="> | ||
<!-- http://localhost:8082 --> | ||
<meta http-equiv="origin-trial" content="AoPGqwBGEQW3twSDYvXt1JHz5zg7Z4o+Orwr8NxdVoXJ68zjwOi2C8/0w4xFYW6UUH8w97eIjykGOa/+jIBfTQMAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODIiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0="> | ||
<!-- http://localhost:8083 --> | ||
<meta http-equiv="origin-trial" content="AvV2HYiHMw7lpIVcmGMSVmm6xC0Gzu4W5xBnZExmfHtE5zyNKFszcyNGm5IfCFQ6swnMotbn16lS1ozkJ0QzEAEAAABQeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODMiLCJmZWF0dXJlIjoiV2ViQXNzZW1ibHlHQyIsImV4cGlyeSI6MTY5ODk2OTU5OX0="> | ||
|
||
<title>JetSnack with Kotlin/Wasm</title> | ||
<script type="application/javascript" src="skiko.js"></script> | ||
<script type="module" src="load.mjs"></script> | ||
<style> | ||
html, body { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
background-color: white; | ||
overflow: hidden; | ||
} | ||
|
||
#warning { | ||
position: absolute; | ||
top: 100px; | ||
left: 100px; | ||
z-index: 100; | ||
} | ||
#warning li { | ||
padding-bottom: 15px; | ||
} | ||
|
||
#warning span.code { | ||
font-family: monospace; | ||
} | ||
|
||
ul { | ||
margin-top: 0; | ||
margin-bottom: 15px; | ||
} | ||
|
||
#footer { | ||
position: fixed; | ||
bottom: 0; | ||
width: 100%; | ||
background-color: white; | ||
} | ||
|
||
#close { | ||
position: absolute; | ||
top: 0; | ||
right: 10px; | ||
cursor: pointer; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<canvas id="aboutLibsCanvas"></canvas> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { instantiate } from './aboutlibraries.uninstantiated.mjs'; | ||
|
||
await wasmSetup; | ||
|
||
let te = null; | ||
try { | ||
await instantiate({ skia: Module['asm'] }); | ||
} catch (e) { | ||
te = e; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Replace paths unavailable during compilation with `null`, so they will not be shown in devtools | ||
; | ||
(() => { | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const outDir = __dirname + "/kotlin/" | ||
const projecName = path.basename(__dirname); | ||
const mapFile = outDir + projecName + ".map" | ||
|
||
const sourcemap = JSON.parse(fs.readFileSync(mapFile)) | ||
const sources = sourcemap["sources"] | ||
srcLoop: for (let i in sources) { | ||
const srcFilePath = sources[i]; | ||
if (srcFilePath == null) continue; | ||
|
||
const srcFileCandidates = [ | ||
outDir + srcFilePath, | ||
outDir + srcFilePath.substring("../".length), | ||
outDir + "../" + srcFilePath, | ||
]; | ||
|
||
for (let srcFile of srcFileCandidates) { | ||
if (fs.existsSync(srcFile)) continue srcLoop; | ||
} | ||
|
||
sources[i] = null; | ||
} | ||
|
||
fs.writeFileSync(mapFile, JSON.stringify(sourcemap)); | ||
})(); |
Oops, something went wrong.