Skip to content

Commit 9ea2a7b

Browse files
committed
Try to bring in some subset of web assembly set from snapchat-djinni
1 parent 1d61ed5 commit 9ea2a7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2095
-77
lines changed

src/it/resources/cpp_interface_dependency.yml

+7
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ cs:
3636
header: '"InterfaceDependency.hpp"'
3737
typename: InterfaceDependency^
3838
reference: true
39+
wasm:
40+
translator: '::InterfaceDependency'
41+
header: '"InterfaceDependency.hpp"'
42+
typename: InterfaceDependency
43+
ts:
44+
typename: InterfaceDependency
45+
module: "InterfaceDependency.ts"

src/it/resources/expected/all_datatypes/cpp-headers/enum_data.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <functional>
77

88
enum class EnumData : int {
9-
A,
10-
B,
9+
A = 0,
10+
B = 1,
1111
};
1212

1313
namespace std {

src/it/resources/expected/all_datatypes/cppcli/EnumData.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#include "../cpp-headers/enum_data.hpp"
77

88
public enum class EnumData {
9-
A,
10-
B,
9+
A = 0,
10+
B = 1,
1111
};

src/it/resources/expected/all_datatypes/generated-files.txt

+5
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ src/it/resources/result/all_datatypes/cwrapper/dh__map_int8_t_bool.cpp
3838
src/it/resources/result/all_datatypes/cwrapper-headers/dh__all_datatypes.h
3939
src/it/resources/result/all_datatypes/cwrapper/dh__all_datatypes.hpp
4040
src/it/resources/result/all_datatypes/cwrapper/dh__all_datatypes.cpp
41+
src/it/resources/result/all_datatypes/wasm/enum_data.hpp
42+
src/it/resources/result/all_datatypes/wasm/enum_data.cpp
43+
src/it/resources/result/all_datatypes/wasm/all_datatypes.hpp
44+
src/it/resources/result/all_datatypes/wasm/all_datatypes.cpp
45+
src/it/resources/result/all_datatypes/ts/module.ts

src/it/resources/expected/all_datatypes/objc-headers/ITEnumData.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
typedef NS_ENUM(NSInteger, ITEnumData)
77
{
8-
ITEnumDataA,
9-
ITEnumDataB,
8+
ITEnumDataA = 0,
9+
ITEnumDataB = 1,
1010
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from all_datatypes.djinni
3+
4+
5+
export enum EnumData {
6+
A = 0,
7+
B = 1,
8+
}
9+
10+
export interface /*record*/ AllDatatypes {
11+
booleanData: boolean;
12+
integer8Data: number;
13+
integer16Data: number;
14+
integer32Data: number;
15+
integer64Data: bigint;
16+
float32Data: number;
17+
float64Data: number;
18+
stringData: string;
19+
binaryData: Uint8Array;
20+
dateData: Date;
21+
listData: Array<boolean>;
22+
setData: Set<boolean>;
23+
mapData: Map<number, boolean>;
24+
optionalData?: boolean;
25+
enumData: EnumData;
26+
}
27+
28+
export interface Module_statics {
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from all_datatypes.djinni
3+
4+
#include "all_datatypes.hpp" // my header
5+
#include "enum_data.hpp"
6+
7+
namespace djinni_generated {
8+
9+
auto AllDatatypes::toCpp(const JsType& j) -> CppType {
10+
return {::djinni::Bool::Boxed::toCpp(j["booleanData"]),
11+
::djinni::I8::Boxed::toCpp(j["integer8Data"]),
12+
::djinni::I16::Boxed::toCpp(j["integer16Data"]),
13+
::djinni::I32::Boxed::toCpp(j["integer32Data"]),
14+
::djinni::I64::Boxed::toCpp(j["integer64Data"]),
15+
::djinni::F32::Boxed::toCpp(j["float32Data"]),
16+
::djinni::F64::Boxed::toCpp(j["float64Data"]),
17+
::djinni::String::Boxed::toCpp(j["stringData"]),
18+
::djinni::Binary::Boxed::toCpp(j["binaryData"]),
19+
::djinni::Date::Boxed::toCpp(j["dateData"]),
20+
::djinni::List<::djinni::Bool>::Boxed::toCpp(j["listData"]),
21+
::djinni::Set<::djinni::Bool>::Boxed::toCpp(j["setData"]),
22+
::djinni::Map<::djinni::I8, ::djinni::Bool>::Boxed::toCpp(j["mapData"]),
23+
::djinni::Optional<std::optional, ::djinni::Bool>::Boxed::toCpp(j["optionalData"]),
24+
::djinni_generated::EnumData::Boxed::toCpp(j["enumData"])};
25+
}
26+
auto AllDatatypes::fromCpp(const CppType& c) -> JsType {
27+
em::val js = em::val::object();
28+
js.set("booleanData", ::djinni::Bool::Boxed::fromCpp(c.booleanData));
29+
js.set("integer8Data", ::djinni::I8::Boxed::fromCpp(c.integer8Data));
30+
js.set("integer16Data", ::djinni::I16::Boxed::fromCpp(c.integer16Data));
31+
js.set("integer32Data", ::djinni::I32::Boxed::fromCpp(c.integer32Data));
32+
js.set("integer64Data", ::djinni::I64::Boxed::fromCpp(c.integer64Data));
33+
js.set("float32Data", ::djinni::F32::Boxed::fromCpp(c.float32Data));
34+
js.set("float64Data", ::djinni::F64::Boxed::fromCpp(c.float64Data));
35+
js.set("stringData", ::djinni::String::Boxed::fromCpp(c.stringData));
36+
js.set("binaryData", ::djinni::Binary::Boxed::fromCpp(c.binaryData));
37+
js.set("dateData", ::djinni::Date::Boxed::fromCpp(c.dateData));
38+
js.set("listData", ::djinni::List<::djinni::Bool>::Boxed::fromCpp(c.listData));
39+
js.set("setData", ::djinni::Set<::djinni::Bool>::Boxed::fromCpp(c.setData));
40+
js.set("mapData", ::djinni::Map<::djinni::I8, ::djinni::Bool>::Boxed::fromCpp(c.mapData));
41+
js.set("optionalData", ::djinni::Optional<std::optional, ::djinni::Bool>::Boxed::fromCpp(c.optionalData));
42+
js.set("enumData", ::djinni_generated::EnumData::Boxed::fromCpp(c.enum_data));
43+
return js;
44+
}
45+
46+
} // namespace djinni_generated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from all_datatypes.djinni
3+
4+
#pragma once
5+
6+
#include "all_datatypes.hpp"
7+
#include "djinni_wasm.hpp"
8+
9+
namespace djinni_generated {
10+
11+
struct AllDatatypes
12+
{
13+
using CppType = ::AllDatatypes;
14+
using JsType = em::val;
15+
using Boxed = AllDatatypes;
16+
17+
static CppType toCpp(const JsType& j);
18+
static JsType fromCpp(const CppType& c);
19+
};
20+
21+
} // namespace djinni_generated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from all_datatypes.djinni
3+
4+
#include "enum_data.hpp" // my header
5+
#include <mutex>
6+
7+
namespace djinni_generated {
8+
9+
namespace {
10+
EM_JS(void, djinni_init__enum_data_consts, (), {
11+
Module.EnumData = {
12+
A : 0,
13+
B : 1,
14+
}
15+
})
16+
}
17+
18+
void EnumData::staticInitializeConstants() {
19+
static std::once_flag initOnce;
20+
std::call_once(initOnce, [] {
21+
djinni_init__enum_data_consts();
22+
});
23+
}
24+
25+
EMSCRIPTEN_BINDINGS(_enum_data) {
26+
EnumData::staticInitializeConstants();
27+
}
28+
29+
} // namespace djinni_generated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from all_datatypes.djinni
3+
4+
#pragma once
5+
6+
#include "djinni_wasm.hpp"
7+
#include "enum_data.hpp"
8+
9+
namespace djinni_generated {
10+
11+
struct EnumData: ::djinni::WasmEnum<::EnumData> {
12+
static void staticInitializeConstants();
13+
};
14+
15+
} // namespace djinni_generated

src/it/resources/expected/all_datatypes_json/cpp-headers/enum_data.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <functional>
77

88
enum class EnumData : int {
9-
FIRSTENUMVALUE,
10-
SECONDENUMVALUE,
9+
FIRSTENUMVALUE = 0,
10+
SECONDENUMVALUE = 1,
1111
};
1212

1313
namespace std {

src/it/resources/expected/all_datatypes_json/cpp-headers/my_flags.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
enum class MyFlags : unsigned {
1010
NO_FLAGS = 0,
1111
/** flag option comment */
12-
FLAG1 = 1u << 0,
13-
FLAG2 = 1u << 1,
14-
FLAG3 = 1u << 2,
15-
ALL_FLAGS = 0 | FLAG1 | FLAG2 | FLAG3,
12+
FLAG1 = 1 << 0,
13+
FLAG2 = 1 << 1,
14+
FLAG3 = 1 << 2,
15+
ALL_FLAGS = 0 | (1 << 0) | (1 << 1) | (1 << 2),
1616
};
1717
constexpr MyFlags operator|(MyFlags lhs, MyFlags rhs) noexcept {
1818
return static_cast<MyFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));

src/it/resources/expected/my_client_interface/generated-files.txt

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ src/it/resources/result/my_client_interface/cwrapper-headers/cw__my_client_inter
1414
src/it/resources/result/my_client_interface/cwrapper/cw__my_client_interface.hpp
1515
src/it/resources/result/my_client_interface/cwrapper/cw__my_client_interface.cpp
1616
src/it/resources/result/my_client_interface/cffi/pycffi_lib_build.py
17+
src/it/resources/result/my_client_interface/wasm/my_client_interface.hpp
18+
src/it/resources/result/my_client_interface/wasm/my_client_interface.cpp
19+
src/it/resources/result/my_client_interface/ts/module.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from my_client_interface.djinni
3+
4+
5+
export interface MyClientInterface {
6+
logString(str: string): boolean;
7+
}
8+
9+
export interface Module_statics {
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from my_client_interface.djinni
3+
4+
#include "my_client_interface.hpp" // my header
5+
6+
namespace djinni_generated {
7+
8+
9+
EMSCRIPTEN_BINDINGS(_my_client_interface) {
10+
em::class_<::MyClientInterface>("MyClientInterface")
11+
.smart_ptr<std::shared_ptr<::MyClientInterface>>("MyClientInterface")
12+
.function("nativeDestroy", &MyClientInterface::nativeDestroy)
13+
;
14+
}
15+
16+
} // namespace djinni_generated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from my_client_interface.djinni
3+
4+
#pragma once
5+
6+
#include "djinni_wasm.hpp"
7+
#include "my_client_interface.hpp"
8+
9+
namespace djinni_generated {
10+
11+
struct MyClientInterface : ::djinni::JsInterface<::MyClientInterface, MyClientInterface> {
12+
using CppType = std::shared_ptr<::MyClientInterface>;
13+
using CppOptType = std::shared_ptr<::MyClientInterface>;
14+
using JsType = em::val;
15+
using Boxed = MyClientInterface;
16+
17+
static CppType toCpp(JsType j) { return _fromJs(j); }
18+
static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; }
19+
static JsType fromCpp(const CppType& c) {
20+
::djinni::checkForNull(c.get(), "MyClientInterface::fromCpp");
21+
return fromCppOpt(c);
22+
}
23+
24+
25+
};
26+
27+
} // namespace djinni_generated

src/it/resources/expected/my_cpp_interface/generated-files.txt

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ src/it/resources/result/my_cpp_interface/cwrapper-headers/cw__my_cpp_interface.h
1616
src/it/resources/result/my_cpp_interface/cwrapper/cw__my_cpp_interface.hpp
1717
src/it/resources/result/my_cpp_interface/cwrapper/cw__my_cpp_interface.cpp
1818
src/it/resources/result/my_cpp_interface/cffi/pycffi_lib_build.py
19+
src/it/resources/result/my_cpp_interface/wasm/my_cpp_interface.hpp
20+
src/it/resources/result/my_cpp_interface/wasm/my_cpp_interface.cpp
21+
src/it/resources/result/my_cpp_interface/ts/module.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from my_cpp_interface.djinni
3+
4+
5+
/** interface comment */
6+
export interface MyCppInterface {
7+
/** method comment */
8+
methodReturningNothing(value: number): void;
9+
methodReturningSomeType(key: string): number;
10+
methodChangingNothing(): number;
11+
}
12+
export namespace MyCppInterface {
13+
/** Interfaces can also have constants */
14+
export const VERSION = 1;
15+
}
16+
export interface MyCppInterface_statics {
17+
getVersion(): number;
18+
}
19+
20+
export interface Module_statics {
21+
MyCppInterface: MyCppInterface_statics;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// AUTOGENERATED FILE - DO NOT MODIFY!
2+
// This file was generated by Djinni from my_cpp_interface.djinni
3+
4+
#include "my_cpp_interface.hpp" // my header
5+
6+
namespace djinni_generated {
7+
8+
em::val MyCppInterface::cppProxyMethods() {
9+
static const em::val methods = em::val::array(std::vector<std::string> {
10+
"methodReturningNothing",
11+
"methodReturningSomeType",
12+
"methodChangingNothing",
13+
});
14+
return methods;
15+
}
16+
17+
void MyCppInterface::method_returning_nothing(const CppType& self, int32_t w_value) {
18+
try {
19+
self->method_returning_nothing(::djinni::I32::toCpp(w_value));
20+
}
21+
catch(const std::exception& e) {
22+
return ::djinni::ExceptionHandlingTraits<void>::handleNativeException(e);
23+
}
24+
}
25+
int32_t MyCppInterface::method_returning_some_type(const CppType& self, const std::string& w_key) {
26+
try {
27+
auto r = self->method_returning_some_type(::djinni::String::toCpp(w_key));
28+
return ::djinni::I32::fromCpp(r);
29+
}
30+
catch(const std::exception& e) {
31+
return ::djinni::ExceptionHandlingTraits<::djinni::I32>::handleNativeException(e);
32+
}
33+
}
34+
int32_t MyCppInterface::method_changing_nothing(const CppType& self) {
35+
try {
36+
auto r = self->method_changing_nothing();
37+
return ::djinni::I32::fromCpp(r);
38+
}
39+
catch(const std::exception& e) {
40+
return ::djinni::ExceptionHandlingTraits<::djinni::I32>::handleNativeException(e);
41+
}
42+
}
43+
int32_t MyCppInterface::get_version() {
44+
try {
45+
auto r = ::MyCppInterface::get_version();
46+
return ::djinni::I32::fromCpp(r);
47+
}
48+
catch(const std::exception& e) {
49+
return ::djinni::ExceptionHandlingTraits<::djinni::I32>::handleNativeException(e);
50+
}
51+
}
52+
53+
EMSCRIPTEN_BINDINGS(_my_cpp_interface) {
54+
em::class_<::MyCppInterface>("MyCppInterface")
55+
.smart_ptr<std::shared_ptr<::MyCppInterface>>("MyCppInterface")
56+
.function("nativeDestroy", &MyCppInterface::nativeDestroy)
57+
.function("methodReturningNothing", MyCppInterface::method_returning_nothing)
58+
.function("methodReturningSomeType", MyCppInterface::method_returning_some_type)
59+
.function("methodChangingNothing", MyCppInterface::method_changing_nothing)
60+
.class_function("getVersion", MyCppInterface::get_version)
61+
;
62+
}
63+
64+
namespace {
65+
EM_JS(void, djinni_init__my_cpp_interface_consts, (), {
66+
if (!('MyCppInterface' in Module)) {
67+
Module.MyCppInterface = {};
68+
}
69+
Module.MyCppInterface.VERSION = 1;
70+
})
71+
}
72+
void MyCppInterface::staticInitializeConstants() {
73+
static std::once_flag initOnce;
74+
std::call_once(initOnce, [] {
75+
djinni_init__my_cpp_interface_consts();
76+
});
77+
}
78+
79+
EMSCRIPTEN_BINDINGS(_my_cpp_interface_consts) {
80+
MyCppInterface::staticInitializeConstants();
81+
}
82+
83+
} // namespace djinni_generated

0 commit comments

Comments
 (0)