Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codewithmirza/dtow
Compile some C code to WASM and call it from Dart (non-Flutter) web app compiled to WASM.
https://github.com/codewithmirza/dtow
c compilation dart web-application webassembly
Last synced: about 2 months ago
JSON representation
Compile some C code to WASM and call it from Dart (non-Flutter) web app compiled to WASM.
- Host: GitHub
- URL: https://github.com/codewithmirza/dtow
- Owner: codewithmirza
- Created: 2024-03-19T06:51:09.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-02T18:07:54.000Z (9 months ago)
- Last Synced: 2024-08-21T06:54:22.431Z (5 months ago)
- Topics: c, compilation, dart, web-application, webassembly
- Language: JavaScript
- Homepage: https://codewithmirza.github.io/dtow/
- Size: 6 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Compiled some C code to WASM and called it from Dart (non-Flutter) web app compiled to WASM.
This project demonstrates the process of compiling C code into WebAssembly (WASM) and calling it from a Dart web application, also compiled to WebAssembly. By leveraging WebAssembly, developers can integrate performance-sensitive C code directly into Dart web applications without the need for server-side processing.
## Project Description
For this project, we've compiled a small C module using Emscripten to create a WASM module. This module contains a single C function that will be invoked from Dart code. The Dart code utilizes the `dart:ffi` library and `@Native` annotations to import the C function and interact with it. Additionally, the Dart code makes use of the `package:web` library to interact with the DOM for input and output purposes.
The workflow involves compiling the C code to WASM using Emscripten and the Dart code to WASMGC using the `dart compile wasm` command. This generates `main.dart.mjs` and `main.dart.wasm` files. The `main.dart.mjs` file is used to instantiate and invoke the WebAssembly-compiled Dart program.
## Sample Project Details
### Setup Instructions
1. Compile the C module to WASM:
```
emcc my_c_module.c WASM=1 -o my_c_module.wasm
```2. Compile the Dart code to WASMGC:
```
dart compile wasm main.dart
```---