emscripten-core / emscripten-core/emscripten

Binding issues with Djinni

Aperta
#20,164 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
embind
Lingua principale
C++
Stelle
27.6k
Fork
3.6k
Merge medio
1g 14h
PR unite (30g)
125

Descrizione

I'm attempting to generate a very simple `MathUtils` class with one function: `add_fff64`, from c++ to JavaScript.

```
#include "MathUtils.hpp"

class MathUtils_ : public MathUtils {
public:
double add_fff64(double a, double b) override {
return a + b;
}
};
```
Using [Snapchat/Djinni](https://github.com/Snapchat/djinni)'s wasm interface, I've generated relevant binding files:
```
// ***wasm/MathUtils.hpp***
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file was generated by Djinni from MathUtils.djinni

#pragma once

#include "src/MathUtils.hpp"
#include "snap.djinni/support-lib/wasm/djinni_wasm.hpp"

namespace djinni_generated {

struct MathUtils : ::djinni::JsInterface<::MathUtils, MathUtils> {
using CppType = std::shared_ptr<::MathUtils>;
using CppOptType = std::shared_ptr<::MathUtils>;
using JsType = em::val;
using Boxed = MathUtils;

static CppType toCpp(JsType j) { return _fromJs(j); }
static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; }
static JsType fromCpp(const CppType& c) {
::djinni::checkForNull(c.get(), "MathUtils::fromCpp");
return fromCppOpt(c);
}

static em::val cppProxyMethods();

static double add_fff64(const CppType& self, double w_a,double w_b);

};

} // namespace djinni_generated
```

```
// ***wasm/MathUtils.cpp***
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file was generated by Djinni from MathUtils.djinni

#include "wasm/MathUtils.hpp" // my header

namespace djinni_generated {

em::val MathUtils::cppProxyMethods() {
static const em::val methods = em::val::array(std::vector {
"addFff64",
});
return methods;
}

double MathUtils::add_fff64(const CppType& self, double w_a,double w_b) {
try {
auto r = self->add_fff64(::djinni::F64::toCpp(w_a),
::djinni::F64::toCpp(w_b));
return ::djinni::F64::fromCpp(r);
}
catch(const std::exception& e) {
return ::djinni::ExceptionHandlingTraits<::djinni::F64>::handleNativeException(e);
}
}

EMSCRIPTEN_BINDINGS(_MathUtils) {
em::class_<::MathUtils>("MathUtils")
.smart_ptr>("MathUtils")
.function("nativeDestroy", &MathUtils::nativeDestroy)
.function("addFff64", MathUtils::add_fff64)
;
}

} // namespace djinni_generated
```
While this has indeed compiled into a JavaScript output, there is **no** semblance of the `MathUtils` class or any `add_fff64` function in `MathUtils.js`. Indeed, when I attempt to call the `add_fff64` function in a generic native html file, I get an error. I use the following script:
```
emcc wasm/MathUtils.cpp src/MathUtils.cpp /Users/sam/snap.djinni/support-lib/wasm/djinni_wasm.cpp -o MathUtils.js --bind
```

This is particularly strange to me because when debugging the generated WebAssembly file with tools such as `wasm-objdump` and `wasm2wat`, `MathUtils` class and `addFff64` both appear, which is why I suspect this may be an issue with emscripten
```
...
- 0010490: 7562 6c65 3e00 6164 6446 6666 3634 0048 uble>.addFff64.H
...
```
Is there any way of confirming what may be the root cause of the issue?

**Version of emscripten/emsdk:**
`emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.45-git`

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo la build segnalata con emcc usando wasm/MathUtils.cpp, src/MathUtils.cpp e djinni_wasm.cpp, quindi esamina MathUtils.js e le esportazioni WebAssembly generate. Confronta l'API visibile del modulo JavaScript con i simboli MathUtils e addFff64 mostrati da wasm-objdump o wasm2wat; il lavoro è completato quando hai identificato perché il binding non può essere chiamato dalla pagina HTML e hai documentato o corretto questo comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, javascript, wasm
Ambito
compilers, web-dev
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.