Skip to content

Commit

Permalink
Add minimal mention of Wasm/TS support in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mutagene committed Nov 18, 2023
1 parent 7f67306 commit e0c0dce
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Djinni generator parses an interface definition file and generates:
- Objective-C++ code to convert between C++ and Objective-C
- Python and C code to convert between C++ and Python over CFFI
- C++/CLI code to convert between C++ and C#
- C++ code to convert between WebAssembly and TS/JS


## Installation
Expand Down Expand Up @@ -86,3 +87,5 @@ The code in this repository is in large portions copied from [dropbox/djinni](ht
- Jacob Potter
- Iulia Tamas
- Andrew Twyman

WebAssembly support is borrowed in large part from [snapchat/djinni](https://github.com/snapchat/djinni).
8 changes: 8 additions & 0 deletions docs/cli-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ djinni \
| `--cppcli-namespace ...` | The namespace name to use for generated C++/CLI classes. |
| `--cppcli-include-cpp-prefix <prefix>` | The prefix for `#include` of the main C++ header files from C++/CLI files. |

### WebAssembly/TS/JS

| Argument | Description |
|----------------------------------------|----------------------------------------------------------------------------|
| `--wasm-out <out-folder>` | WebAssembly bridge code output folder |
| `--ts-out <out-folder>` | Path to the Typescript type definitions output folder |
| `--ts-module <module>` | Name of the module for the Typescript types. `module.ts` by default. |


### Yaml Generation

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/djinni/TsGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class TsGenerator(spec: Spec) extends Generator(spec) {
}
}

//------------------------------------------------------------------------
// ------------------------------------------------------------------------
private def generateEnum(
origin: String,
ident: Ident,
Expand Down Expand Up @@ -245,7 +245,7 @@ class TsGenerator(spec: Spec) extends Generator(spec) {
) + sep + name
case None => name
}
//--------------------------------------------------------------------------
// --------------------------------------------------------------------------
override def generate(idl: Seq[TypeDecl]) {
createFile(
spec.tsOutFolder.get,
Expand Down
28 changes: 14 additions & 14 deletions src/main/scala/djinni/WasmGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
if (!spec.wasmOmitNsAlias && !spec.wasmNamespace.isEmpty) {
w.wl(
s""" ::djinni::djinni_register_name_in_ns("${fullyQualifiedName}", "${spec.wasmNamespace.get}.${idJs
.ty(ident)}");"""
.ty(ident)}");"""
)
}
w.wl(s"});")
Expand All @@ -249,7 +249,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
}
}

//------------------------------------------------------------------------------
// ------------------------------------------------------------------------------

override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) {
val refs = new WasmRefs(ident.name)
Expand Down Expand Up @@ -306,7 +306,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
if (!spec.wasmOmitNsAlias && !spec.wasmNamespace.isEmpty) {
w.wl(
s""" ::djinni::djinni_register_name_in_ns("${fullyQualifiedName}", "${spec.wasmNamespace.get}.${idJs
.ty(ident)}");"""
.ty(ident)}");"""
)
}
w.wl(s"});")
Expand Down Expand Up @@ -484,7 +484,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
w.wl(";")
m.ret.fold(())(r =>
w.wl(s"return ${helperClass(r.resolved)}::fromCpp(${cppMarshal
.maybeMove("r", r)});")
.maybeMove("r", r)});")
)
}
w.w("catch(const std::exception& e)").braced {
Expand All @@ -506,7 +506,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
val constModifier = if (m.const) " const" else ""
w.w(
s"${cppMarshal.fqReturnType(m.ret)} ${helper}::JsProxy::${idCpp
.method(m.ident)}("
.method(m.ident)}("
)
w.w(
m.params
Expand All @@ -526,7 +526,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
s")",
p => {
s"${helperClass(p.ty.resolved)}::fromCpp(${cppMarshal
.maybeMove(idCpp.local(p.ident), p.ty)})"
.maybeMove(idCpp.local(p.ident), p.ty)})"
}
)
w.wl(";")
Expand Down Expand Up @@ -556,7 +556,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
val classRegister =
if (!spec.wasmOmitNsAlias && !spec.wasmNamespace.isEmpty) {
s"""::djinni::DjinniClass_<$cls>("${fullyQualifiedJsName}", "${spec.wasmNamespace.get}.${idJs
.ty(ident.name)}")"""
.ty(ident.name)}")"""
} else {
s"""em::class_<$cls>("${fullyQualifiedJsName}")"""
}
Expand All @@ -566,13 +566,13 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
s""".smart_ptr<std::shared_ptr<$cls>>("${fullyQualifiedJsName}")"""
)
w.wl(s""".function("${idJs
.method("native_destroy")}", &$helper::nativeDestroy)""")
.method("native_destroy")}", &$helper::nativeDestroy)""")
if (i.ext.cpp) {
for (m <- i.methods.filter(m => !m.static || m.lang.js)) {
val funcType = if (m.static) "class_function" else "function"
w.wl(s""".$funcType("${idJs.method(
m.ident.name
)}", $helper::${idCpp.method(m.ident)})""")
m.ident.name
)}", $helper::${idCpp.method(m.ident)})""")
}
}
w.wl(";")
Expand Down Expand Up @@ -661,7 +661,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
"}",
f => {
s"""${helperClass(f.ty.resolved)}::Boxed::toCpp(j["${idJs
.field(f.ident.name)}"])"""
.field(f.ident.name)}"])"""
}
)
w.wl(";")
Expand All @@ -670,9 +670,9 @@ class WasmGenerator(spec: Spec) extends Generator(spec) {
w.wl("em::val js = em::val::object();")
for (f <- r.fields) {
w.wl(s"""js.set("${idJs.field(f.ident.name)}", ${helperClass(
f.ty.resolved
)}::Boxed::fromCpp(${cppMarshal
.maybeMove("c." + idCpp.field(f.ident), f.ty)}));""")
f.ty.resolved
)}::Boxed::fromCpp(${cppMarshal
.maybeMove("c." + idCpp.field(f.ident), f.ty)}));""")
}
w.wl("return js;")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/djinni/YamlGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class YamlGenerator(spec: Spec) extends Generator(spec) {
private def ts(td: TypeDecl) = Map[String, Any](
"typename" -> tsMarshal.toTsType(mexpr(td), /*addNullability*/ false),
"module" -> QuotedString("./" + spec.tsModule)
//, "generic" -> false
// , "generic" -> false
)

// TODO: there has to be a way to do all this without the MExpr/Meta conversions?
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/djinni/parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ case class Parser(includePaths: List[String]) {
InternTypeDecl(ident, typeParams, body, doc, origin)
}

def ext(default: Ext): Parser[Ext] =
def ext(default: Ext): Parser[Ext] =
(rep1("+" ~> ident) >> checkExts) | success(default)
def extRecord: Parser[Ext] = ext(
Ext(
Expand Down

0 comments on commit e0c0dce

Please sign in to comment.