Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Import wasm support from snapchat repo #76

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,40 @@ jobs:
working-directory: build/test-suite
run: ctest -C Release -V

build-on-ubuntu-for-wasm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: asdf-vm/actions/install@v1
- name: Install dependencies
uses: py-actions/py-dependency-install@v3
with:
path: "requirements.txt"
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 20.9.0
- name: Install browserify
run: npm install -g browserify
- name: Setup EMSDK
uses: mymindstorm/setup-emsdk@v11
with:
version: 3.1.44
- name: Install chrome
uses: browser-actions/setup-chrome@latest
- name: Use local djinni on branch for now
if: ${{ github.ref != 'refs/heads/master' }}
run: export CMAKE_DJINNI_OPT="-DDJINNI_EXECUTABLE=$(pwd)/bin/djinni"
- name: Report cmake version
run: cmake --version
- name: Configure cmake
run: cmake -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -S . -B build -DDJINNI_WITH_WASM=ON -DDJINNI_EXECUTABLE=$(pwd)/bin/djinni
- name: Build release
run: cmake --build build --parallel $(nproc) --config Release
- name: Run headless test
run: pushd build && ctest --output-on-failure
- name: Run integration test on sample app
run: pushd build/examples && ./run.sh && python3 run-tests-selenium.py

build-on-windows-for-cppcli:
runs-on: windows-latest
Expand Down
32 changes: 29 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ project(djinni_support_lib CXX ${PROJECT_LANGUAGES})

include(GNUInstallDirs)

include(cmake/Djinni.cmake)

set(SRC_SHARED
"djinni/djinni_common.hpp"
"djinni/proxy_cache_interface.hpp"
Expand Down Expand Up @@ -48,6 +50,11 @@ set(SRC_CPPCLI
"djinni/cppcli/WrapperCache.cpp"
)

set(SRC_WASM
"djinni/wasm/djinni_wasm.hpp"
"djinni/wasm/djinni_wasm.cpp"
)

# set `DJINNI_LIBRARY_TYPE` to `STATIC` or `SHARED` to define the type of library.
# If undefined, the type will be determined based on `BUILD_SHARED_LIBS`
add_library(djinni_support_lib ${DJINNI_LIBRARY_TYPE} ${SRC_SHARED})
Expand Down Expand Up @@ -151,13 +158,14 @@ if(DJINNI_WITH_PYTHON)
endif()

option(DJINNI_WITH_CPPCLI "Include the C++/CLI support code in Djinni support library." OFF)
option(DJINNI_WITH_WASM "Include the WASM/TS support code in Djinni support library." OFF)
if(DJINNI_WITH_CPPCLI)

if(NOT MSVC)
message(FATAL_ERROR "Enabling DJINNI_WITH_CPPCLI without MSVC is not supported")
endif()

if(DJINNI_WITH_OBJC OR DJINNI_WITH_JNI OR DJINNI_WITH_PYTHON)
if(DJINNI_WITH_OBJC OR DJINNI_WITH_JNI OR DJINNI_WITH_PYTHON OR DJINNI_WITH_WASM)
message(FATAL_ERROR "DJINNI_WITH_CPPCLI can not be used with other bindings enabled.")
endif()

Expand All @@ -180,13 +188,31 @@ if(DJINNI_WITH_CPPCLI)
)
endif()

if(NOT (DJINNI_WITH_OBJC OR DJINNI_WITH_JNI OR DJINNI_WITH_PYTHON OR DJINNI_WITH_CPPCLI))
message(FATAL_ERROR "At least one of DJINNI_WITH_OBJC or DJINNI_WITH_JNI or DJINNI_WITH_PYTHON or DJINNI_WITH_CPPCLI must be enabled.")
if(DJINNI_WITH_WASM)

if(DJINNI_WITH_OBJC OR DJINNI_WITH_JNI OR DJINNI_WITH_PYTHON OR DJINNI_WITH_CPPCLI)
message(FATAL_ERROR "DJINNI_WITH_WASM can not be used with other bindings enabled.")
endif()

target_include_directories(djinni_support_lib PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/djinni/wasm>")
target_sources(djinni_support_lib PRIVATE ${SRC_WASM})
source_group("wasm" FILES ${SRC_WASM})
install(
FILES
"djinni/wasm/djinni_wasm.hpp"
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/djinni/wasm
)
endif()

if(NOT (DJINNI_WITH_OBJC OR DJINNI_WITH_JNI OR DJINNI_WITH_PYTHON OR DJINNI_WITH_CPPCLI OR DJINNI_WITH_WASM))
message(FATAL_ERROR "At least one of DJINNI_WITH_OBJC or DJINNI_WITH_JNI or DJINNI_WITH_PYTHON or DJINNI_WITH_CPPCLI or DJINNI_WITH_WASM must be enabled.")
endif()

option(DJINNI_BUILD_TESTING "Build tests" ON)

include(CTest)
if (BUILD_TESTING AND DJINNI_BUILD_TESTING)
add_subdirectory(examples)
add_subdirectory(test-suite)
endif()
Binary file added bin/djinni
Binary file not shown.
47 changes: 46 additions & 1 deletion test-suite/Djinni.cmake → cmake/Djinni.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ execute_process(COMMAND ${DJINNI_EXECUTABLE} "--version" OUTPUT_VARIABLE DJINNI_
string(REGEX REPLACE "\n+$" "" DJINNI_VERSION "${DJINNI_VERSION}")
message(STATUS "Found Djinni: ${DJINNI_EXECUTABLE} (${DJINNI_VERSION})")


macro(append_if_defined LIST OPTION)
if(NOT "${ARGN}" STREQUAL "")
list(APPEND ${LIST} ${OPTION} ${ARGN})
Expand Down Expand Up @@ -178,6 +177,15 @@ function(add_djinni_target)
CPPCLI_NAMESPACE
CPPCLI_INCLUDE_CPP_PREFIX

WASM_OUT
WASM_OUT_FILES
WASM_NAMESPACE

TS_OUT
TS_OUT_FILES
TS_MODULE
TS_SUPPORT_FILES_OUT

YAML_OUT
YAML_OUT_FILE
YAML_PREFIX
Expand Down Expand Up @@ -270,6 +278,10 @@ function(add_djinni_target)
append_if_defined(DJINNI_GENERATION_COMMAND "--cppcli-namespace" ${DJINNI_CPPCLI_NAMESPACE})
append_if_defined(DJINNI_GENERATION_COMMAND "--cppcli-include-cpp-prefix" ${DJINNI_CPPCLI_INCLUDE_CPP_PREFIX})

append_if_defined(DJINNI_GENERATION_COMMAND "--wasm-namespace" ${DJINNI_WASM_NAMESPACE})
append_if_defined(DJINNI_GENERATION_COMMAND "--ts-module" ${DJINNI_TS_MODULE})
append_if_defined(DJINNI_GENERATION_COMMAND "--ts-support-files-out" ${DJINNI_TS_SUPPORT_FILES_OUT})

if(DEFINED DJINNI_CPP_OUT_FILES)
set(DJINNI_CPP_GENERATION_COMMAND ${DJINNI_GENERATION_COMMAND})
append_if_defined(DJINNI_CPP_GENERATION_COMMAND "--cpp-out" ${DJINNI_CPP_OUT})
Expand Down Expand Up @@ -418,5 +430,38 @@ function(add_djinni_target)
set(${DJINNI_CPPCLI_OUT_FILES} ${CPPCLI_OUT_FILES} PARENT_SCOPE)
endif()

if(DEFINED DJINNI_WASM_OUT_FILES)
set(DJINNI_WASM_GENERATION_COMMAND ${DJINNI_GENERATION_COMMAND})
append_if_defined(DJINNI_WASM_GENERATION_COMMAND "--wasm-out" ${DJINNI_WASM_OUT})

resolve_djinni_outputs(COMMAND "${DJINNI_WASM_GENERATION_COMMAND}" RESULT WASM_OUT_FILES)

add_custom_command(
OUTPUT ${WASM_OUT_FILES}
DEPENDS ${DJINNI_INPUTS}
COMMAND ${DJINNI_WASM_GENERATION_COMMAND}
COMMENT "Generating Djinni Web Assembly bindings from ${DJINNI_IDL}"
VERBATIM
)
set(${DJINNI_WASM_OUT_FILES} ${WASM_OUT_FILES} PARENT_SCOPE)
endif()

if(DEFINED DJINNI_TS_OUT_FILES)
set(DJINNI_TS_GENERATION_COMMAND ${DJINNI_GENERATION_COMMAND})
append_if_defined(DJINNI_TS_GENERATION_COMMAND "--ts-out" ${DJINNI_TS_OUT})

resolve_djinni_outputs(COMMAND "${DJINNI_TS_GENERATION_COMMAND}" RESULT TS_OUT_FILES)

message(STATUS "Output: ${TS_OUT_FILES}, Depends: ${DJINNI_INPUTS}, Command: ${DJINNI_TS_GENERATION_COMMAND}")
add_custom_command(
OUTPUT ${TS_OUT_FILES}
DEPENDS ${DJINNI_INPUTS}
COMMAND ${DJINNI_TS_GENERATION_COMMAND}
COMMENT "Generating Djinni TS bindings from ${DJINNI_IDL}"
VERBATIM
)
set(${DJINNI_TS_OUT_FILES} ${TS_OUT_FILES} PARENT_SCOPE)
endif()

endfunction()

Loading
Loading