Skip to content

Commit

Permalink
Partial cherry-pick from dengkunli:feature-opfs
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopi committed Nov 20, 2023
1 parent f8d17f4 commit 1b47ff7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
10 changes: 8 additions & 2 deletions examples/esbuild-browser/serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
{
"source": "*",
"headers": [
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" },
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" }
{
"key": "Cross-Origin-Embedder-Policy",
"value": "require-corp"
},
{
"key": "Cross-Origin-Opener-Policy",
"value": "same-origin"
}
]
}
]
Expand Down
11 changes: 3 additions & 8 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(DEFINED ENV{DUCKDB_WASM_LOADABLE_EXTENSIONS})
endif()


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -DDUCKDB_WASM=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -DDUCKDB_WASM=1 -DFSST_MUST_ALIGN")

if(DUCKDB_WASM_LOADABLE_EXTENSIONS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWASM_LOADABLE_EXTENSIONS=1 -DDUCKDB_EXTENSION_AUTOLOAD_DEFAULT=1 -fPIC")
Expand Down Expand Up @@ -110,16 +110,11 @@ if(EMSCRIPTEN)
endif()
# Debug build
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
--profiling \
-gsource-map \
--source-map-base=file://${CMAKE_BINARY_DIR}/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} \
-sASSERTIONS=1 \
-sSAFE_HEAP=1 \
-gsource-map \
--source-map-base=file://${CMAKE_BINARY_DIR}/ \
-sSEPARATE_DWARF_URL=file://${CMAKE_BINARY_DIR}/duckdb.wasm")
-g")
# ... with fast linking
if(WASM_FAST_LINKING)
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -O0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ for (const func of Object.getOwnPropertyNames(BROWSER_RUNTIME)) {
// We just override the load handler of the pthread wrapper to bundle DuckDB with esbuild.
globalThis.onmessage = (e: any) => {
if (e.data.cmd === 'load') {
const m = pthread_api.getModule();
let m = pthread_api.getModule();

// Module and memory were sent from main thread
(globalThis as any).startWorker = (instance: any) => {
m = instance;
postMessage({ cmd: 'loaded' });
};
m['wasmModule'] = e.data.wasmModule;
m['wasmMemory'] = e.data.wasmMemory;
m['buffer'] = m['wasmMemory'].buffer;
m['ENVIRONMENT_IS_PTHREAD'] = true;

DuckDB(m).then(function (instance) {
DuckDB(m).then((instance: any) => {
pthread_api.setModule(instance);
});
} else if (e.data.cmd === 'registerFileHandle') {
Expand Down

0 comments on commit 1b47ff7

Please sign in to comment.