Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
82d1b12c
Commit
82d1b12c
authored
Sep 03, 2021
by
Shagen Ogandzhanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minimal testing setup for wasm / kjs interop
parent
56b88584
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
105 additions
and
9 deletions
+105
-9
settings.gradle
settings.gradle
+1
-1
build.gradle.kts
skiko/build.gradle.kts
+18
-1
wasm.js
skiko/karma.config.d/wasm.js
+30
-0
wrapper.cc
skiko/src/jsMain/cpp/wrapper.cc
+10
-7
wasmsetup.js
skiko/src/jsTest/config/wasmsetup.js
+11
-0
WasmTests.kt
skiko/src/jsTest/kotlin/WasmTests.kt
+35
-0
No files found.
settings.gradle
View file @
82d1b12c
rootProject
.
name
=
"skiko-all"
includeBuild
(
"samples/SkiaJvmSample"
)
includeBuild
(
"skiko"
)
\ No newline at end of file
includeBuild
(
"skiko"
)
skiko/build.gradle.kts
View file @
82d1b12c
...
...
@@ -114,7 +114,15 @@ kotlin {
}
js
(
IR
)
{
browser
()
browser
()
{
testTask
{
testLogging
.
showStandardStreams
=
true
dependsOn
(
project
.
tasks
.
named
(
"wasmCompile"
))
useKarma
()
{
useChromeHeadless
()
}
}
}
binaries
.
executable
()
}
...
...
@@ -163,6 +171,14 @@ kotlin {
implementation
(
kotlin
(
"test-junit"
))
}
}
val
jsTest
by
getting
{
dependencies
{
implementation
(
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0"
)
implementation
(
kotlin
(
"test-js"
))
}
}
if
(
supportNative
)
{
val
macosX64Main
by
getting
{
}
...
...
@@ -328,6 +344,7 @@ project.tasks.register<Exec>("wasmCompile") {
"-I$skiaDir/include"
,
"-I$skiaDir/include/gpu"
,
"-std=c++17"
,
"--bind"
,
"-o"
,
outJs
,
*
libs
.
files
.
map
{
it
.
absolutePath
}.
toTypedArray
(),
*
srcs
...
...
skiko/karma.config.d/wasm.js
0 → 100644
View file @
82d1b12c
// see https://kotlinlang.org/docs/js-project-setup.html#webpack-configuration-file
const
path
=
require
(
"path"
);
config
.
browserConsoleLogOptions
.
level
=
"debug"
;
const
basePath
=
config
.
basePath
;
const
projectPath
=
path
.
resolve
(
basePath
,
".."
,
".."
,
".."
,
".."
,
".."
);
const
setupPath
=
path
.
resolve
(
projectPath
,
"src"
,
"jsTest"
,
"config"
);
const
wasmPath
=
path
.
resolve
(
projectPath
,
"build"
,
"wasm"
)
const
debug
=
message
=>
console
.
log
(
`[karma-config]
${
message
}
`
);
debug
(
`karma basePath:
${
basePath
}
`
);
debug
(
`karma setupPath:
${
setupPath
}
`
);
debug
(
`karma wasmPath:
${
wasmPath
}
`
);
config
.
proxies
=
{
"/wasm/"
:
wasmPath
}
config
.
files
=
[
path
.
resolve
(
setupPath
,
"wasmsetup.js"
),
path
.
resolve
(
wasmPath
,
"skiko.js"
),
{
pattern
:
path
.
resolve
(
wasmPath
,
"skiko.wasm"
),
included
:
false
,
served
:
true
,
watched
:
false
},
].
concat
(
config
.
files
);
const
fs
=
require
(
"fs"
);
fs
.
writeFileSync
(
"KARMA.txt"
,
JSON
.
stringify
(
config
,
null
,
4
));
skiko/src/jsMain/cpp/wrapper.cc
View file @
82d1b12c
#include "GrBackendSurface.h"
#include "GrDirectContext.h"
#include <emscripten.h>
#include <emscripten/bind.h>
using
namespace
emscripten
;
EMSCRIPTEN_KEEPALIVE
extern
"C"
void
*
init_surface
()
{
return
nullptr
;
}
int
main
()
{
printf
(
"Hello from WASM
\n
"
);
//void* ctx = GrDirectContext::MakeGL().release();
//printf("Context is %p\n");
return
0
;
bool
ping
()
{
return
true
;
}
EMSCRIPTEN_BINDINGS
(
Skiko
)
{
function
(
"ping"
,
&
ping
);
};
skiko/src/jsTest/config/wasmsetup.js
0 → 100644
View file @
82d1b12c
var
Module
=
{};
Module
[
'locateFile'
]
=
(
path
,
scriptDirectory
)
=>
{
return
"/wasm/skiko.wasm"
;
};
var
ModulePromised
=
new
Promise
(
function
(
resolve
,
reject
)
{
Module
[
'onRuntimeInitialized'
]
=
_
=>
{
resolve
(
Module
);
};
});
skiko/src/jsTest/kotlin/WasmTests.kt
0 → 100644
View file @
82d1b12c
package
org.jetbrains.skiko.wasm
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.promise
import
kotlin.coroutines.*
import
kotlin.js.Promise
import
kotlin.test.Test
import
kotlin.test.assertEquals
import
kotlin.test.assertTrue
external
interface
ModuleInterface
{
fun
ping
():
Boolean
}
external
val
ModulePromised
:
Promise
<
ModuleInterface
>
suspend
fun
<
T
>
Promise
<
T
>.
await
():
T
=
suspendCoroutine
{
cont
->
then
({
cont
.
resume
(
it
)
},
{
cont
.
resumeWithException
(
it
)
})
}
private
fun
async
(
block
:
suspend
()
->
Unit
):
dynamic
=
GlobalScope
.
promise
{
block
()
}
private
fun
withModule
(
block
:
ModuleInterface
.()
->
Unit
)
=
async
{
val
module
=
ModulePromised
.
await
()
block
.
invoke
(
module
)
}
class
WasmTests
{
@Test
fun
pingTest
()
=
withModule
{
assertTrue
(
this
.
ping
())
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment