Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e0c0dce

Browse files
committedNov 18, 2023
Add minimal mention of Wasm/TS support in docs
1 parent 7f67306 commit e0c0dce

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed
 

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Djinni generator parses an interface definition file and generates:
2020
- Objective-C++ code to convert between C++ and Objective-C
2121
- Python and C code to convert between C++ and Python over CFFI
2222
- C++/CLI code to convert between C++ and C#
23+
- C++ code to convert between WebAssembly and TS/JS
2324

2425

2526
## Installation
@@ -86,3 +87,5 @@ The code in this repository is in large portions copied from [dropbox/djinni](ht
8687
- Jacob Potter
8788
- Iulia Tamas
8889
- Andrew Twyman
90+
91+
WebAssembly support is borrowed in large part from [snapchat/djinni](https://github.com/snapchat/djinni).

‎docs/cli-usage.md

+8
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ djinni \
145145
| `--cppcli-namespace ...` | The namespace name to use for generated C++/CLI classes. |
146146
| `--cppcli-include-cpp-prefix <prefix>` | The prefix for `#include` of the main C++ header files from C++/CLI files. |
147147

148+
### WebAssembly/TS/JS
149+
150+
| Argument | Description |
151+
|----------------------------------------|----------------------------------------------------------------------------|
152+
| `--wasm-out <out-folder>` | WebAssembly bridge code output folder |
153+
| `--ts-out <out-folder>` | Path to the Typescript type definitions output folder |
154+
| `--ts-module <module>` | Name of the module for the Typescript types. `module.ts` by default. |
155+
148156

149157
### Yaml Generation
150158

‎src/main/scala/djinni/TsGenerator.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class TsGenerator(spec: Spec) extends Generator(spec) {
156156
}
157157
}
158158

159-
//------------------------------------------------------------------------
159+
// ------------------------------------------------------------------------
160160
private def generateEnum(
161161
origin: String,
162162
ident: Ident,
@@ -245,7 +245,7 @@ class TsGenerator(spec: Spec) extends Generator(spec) {
245245
) + sep + name
246246
case None => name
247247
}
248-
//--------------------------------------------------------------------------
248+
// --------------------------------------------------------------------------
249249
override def generate(idl: Seq[TypeDecl]) {
250250
createFile(
251251
spec.tsOutFolder.get,

‎src/main/scala/djinni/WasmGenerator.scala

+14-14
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
234234
if (!spec.wasmOmitNsAlias && !spec.wasmNamespace.isEmpty) {
235235
w.wl(
236236
s""" ::djinni::djinni_register_name_in_ns("${fullyQualifiedName}", "${spec.wasmNamespace.get}.${idJs
237-
.ty(ident)}");"""
237+
.ty(ident)}");"""
238238
)
239239
}
240240
w.wl(s"});")
@@ -249,7 +249,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
249249
}
250250
}
251251

252-
//------------------------------------------------------------------------------
252+
// ------------------------------------------------------------------------------
253253

254254
override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) {
255255
val refs = new WasmRefs(ident.name)
@@ -306,7 +306,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
306306
if (!spec.wasmOmitNsAlias && !spec.wasmNamespace.isEmpty) {
307307
w.wl(
308308
s""" ::djinni::djinni_register_name_in_ns("${fullyQualifiedName}", "${spec.wasmNamespace.get}.${idJs
309-
.ty(ident)}");"""
309+
.ty(ident)}");"""
310310
)
311311
}
312312
w.wl(s"});")
@@ -484,7 +484,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
484484
w.wl(";")
485485
m.ret.fold(())(r =>
486486
w.wl(s"return ${helperClass(r.resolved)}::fromCpp(${cppMarshal
487-
.maybeMove("r", r)});")
487+
.maybeMove("r", r)});")
488488
)
489489
}
490490
w.w("catch(const std::exception& e)").braced {
@@ -506,7 +506,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
506506
val constModifier = if (m.const) " const" else ""
507507
w.w(
508508
s"${cppMarshal.fqReturnType(m.ret)} ${helper}::JsProxy::${idCpp
509-
.method(m.ident)}("
509+
.method(m.ident)}("
510510
)
511511
w.w(
512512
m.params
@@ -526,7 +526,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
526526
s")",
527527
p => {
528528
s"${helperClass(p.ty.resolved)}::fromCpp(${cppMarshal
529-
.maybeMove(idCpp.local(p.ident), p.ty)})"
529+
.maybeMove(idCpp.local(p.ident), p.ty)})"
530530
}
531531
)
532532
w.wl(";")
@@ -556,7 +556,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
556556
val classRegister =
557557
if (!spec.wasmOmitNsAlias && !spec.wasmNamespace.isEmpty) {
558558
s"""::djinni::DjinniClass_<$cls>("${fullyQualifiedJsName}", "${spec.wasmNamespace.get}.${idJs
559-
.ty(ident.name)}")"""
559+
.ty(ident.name)}")"""
560560
} else {
561561
s"""em::class_<$cls>("${fullyQualifiedJsName}")"""
562562
}
@@ -566,13 +566,13 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
566566
s""".smart_ptr<std::shared_ptr<$cls>>("${fullyQualifiedJsName}")"""
567567
)
568568
w.wl(s""".function("${idJs
569-
.method("native_destroy")}", &$helper::nativeDestroy)""")
569+
.method("native_destroy")}", &$helper::nativeDestroy)""")
570570
if (i.ext.cpp) {
571571
for (m <- i.methods.filter(m => !m.static || m.lang.js)) {
572572
val funcType = if (m.static) "class_function" else "function"
573573
w.wl(s""".$funcType("${idJs.method(
574-
m.ident.name
575-
)}", $helper::${idCpp.method(m.ident)})""")
574+
m.ident.name
575+
)}", $helper::${idCpp.method(m.ident)})""")
576576
}
577577
}
578578
w.wl(";")
@@ -661,7 +661,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
661661
"}",
662662
f => {
663663
s"""${helperClass(f.ty.resolved)}::Boxed::toCpp(j["${idJs
664-
.field(f.ident.name)}"])"""
664+
.field(f.ident.name)}"])"""
665665
}
666666
)
667667
w.wl(";")
@@ -670,9 +670,9 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
670670
w.wl("em::val js = em::val::object();")
671671
for (f <- r.fields) {
672672
w.wl(s"""js.set("${idJs.field(f.ident.name)}", ${helperClass(
673-
f.ty.resolved
674-
)}::Boxed::fromCpp(${cppMarshal
675-
.maybeMove("c." + idCpp.field(f.ident), f.ty)}));""")
673+
f.ty.resolved
674+
)}::Boxed::fromCpp(${cppMarshal
675+
.maybeMove("c." + idCpp.field(f.ident), f.ty)}));""")
676676
}
677677
w.wl("return js;")
678678
}

‎src/main/scala/djinni/YamlGenerator.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class YamlGenerator(spec: Spec) extends Generator(spec) {
206206
private def ts(td: TypeDecl) = Map[String, Any](
207207
"typename" -> tsMarshal.toTsType(mexpr(td), /*addNullability*/ false),
208208
"module" -> QuotedString("./" + spec.tsModule)
209-
//, "generic" -> false
209+
// , "generic" -> false
210210
)
211211

212212
// TODO: there has to be a way to do all this without the MExpr/Meta conversions?

‎src/main/scala/djinni/parser.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ case class Parser(includePaths: List[String]) {
9191
InternTypeDecl(ident, typeParams, body, doc, origin)
9292
}
9393

94-
def ext(default: Ext): Parser[Ext] =
94+
def ext(default: Ext): Parser[Ext] =
9595
(rep1("+" ~> ident) >> checkExts) | success(default)
9696
def extRecord: Parser[Ext] = ext(
9797
Ext(

0 commit comments

Comments
 (0)
Please sign in to comment.