From e17f05380bf268c631268a7b894b3b27e9acf2e3 Mon Sep 17 00:00:00 2001 From: Yves Date: Thu, 29 Feb 2024 10:22:29 -0500 Subject: [PATCH] Add `allowUnsignedExtensions` to DuckDB Config --- .github/workflows/main.yml | 4 ++-- Makefile | 6 +----- lib/CMakeLists.txt | 8 -------- lib/include/duckdb/web/config.h | 3 +++ lib/src/config.cc | 19 ++++++++++++------- lib/src/webdb.cc | 4 +--- packages/duckdb-wasm/src/bindings/config.ts | 4 ++++ 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3d839401..a5ccde568 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -490,7 +490,7 @@ jobs: - name: Build Wasm module run: | cp .github/config/extension_config_wasm.cmake submodules/duckdb/extension/extension_config.cmake - DUCKDB_PLATFORM="wasm_mvp" DUCKDB_WASM_LOADABLE_EXTENSIONS="signed" GEN=ninja ./scripts/wasm_build_lib.sh relsize mvp + DUCKDB_PLATFORM="wasm_mvp" DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize mvp - name: Upload artifact uses: actions/upload-artifact@v4 @@ -533,7 +533,7 @@ jobs: - name: Build Wasm module run: | cp .github/config/extension_config_wasm.cmake submodules/duckdb/extension/extension_config.cmake - DUCKDB_PLATFORM="wasm_eh" DUCKDB_WASM_LOADABLE_EXTENSIONS="signed" GEN=ninja ./scripts/wasm_build_lib.sh relsize eh + DUCKDB_PLATFORM="wasm_eh" DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize eh - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/Makefile b/Makefile index b77053554..2221a22d0 100644 --- a/Makefile +++ b/Makefile @@ -362,11 +362,7 @@ app: wasm wasmpack shell docs js_tests_release build_loadable: cp .github/config/extension_config_wasm.cmake submodules/duckdb/extension/extension_config.cmake - DUCKDB_PLATFORM=wasm_${TARGET} DUCKDB_WASM_LOADABLE_EXTENSIONS="signed" GEN=ninja ./scripts/wasm_build_lib.sh relsize ${TARGET} - -build_loadable_unsigned: - cp .github/config/extension_config_wasm.cmake submodules/duckdb/extension/extension_config.cmake - DUCKDB_PLATFORM=wasm_${TARGET} DUCKDB_WASM_LOADABLE_EXTENSIONS="unsigned" GEN=ninja ./scripts/wasm_build_lib.sh relsize ${TARGET} + DUCKDB_PLATFORM=wasm_${TARGET} DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize ${TARGET} serve_loadable_base: wasmpack shell docs yarn workspace @duckdb/duckdb-wasm-app build:release diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4ca63e490..683a3594f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -12,13 +12,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(ignoreMe "${DUCKDB_WASM_VERSION}") option(DUCKDB_WASM_LOADABLE_EXTENSIONS "Build with loadable extensions" OFF) -option(DUCKDB_WASM_LOADABLE_EXTENSIONS_UNSIGNED "Build with loadable extensions" OFF) if(DEFINED ENV{DUCKDB_WASM_LOADABLE_EXTENSIONS}) set(DUCKDB_WASM_LOADABLE_EXTENSIONS ON) - if("$ENV{DUCKDB_WASM_LOADABLE_EXTENSIONS}" STREQUAL "unsigned") - set(DUCKDB_WASM_LOADABLE_EXTENSIONS_UNSIGNED ON) - endif() endif() @@ -30,10 +26,6 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_EXTENSION_LOAD=1") endif() -if(DUCKDB_WASM_LOADABLE_EXTENSIONS_UNSIGNED) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWASM_LOADABLE_EXTENSIONS_UNSIGNED=1") -endif() - if(NOT EMSCRIPTEN) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined") diff --git a/lib/include/duckdb/web/config.h b/lib/include/duckdb/web/config.h index e5d5a91ee..527dbd31b 100644 --- a/lib/include/duckdb/web/config.h +++ b/lib/include/duckdb/web/config.h @@ -98,6 +98,9 @@ struct WebDBConfig { .s3_session_token = "", }; + /// Whether to allow unsigned extensions + bool allow_unsigned_extensions = false; + /// Read from a document static WebDBConfig ReadFrom(std::string_view args_json); }; diff --git a/lib/src/config.cc b/lib/src/config.cc index 49933780c..d6016e617 100644 --- a/lib/src/config.cc +++ b/lib/src/config.cc @@ -50,13 +50,15 @@ WebDBConfig WebDBConfig::ReadFrom(std::string_view args_json) { FileSystemConfig{ .allow_full_http_reads = std::nullopt, }, - .duckdb_config_options = DuckDBConfigOptions{ - .s3_region = "", - .s3_endpoint = "", - .s3_access_key_id = "", - .s3_secret_access_key = "", - .s3_session_token = "", - }}; + .duckdb_config_options = + DuckDBConfigOptions{ + .s3_region = "", + .s3_endpoint = "", + .s3_access_key_id = "", + .s3_secret_access_key = "", + .s3_session_token = "", + }, + .allow_unsigned_extensions = false}; rapidjson::Document doc; rapidjson::ParseResult ok = doc.Parse(args_json.begin(), args_json.size()); if (ok) { @@ -69,6 +71,9 @@ WebDBConfig WebDBConfig::ReadFrom(std::string_view args_json) { if (doc.HasMember("maximumThreads") && doc["maximumThreads"].IsNumber()) { config.maximum_threads = doc["maximumThreads"].GetInt(); } + if (doc.HasMember("allowUnsignedExtensions") && doc["allowUnsignedExtensions"].IsBool()) { + config.allow_unsigned_extensions = doc["allowUnsignedExtensions"].GetBool(); + } if (doc.HasMember("query") && doc["query"].IsObject()) { auto q = doc["query"].GetObject(); if (q.HasMember("queryPollingInterval") && q["queryPollingInterval"].IsNumber()) { diff --git a/lib/src/webdb.cc b/lib/src/webdb.cc index 096db4bc3..7b5d93240 100644 --- a/lib/src/webdb.cc +++ b/lib/src/webdb.cc @@ -812,9 +812,7 @@ arrow::Status WebDB::Open(std::string_view args_json) { duckdb::DBConfig db_config; db_config.file_system = std::move(buffered_fs); -#ifdef WASM_LOADABLE_EXTENSIONS_UNSIGNED - db_config.options.allow_unsigned_extensions = true; -#endif + db_config.options.allow_unsigned_extensions = config_->allow_unsigned_extensions; db_config.options.maximum_threads = config_->maximum_threads; db_config.options.use_temporary_directory = false; db_config.options.access_mode = access_mode; diff --git a/packages/duckdb-wasm/src/bindings/config.ts b/packages/duckdb-wasm/src/bindings/config.ts index e0cc9da4b..ba9033e4c 100644 --- a/packages/duckdb-wasm/src/bindings/config.ts +++ b/packages/duckdb-wasm/src/bindings/config.ts @@ -57,4 +57,8 @@ export interface DuckDBConfig { * The filesystem config */ filesystem?: DuckDBFilesystemConfig; + /** + * Whether to allow unsigned extensions + */ + allowUnsignedExtensions?: boolean; }