diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 1d9cb16..9792c9e 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,11 +1,11 @@ set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) set(SNAPPY_URL "https://github.com/google/snappy.git" CACHE STRING "Url to Snappy git") -set(SNAPPY_TAG "1.1.7" CACHE STRING "Git tag to build") +set(SNAPPY_TAG "1.2.0" CACHE STRING "Git tag to build") set(SNAPPY_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" -DSNAPPY_BUILD_TESTS=OFF) set(LEVELDB_URL "https://github.com/google/leveldb.git" CACHE STRING "URL to LevelDB git") -set(LEVELDB_TAG "1.21" CACHE STRING "Git tag to build") +set(LEVELDB_TAG "1.23" CACHE STRING "Git tag to build") set(LEVELDB_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" -DLEVELDB_BUILD_TESTS=OFF -DLEVELDB_BUILD_BENCHMARKS=OFF) set(EXTERNAL_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/external-install) @@ -36,7 +36,7 @@ set (LEVELDB_REQUIRED_FLAGS ExternalProject_Add(leveldb_external GIT_REPOSITORY ${LEVELDB_URL} GIT_TAG ${LEVELDB_TAG} - PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/leveldb.compaction.patch + PATCH_COMMAND patch --batch --dry-run --read-only=ignore --reverse --silent -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/leveldb.compaction.patch && echo "Patch already applied" || patch --forward -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/leveldb.compaction.patch CMAKE_ARGS ${CMAKE_ARGS} ${LEVELDB_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_DIR}" diff --git a/main.cpp b/main.cpp index e197699..2441395 100644 --- a/main.cpp +++ b/main.cpp @@ -23,6 +23,20 @@ static void dumpAllKeys(leveldb::DB* db, bool keysOnly) { } } +#ifdef EMSCRIPTEN +// note - this is an emscripten specific workaround to write binary to stdout +// for some reason, doing an frwrite to stdout produces garbage, probably +// because of utf-8 conversion ?? +EM_JS(void, to_stdout, (const char* buffer, size_t length), { + const array = new Uint8Array(length); + for (let i = 0; i < length; i++) { + array[i] = getValue(buffer + i, 'i8'); + } + + process.stdout.write(array); +}); +#endif + static bool dumpValue(leveldb::DB* db, const std::string& key) { auto iter = std::unique_ptr{db->NewIterator({})}; iter->Seek(key); @@ -31,8 +45,12 @@ static bool dumpValue(leveldb::DB* db, const std::string& key) { return false; } +#ifdef EMSCRIPTEN + to_stdout(iter->value().data(), iter->value().size()); +#else // use fwrite to make sure that \0 bytes are also written fwrite(iter->value().data(), 1, iter->value().size(), stdout); +#endif return true; }