Skip to content

Commit 5a4a208

Browse files
committed
morewip
1 parent cc25461 commit 5a4a208

30 files changed

+156
-440
lines changed

djinni/ts/DjinniModule.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
/**
3+
* Copyright 2021 Snap, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
exports.__esModule = true;

test-suite/CMakeLists.txt

Lines changed: 59 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ add_djinni_target(DjinniAllTests
3636
CPPCLI_NAMESPACE "Djinni::TestSuite"
3737
CPPCLI_INCLUDE_CPP_PREFIX "cpp/"
3838
WASM_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/wasm"
39+
WASM_NAMESPACE "testsuite"
40+
TS_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/ts"
41+
TS_MODULE "test"
3942
YAML_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/yaml"
4043
YAML_PREFIX "test_"
4144

@@ -46,6 +49,7 @@ add_djinni_target(DjinniAllTests
4649
OBJCPP_OUT_FILES OBJCPP_GENERATED_SRCS
4750
CPPCLI_OUT_FILES CPPCLI_GENERATED_SRCS
4851
WASM_OUT_FILES WASM_GENERATED_SRCS
52+
TS_OUT_FILES TS_GENERATED_SRCS
4953
YAML_OUT_FILE YAML_GENERATED_SRCS
5054
)
5155

@@ -75,7 +79,9 @@ add_djinni_target(DjinniWCharTests
7579
CPPCLI_NAMESPACE "Djinni::TestSuite"
7680
CPPCLI_INCLUDE_CPP_PREFIX "cpp/"
7781
WASM_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/wasm"
78-
YAML_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/yaml"
82+
WASM_NAMESPACE "testsuite"
83+
TS_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/ts"
84+
TS_MODULE "test_wchar"
7985
YAML_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/yaml"
8086
YAML_PREFIX "test_"
8187

@@ -86,6 +92,7 @@ add_djinni_target(DjinniWCharTests
8692
OBJCPP_OUT_FILES WCHAR_OBJCPP_GENERATED_SRCS
8793
CPPCLI_OUT_FILES WCHAR_CPPCLI_GENERATED_SRCS
8894
WASM_OUT_FILES WCHAR_WASM_GENERATED_SRCS
95+
TS_OUT_FILES WCHAR_TS_GENERATED_SRCS
8996
YAML_OUT_FILE WCHAR_YAML_GENERATED_SRCS
9097
)
9198

@@ -112,6 +119,7 @@ file(GLOB_RECURSE OBJC_TEST_SRCS "handwritten-src/objc/tests/*")
112119
file(GLOB_RECURSE C_WRAPPER_HANDWRITTEN_SRCS "handwritten-src/cwrapper/*")
113120
file(GLOB_RECURSE PYCPP_HANDWRITTEN_SRCS "handwritten-src/pycpp/*")
114121
file(GLOB_RECURSE WASM_HANDWRITTEN_SRCS "handwritten-src/wasm/*")
122+
file(GLOB_RECURSE TS_HANDWRITTEN_SRCS "handwritten-src/ts/*")
115123

116124
source_group("handwritten-cpp" FILES ${CPP_HANDWRITTEN_SRCS})
117125
source_group("handwritten-objc" FILES ${OBJC_HANDWRITTEN_SRCS})
@@ -124,6 +132,8 @@ source_group("generated-java" FILES ${JAVA_GENERATED_SRCS})
124132
source_group("generated-jni" FILES ${JNI_GENERATED_SRCS})
125133
source_group("generated-objc" FILES ${OBJC_GENERATED_SRCS})
126134
source_group("generated-objcpp" FILES ${OBJCPP_GENERATED_SRCS})
135+
source_group("generated-wasm" FILES ${WASM_GENERATED_SRCS})
136+
source_group("generated-ts" FILES ${TS_GENERATED_SRCS})
127137
source_group("generated-yaml" FILES ${YAML_GENERATED_SRCS})
128138

129139
source_group("generated-cpp" FILES ${WCHAR_CPP_GENERATED_SRCS})
@@ -132,6 +142,7 @@ source_group("generated-jni" FILES ${WCHAR_JNI_GENERATED_SRCS})
132142
source_group("generated-objc" FILES ${WCHAR_OBJC_GENERATED_SRCS})
133143
source_group("generated-objcpp" FILES ${WCHAR_OBJCPP_GENERATED_SRCS})
134144
source_group("generated-wasm" FILES ${WCHAR_WASM_GENERATED_SRCS})
145+
source_group("generated-ts" FILES ${WCHAR_TS_GENERATED_SRCS})
135146
source_group("generated-yaml" FILES ${WCHAR_YAML_GENERATED_SRCS})
136147

137148
if(DJINNI_WITH_JNI)
@@ -212,80 +223,53 @@ endif()
212223

213224

214225
if(DJINNI_WITH_WASM)
215-
216-
set(DjinniWasmTest "test-wasm")
217-
218-
add_executable(${DjinniWasmTest}
219-
${CPP_HANDWRITTEN_SRCS}
220-
${CPP_GENERATED_SRCS}
221-
${WASM_GENERATED_SRCS}
222-
${WCHAR_CPP_GENERATED_SRCS}
223-
${WCHAR_WASM_GENERATED_SRCS}
224-
)
225-
target_include_directories(${DjinniWasmTest} PUBLIC
226-
${CMAKE_SOURCE_DIR}
227-
${CMAKE_CURRENT_SOURCE_DIR}/handwritten-src/cpp
228-
${CMAKE_CURRENT_BINARY_DIR}/generated-src/cpp
229-
${CMAKE_CURRENT_BINARY_DIR}/generated-src/wasm
230-
)
231-
232-
set(WASM_CC_FLAGS "-s MAIN_MODULE=1 -fexceptions")
233-
message(WARNING ${WASM_CC_FLAGS})
234-
set_target_properties(${DjinniWasmTest} PROPERTIES COMPILE_FLAGS ${WASM_CC_FLAGS})
235-
236-
set(EMSCRIPTEN_LINK_OPTIONS
237-
"-s WASM=1 "
238-
"--bind " # Compiles the source code using the Embind bindings to connect C/C++ and JavaScript
239-
"-s MALLOC=emmalloc " # Switch to using the much smaller implementation
240-
"-s MODULARIZE=1 " # Allows us to manually invoke the initialization of wasm
241-
"-s WASM_BIGINT=1 " # We need to pass int64_t
242-
)
243-
244-
set(WASM_LINK_FLAGS "${EMSCRIPTEN_LINK_OPTIONS} -fexceptions")
245-
message(WARNING ${WASM_LINK_FLAGS})
246-
set_target_properties(${DjinniWasmTest} PROPERTIES LINK_FLAGS ${WASM_LINK_FLAGS})
247-
set(CMAKE_EXECUTABLE_SUFFIX ".js")
248-
249-
target_link_libraries(${DjinniWasmTest} PUBLIC djinni-support-lib::djinni-support-lib embind)
250-
251-
add_custom_target(DjinniWasmTestCopy)
252-
file(GLOB DjinniWasmTestResources ${CMAKE_CURRENT_SOURCE_DIR}/handwritten-src/ts/*)
253-
foreach(ResourceFile ${DjinniWasmTestResources})
254-
add_custom_command(TARGET ${DjinniWasmTest} PRE_BUILD
255-
COMMAND ${CMAKE_COMMAND} -E
256-
copy ${ResourceFile} $<TARGET_FILE_DIR:DjinniWasmTest>)
257-
endforeach()
258-
add_dependencies(${DjinniWasmTest} DjinniWasmTestCopy)
259-
260-
# find_program (BASH_PROGRAM bash)
261-
262-
# add_test(DjinniWasmTestTests ${BASH_PROGRAM} "${CMAKE_CURRENT_BINARY_DIR}/run.sh")
263-
add_test(NAME DjinniWasmTestTests COMMAND bash -c "${CMAKE_CURRENT_BINARY_DIR}/run.sh")
264-
265-
# add_custom_target(DjinniWasmTestPrep ALL
266-
# ${CMAKE_COMMAND} -E env PYTHONPATH=${PYTHONPATH} LIBRARY_PATH=$<TARGET_FILE_DIR:mylib> ${PYTHON_EXECUTABLE}
267-
# ${PYCFFI_GENERATED_SRCS}
268-
# ${CMAKE_SOURCE_DIR}/djinni/cwrapper/wrapper_marshal.h
269-
# ${C_WRAPPER_GENERATED_HEADERS}
270-
# ${CMAKE_CURRENT_SOURCE_DIR}/handwritten-src/cwrapper/limits_helper.h
271-
# DEPENDS mylib ${PYCFFI_GENERATED_SRCS} ${PYTHON_GENERATED_SRCS} ${C_WRAPPER_GENERATED_HEADERS}
272-
# COMMENT "Building CFFI lib"
273-
# VERBATIM
274-
# WORKING_DIRECTORY $<TARGET_FILE_DIR:mylib>
275-
# )
276-
277-
# add_test(NAME PythonTests COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${PYTHONPATH}
278-
# ${PYTHON_EXECUTABLE} -m pytest -s "${CMAKE_CURRENT_SOURCE_DIR}/handwritten-src/python"
279-
# )
280-
281-
282-
# add_test(NAME DjinniWasmTestTests COMMAND ${Java_JAVA_EXECUTABLE}
283-
# -Xcheck:jni
284-
# -Ddjinni.native_libs_dirs=$<TARGET_FILE:DjinniTestNative>
285-
# -cp ${_JAVA_TESTS_CLASSPATH}
286-
# "com.dropbox.djinni.test.AllTests"
287-
# )
288-
226+
set(DjinniWasmTest "test-wasm")
227+
228+
add_executable(${DjinniWasmTest}
229+
${CPP_HANDWRITTEN_SRCS}
230+
${CPP_GENERATED_SRCS}
231+
${WASM_GENERATED_SRCS}
232+
${TS_GENERATED_SRCS}
233+
${WCHAR_CPP_GENERATED_SRCS}
234+
${WCHAR_WASM_GENERATED_SRCS}
235+
${WCHAR_TS_GENERATED_SRCS}
236+
)
237+
target_include_directories(${DjinniWasmTest} PUBLIC
238+
${CMAKE_SOURCE_DIR}
239+
${CMAKE_CURRENT_SOURCE_DIR}/handwritten-src/cpp
240+
${CMAKE_CURRENT_BINARY_DIR}/generated-src/cpp
241+
${CMAKE_CURRENT_BINARY_DIR}/generated-src/wasm
242+
)
243+
244+
set(WASM_CC_FLAGS "-s MAIN_MODULE=1 -fexceptions")
245+
message(WARNING ${WASM_CC_FLAGS})
246+
set_target_properties(${DjinniWasmTest} PROPERTIES COMPILE_FLAGS ${WASM_CC_FLAGS})
247+
248+
set(EMSCRIPTEN_LINK_OPTIONS
249+
"-s WASM=1 "
250+
"--bind " # Compiles the source code using the Embind bindings to connect C/C++ and JavaScript
251+
"-s MALLOC=emmalloc " # Switch to using the much smaller implementation
252+
"-s MODULARIZE=1 " # Allows us to manually invoke the initialization of wasm
253+
"-s WASM_BIGINT=1 " # We need to pass int64_t
254+
)
255+
256+
set(WASM_LINK_FLAGS "${EMSCRIPTEN_LINK_OPTIONS} -fexceptions")
257+
message(WARNING ${WASM_LINK_FLAGS})
258+
set_target_properties(${DjinniWasmTest} PROPERTIES LINK_FLAGS ${WASM_LINK_FLAGS})
259+
set(CMAKE_EXECUTABLE_SUFFIX ".js")
260+
261+
target_link_libraries(${DjinniWasmTest} PUBLIC djinni-support-lib::djinni-support-lib embind)
262+
263+
add_custom_target(DjinniWasmTestCopy)
264+
file(GLOB DjinniWasmTestResources ${CMAKE_CURRENT_SOURCE_DIR}/handwritten-src/ts/*)
265+
foreach(ResourceFile ${DjinniWasmTestResources})
266+
add_custom_command(TARGET ${DjinniWasmTest} PRE_BUILD
267+
COMMAND ${CMAKE_COMMAND} -E
268+
copy ${ResourceFile} $<TARGET_FILE_DIR:${DjinniWasmTest}>)
269+
endforeach()
270+
add_dependencies(${DjinniWasmTest} DjinniWasmTestCopy)
271+
272+
add_test(NAME DjinniWasmTestTests COMMAND bash -c "${CMAKE_CURRENT_BINARY_DIR}/run.sh")
289273

290274
endif()
291275

test-suite/Djinni.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ execute_process(COMMAND ${DJINNI_EXECUTABLE} "--version" OUTPUT_VARIABLE DJINNI_
1515
string(REGEX REPLACE "\n+$" "" DJINNI_VERSION "${DJINNI_VERSION}")
1616
message(STATUS "Found Djinni: ${DJINNI_EXECUTABLE} (${DJINNI_VERSION})")
1717

18-
1918
macro(append_if_defined LIST OPTION)
2019
if(NOT "${ARGN}" STREQUAL "")
2120
list(APPEND ${LIST} ${OPTION} ${ARGN})
@@ -180,9 +179,10 @@ function(add_djinni_target)
180179

181180
WASM_OUT
182181
WASM_OUT_FILES
182+
WASM_NAMESPACE
183+
183184
TS_OUT
184185
TS_OUT_FILES
185-
WASM_NAMESPACE
186186
TS_MODULE
187187

188188
YAML_OUT
@@ -277,7 +277,7 @@ function(add_djinni_target)
277277
append_if_defined(DJINNI_GENERATION_COMMAND "--cppcli-namespace" ${DJINNI_CPPCLI_NAMESPACE})
278278
append_if_defined(DJINNI_GENERATION_COMMAND "--cppcli-include-cpp-prefix" ${DJINNI_CPPCLI_INCLUDE_CPP_PREFIX})
279279

280-
append_if_defined(DJINNI_GENERATION_COMMAND "--wasm-namespace" ${DJINNI_WASM_NAMESPCE})
280+
append_if_defined(DJINNI_GENERATION_COMMAND "--wasm-namespace" ${DJINNI_WASM_NAMESPACE})
281281
append_if_defined(DJINNI_GENERATION_COMMAND "--ts-module" ${DJINNI_TS_MODULE})
282282

283283
if(DEFINED DJINNI_CPP_OUT_FILES)

test-suite/djinni/client_interface.djinni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ client_returned_record = record {
66
} deriving (parcelable)
77

88
# Client interface
9-
client_interface = interface +j +o +p +s {
9+
client_interface = interface +j +o +w +p +s {
1010
# Returns record of given string
1111
get_record(record_id: i64, utf8string: string, misc: optional<string>): client_returned_record;
1212
identifier_check(data: binary, r: i32, jret: i64): f64;

test-suite/djinni/enum.djinni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum_usage_record = record {
1919
m: map<color, color>;
2020
} deriving(parcelable)
2121

22-
enum_usage_interface = interface +c +j +o {
22+
enum_usage_interface = interface +c +j +o +w {
2323
e(e: color): color;
2424
o(o: optional<color>): optional<color>;
2525
l(l: list<color>): list<color>;

test-suite/djinni/exception.djinni

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
throwing_interface = interface +w {
2+
throw_exception();
3+
}
4+
15
cpp_exception = interface +c {
26
throw_an_exception(): i32;
7+
call_throwing_interface(cb: throwing_interface): i32;
8+
call_throwing_and_catch(cb: throwing_interface): string;
39
static get(): cpp_exception;
410
}

test-suite/djinni/test.djinni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test_helpers = interface +c {
2929
static check_enum_map(m: map<color, string>);
3030
static check_enum(c: color);
3131

32-
static token_id(t: user_token): user_token;
32+
static token_id(t: optional<user_token>): optional<user_token>;
3333
static create_cpp_token(): user_token;
3434
static check_cpp_token(t: user_token);
3535
static cpp_token_id(t: user_token): i64;

test-suite/djinni/user_token.djinni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
user_token = interface +c +j +o +s {
1+
user_token = interface +c +j +o +w +s {
22
whoami() : string;
33
}
Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
#include "cpp_exception_impl.hpp"
2-
#include <exception>
3-
4-
namespace testsuite {
5-
6-
int32_t CppExceptionImpl::throw_an_exception() {
7-
throw ExampleException();
8-
}
9-
10-
std::shared_ptr<CppException> CppException::get() {
11-
return std::make_shared<CppExceptionImpl>();
12-
}
13-
14-
} // namespace testsuite
1+
#include "cpp_exception_impl.hpp"
2+
#include "throwing_interface.hpp"
3+
#include <exception>
4+
5+
namespace testsuite {
6+
7+
int32_t CppExceptionImpl::throw_an_exception() {
8+
throw ExampleException();
9+
}
10+
11+
int32_t CppExceptionImpl::call_throwing_interface(const /*not-null*/ std::shared_ptr<ThrowingInterface>& cb) {
12+
cb->throw_exception();
13+
return 0;
14+
}
15+
16+
std::string CppExceptionImpl::call_throwing_and_catch(const /*not-null*/ std::shared_ptr<ThrowingInterface>& cb) {
17+
try {
18+
cb->throw_exception();
19+
} catch (std::exception& e) {
20+
return e.what();
21+
}
22+
return {};
23+
}
24+
25+
std::shared_ptr<CppException> CppException::get() {
26+
return std::make_shared<CppExceptionImpl>();
27+
}
28+
29+
} // namespace testsuite
Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
#include "cpp_exception.hpp"
2-
#include <exception>
3-
4-
namespace testsuite {
5-
6-
class ExampleException: public std::exception {
7-
virtual const char* what() const throw() {
8-
return "Exception Thrown";
9-
}
10-
};
11-
12-
extern ExampleException EXAMPLE_EXCEPTION;
13-
14-
class CppExceptionImpl : public CppException {
15-
public:
16-
CppExceptionImpl() {}
17-
virtual ~CppExceptionImpl() {}
18-
19-
virtual int32_t throw_an_exception () override;
20-
};
21-
22-
} // namespace testsuite
23-
1+
#include "cpp_exception.hpp"
2+
#include <exception>
3+
4+
namespace testsuite {
5+
6+
class ExampleException: public std::exception {
7+
virtual const char* what() const throw() {
8+
return "Exception Thrown";
9+
}
10+
};
11+
12+
extern ExampleException EXAMPLE_EXCEPTION;
13+
14+
class CppExceptionImpl : public CppException {
15+
public:
16+
CppExceptionImpl() {}
17+
virtual ~CppExceptionImpl() {}
18+
19+
virtual int32_t throw_an_exception () override;
20+
virtual int32_t call_throwing_interface(const /*not-null*/ std::shared_ptr<ThrowingInterface>& cb) override;
21+
virtual std::string call_throwing_and_catch(const /*not-null*/ std::shared_ptr<ThrowingInterface>& cb) override;
22+
};
23+
24+
} // namespace testsuite
25+

0 commit comments

Comments
 (0)