diff --git a/.ci/version.txt b/.ci/version.txt index 7b3d094307..5bbe3dd2cb 100644 --- a/.ci/version.txt +++ b/.ci/version.txt @@ -1,5 +1,5 @@ 1.22.0 dev -1 +2 53ffd477e36c5f4ee52621c2fbd8583f64abe9111e098b6226c73fbd6e409670 \ No newline at end of file diff --git a/api/wasm/indigo-ketcher/CMakeLists.txt b/api/wasm/indigo-ketcher/CMakeLists.txt index bc1c80b14f..a6253465f0 100644 --- a/api/wasm/indigo-ketcher/CMakeLists.txt +++ b/api/wasm/indigo-ketcher/CMakeLists.txt @@ -5,34 +5,59 @@ project(indigo-ketcher) add_library(${PROJECT_NAME}-object OBJECT indigo-ketcher.cpp) target_link_libraries(${PROJECT_NAME}-object indigo-static indigo-inchi-static indigo-renderer-static cppcodec) -set(EMCC_FLAGS +if (CMAKE_BUILD_TYPE STREQUAL Debug) + set(EMCC_FLAGS + -g + ) +else () + set(EMCC_FLAGS + -Oz + ) +endif () + +set(EMCC_COMMON_FLAGS --bind -s INITIAL_MEMORY=32mb -s ALLOW_MEMORY_GROWTH=1 -s DISABLE_EXCEPTION_CATCHING=0 - -s SINGLE_FILE=1 -s MODULARIZE=1 -s FILESYSTEM=1 -s ASSERTIONS=1 -s USE_SDL=0 -s USE_SDL_IMAGE=0 -s USE_SDL_TTF=0 -s USE_SDL_NET=0 - --no-entry) -if (CMAKE_BUILD_TYPE STREQUAL Debug) - list(APPEND EMCC_FLAGS - -g - ) -elseif (CMAKE_BUILD_TYPE STREQUAL Release) - list(APPEND EMCC_FLAGS - -Oz - ) -endif () + --no-entry + ${EMCC_FLAGS} + ) + +set(EMCC_FLAGS_SEPARATE + ${EMCC_COMMON_FLAGS} + -s SINGLE_FILE=0 + ) + +set(EMCC_FLAGS + ${EMCC_COMMON_FLAGS} + -s SINGLE_FILE=1 + ) + +set(TARGET_FILES + $ + $ $ $ $ $ $ $ $ $ $ $ $ + ) + +add_custom_target(${PROJECT_NAME}-separate + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + COMMAND emcc + -o ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/indigo-ketcher-separate-wasm.js + ${EMCC_FLAGS_SEPARATE} + ${TARGET_FILES} + DEPENDS ${PROJECT_NAME}-object + ) add_custom_target(${PROJECT_NAME} COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} COMMAND emcc -o ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/indigo-ketcher.js ${EMCC_FLAGS} - $ - $ $ $ $ $ $ $ $ $ $ $ $ + ${TARGET_FILES} DEPENDS ${PROJECT_NAME}-object ) @@ -43,12 +68,13 @@ if (NOT RENDER_ENABLE_CJK) COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ COMMAND npm install COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test/ ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ + WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/patch.cmake COMMAND npm test COMMAND npm pack COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_DIRECTORY} COMMAND ${COPY_COMMAND} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}${SEP}${PROJECT_NAME}*.tgz ${NATIVE_DIST_DIRECTORY}${SEP} - WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} - DEPENDS ${PROJECT_NAME} + DEPENDS ${PROJECT_NAME} ${PROJECT_NAME}-separate ) else () add_custom_target(${PROJECT_NAME}-package @@ -58,12 +84,13 @@ else () COMMAND npm install COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test/ ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test-cjk/ ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ + WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/patch.cmake COMMAND npm test COMMAND npm run test_cjk COMMAND npm pack COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_DIRECTORY} COMMAND ${COPY_COMMAND} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}${SEP}${PROJECT_NAME}*.tgz ${NATIVE_DIST_DIRECTORY}${SEP} - WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} - DEPENDS ${PROJECT_NAME} + DEPENDS ${PROJECT_NAME} ${PROJECT_NAME}-separate ) -endif () +endif () \ No newline at end of file diff --git a/api/wasm/indigo-ketcher/package.json b/api/wasm/indigo-ketcher/package.json index 47024869fe..54e6d4422c 100644 --- a/api/wasm/indigo-ketcher/package.json +++ b/api/wasm/indigo-ketcher/package.json @@ -2,9 +2,20 @@ "name": "indigo-ketcher", "version": "1.22.0-dev.1-2", "description": "WASM implementation of Indigo organic chemistry toolkit web service for Ketcher", - "main": "indigo-ketcher.js", + "exports": { + ".": { + "import": "./indigo-ketcher.js", + "require": "./indigo-ketcher.js" + }, + "./binaryWasm": { + "import": "./indigo-ketcher-separate-wasm.js", + "require": "./indigo-ketcher-separate-wasm.js" + } + }, "files": [ + "indigo-ketcher-separate-wasm.js", "indigo-ketcher.js", + "indigo-ketcher-separate-wasm.wasm", "README.md", "LICENSE" ], diff --git a/api/wasm/indigo-ketcher/patch.cmake b/api/wasm/indigo-ketcher/patch.cmake new file mode 100644 index 0000000000..106ba5eee8 --- /dev/null +++ b/api/wasm/indigo-ketcher/patch.cmake @@ -0,0 +1,17 @@ +file(READ package.json packageJson) + +string(REGEX REPLACE ".*\"version\": \"([^\"]*)\".*" "\\1" version ${packageJson}) +message("Version is: ${version}") +# patch package.json +string(REPLACE "indigo-ketcher-separate-wasm.wasm" "indigo-ketcher-${version}.wasm" modifiedPackageJson ${packageJson}) +file(WRITE package.json "${modifiedPackageJson}") + +# patch indigo-ketcher-separate-wasm.js +file(READ indigo-ketcher-separate-wasm.js content) +string(REPLACE "indigo-ketcher-separate-wasm.wasm" "/indigo-ketcher-${version}.wasm" content "${content}") +string(REPLACE "fetch(binaryFile" "fetch(new URL(binaryFile, self.location.origin)" content "${content}") + +file(WRITE "indigo-ketcher-separate-wasm.js" "${content}") + +# rename indigo-ketcher.wasm +file(RENAME indigo-ketcher-separate-wasm.wasm indigo-ketcher-${version}.wasm)