-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final WASM retake (with disabled libraries depending on coroutines/at…
…omicfu) (#1677)
- Loading branch information
Showing
29 changed files
with
210 additions
and
126 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
50 changes: 50 additions & 0 deletions
50
buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/js/Wasm.kt
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,50 @@ | ||
package korlibs.korge.gradle.targets.js | ||
|
||
import korlibs.korge.gradle.gkotlin | ||
import korlibs.korge.gradle.kotlin | ||
import korlibs.korge.gradle.targets.* | ||
import korlibs.korge.gradle.targets.js.configureWasm | ||
import korlibs.korge.gradle.targets.wasm.* | ||
import korlibs.korge.gradle.util.* | ||
import korlibs.root.* | ||
import org.gradle.api.* | ||
import org.jetbrains.kotlin.gradle.targets.js.npm.* | ||
import java.io.* | ||
|
||
fun Project.configureWasm(projectType: ProjectType, binaryen: Boolean = false) { | ||
if (gkotlin.targets.findByName("wasm") != null) return | ||
|
||
configureWasm(executable = true, binaryen = binaryen) | ||
|
||
if (projectType.isExecutable) { | ||
|
||
project.tasks.createThis<Task>("wasmCreateIndex") { | ||
doFirst { | ||
wasmCreateIndex(project) | ||
} | ||
} | ||
project.tasks.findByName("wasmBrowserDevelopmentRun")?.apply { | ||
dependsOn("wasmCreateIndex") | ||
doFirst { wasmCreateIndex(project) } | ||
} | ||
val task = project.tasks.createThis<Task>("runWasm") { | ||
dependsOn("wasmRun") | ||
} | ||
} | ||
} | ||
|
||
fun wasmCreateIndex(project: Project) { | ||
val compilation = project.kotlin.wasm().compilations["main"]!! | ||
val npmDir = compilation.npmProject.dir | ||
File(npmDir, "kotlin/index.html").also { it.parentFile.mkdirs() }.writeText( | ||
""" | ||
<html> | ||
<script type = 'module'> | ||
import module from "./${npmDir.name}.mjs" | ||
console.log(module) | ||
//instantiate(); | ||
</script> | ||
</html> | ||
""".trimIndent() | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/wasm/ConfigureWasm.kt
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,30 @@ | ||
package korlibs.korge.gradle.targets.wasm | ||
|
||
import korlibs.* | ||
import org.gradle.api.* | ||
|
||
fun Project.configureWasm(executable: Boolean, binaryen: Boolean = false) { | ||
kotlin { | ||
wasm { | ||
if (binaryen) applyBinaryen() | ||
|
||
if (executable) { | ||
binaries.executable() | ||
} | ||
//applyBinaryen() | ||
browser { | ||
commonWebpackConfig { experiments = mutableSetOf("topLevelAwait") } | ||
if (executable) { | ||
this.distribution { | ||
} | ||
} | ||
//testTask { | ||
// it.useKarma { | ||
// //useChromeHeadless() | ||
// this.webpackConfig.configDirectory = File(rootProject.rootDir, "karma.config.d") | ||
// } | ||
//} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
#enable.wasm=true | ||
enable.wasm=false |
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 |
---|---|---|
@@ -1 +1 @@ | ||
#enable.wasm=true | ||
enable.wasm=false |
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 |
---|---|---|
@@ -1 +1 @@ | ||
#enable.wasm=true | ||
enable.wasm=false |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
#enable.wasm=true | ||
enable.wasm=false |
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 |
---|---|---|
@@ -1 +1 @@ | ||
#enable.wasm=true | ||
enable.wasm=false |
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
Oops, something went wrong.