duckdb / duckdb-wasm

WebAssembly version of DuckDB
https://shell.duckdb.org
MIT License
1.02k stars 110 forks source link

How to integrate with Rust WASM build? #1385

Open gitmalong opened 10 months ago

gitmalong commented 10 months ago

What happens?

I am trying to integrate DuckDb in a Rust Client Side Rendered WASM project as seen here: https://github.com/leptos-rs/leptos/tree/main/examples/tailwind_csr_trunk

When adding duckdb duckdb = { version = "0.8.1", features = ["bundled"] } the build fails with cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'

To Reproduce

git clone  https://github.com/leptos-rs/leptos/
cd leptos/examples/tailwind_csr_trunk
cargo add duckdb --features bundled
cargo run

OS:

macOS

DuckDB Version:

0.8.1 crate

DuckDB Client:

https://crates.io/crates/duckdb

Full Name:

Ma zhang

Affiliation:

hobby

Have you tried this on the latest master branch?

I have tested with a master build

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

Mause commented 10 months ago

This sounds like an issue with your version of clang, see https://github.com/WebAssembly/wasi-sdk/issues/172

gitmalong commented 10 months ago

I just installed llvm 16 via homebrew. Then my build says:

...
  cargo:warning=In file included from duckdb/src/include/duckdb/optimizer/statistics_propagator.hpp:11:

  cargo:warning=In file included from duckdb/src/include/duckdb/common/common.hpp:11:

  cargo:warning=duckdb/src/include/duckdb/common/constants.hpp:11:10: fatal error: 'memory' file not found

  cargo:warning=#include <memory>

  cargo:warning=         ^~~~~~~~

  cargo:warning=In file included from duckdb/third_party/libpg_query/src_common_keywords.cpp:24:

  cargo:warning=duckdb/third_party/libpg_query/include/pg_functions.hpp:3:10: fatal error: 'stdlib.h' file not found

  cargo:warning=#include <stdlib.h>

...

Not sure how I can tell the duckdb build to use my homebrew llvm if this is the root of the problem?

carlopi commented 10 months ago

Welcome @gitmalong!

First a word of advice: coupling duckdb-wasm with Rust will require some effort.

As for how to build duckdb with recent llvm:

CMAKE_LLVM_PATH='/usr/local/opt/llvm' make

has been recently addded just for this purpose.

(Your llvm folder will be somewhere else, but basically if clang++ is located in some/folder/llvm/bin/clang++ then you need to pass CMAKE_LLVM_PATH=some/folder/llvm.

gh-everglades commented 2 days ago

Hello @gitmalong, I am curious if you were able to integrate leptos with duckdb and compile it to wasm. I am developing a project in which the idea is to use egui https://github.com/emilk/egui to build the frontend and I would like to have Duckdb as the database for it. I am using trunk to build and I am getting similar errors like fatal error: 'memory' file not found.

I wonder if you found a solution, I dont want to develop the Frontend in React or something similar.