Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mutagene committed Nov 22, 2023
1 parent 848a965 commit 65e90a1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
9 changes: 6 additions & 3 deletions docs/cli-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ djinni \

| 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. |
| `--wasm-out <out-folder>` | WebAssembly bridge code output folder. |
| `--wasm-include-prefix` | The prefix for #includes of WASM bridge C++ header files. |
| `--wasm-include-cpp-prefix` | The prefix for #includes of C++ header files. |
| `--wasm-base-lib-include-prefix` | The path prefix to be added to djinni support library inlcude lines in generated files |
| `--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
37 changes: 36 additions & 1 deletion docs/generated-code-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,41 @@ Add all generated files to your build target, and link against the [djinni-suppo

C++/CLI sources have to be compiled with MSVC and the [`/clr` (Common Language Runtime Compilation)](https://docs.microsoft.com/en-us/cpp/build/reference/clr-common-language-runtime-compilation?view=msvc-160) option.

## TS/JS C++/WASM Project

Djinni can generate code that bridges C++ (that compiles to Web Assembly) and Javascript/TypeScript in web browsers.

For WASM, Djinni generates:
- C++ code, which should be compiled into the WASM bindary
- TypeScript code, provides optional TypeScript interface definitions

The generated code can be used with both plain Javascript and TypeScript.

Almost all Djinni features are supported, including importing external types via
yaml.

Notable differences when comparing to the Java/ObjC support:

- deriving(ord, eq) is not applicable to Javascript because JS doesn't support
overloading standard comparison methods.

### Includes & Build target

The following code will be generated for each defined type:

| Type | C++ header | C++ source | WASM header/sources | TS definitions |
|------------|--------------------------|----------------------------|-------------------------------------|----------------------|
| Enum/Flags | my\_enum.hpp | | my_enum.hpp, my_enum.cpp | module.ts :three: |
| | my\_enum+json.hpp :two: | | | |
| Record | my\_record.hpp | my\_record.cpp | my_record.hpp, my_enum.cpp | |
| | my\_record+json.hpp :two:| | | |
| Interface | my\_interface.hpp | my\_interface.cpp :one: | my_interface.hpp, my_interface.cpp | |

- :one: Generated only for types that contain constants.
- :two: Generated only if cpp json serialization is enabled.
- :three: Name of file configurable via command-line options.


## C++ JSON Serialization support

Serialization from C++ types to/from JSON is supported. This feature is currently only enabled for `nlohmann/json`, and if enabled creates `to_json`/`from_json` methods for all djinni records and enums.
Expand Down Expand Up @@ -219,4 +254,4 @@ namespace nlohmann {
}
};
}
```
```

0 comments on commit 65e90a1

Please sign in to comment.