theseus-rs / postgresql-embedded

Embed PostgreSQL database
Apache License 2.0
54 stars 8 forks source link

how to use with wasm? #109

Closed smir-ant closed 1 month ago

smir-ant commented 1 month ago

yes, the option to use wasm and postgre embedded seems excessively strange. But this is exactly what I would like for my project

my project is compiled with cargo.toml:

[dependencies]
leptos = { version = "0.6", features = ["csr", "nightly"] }
leptos_meta = { version = "0.6", features = ["csr", "nightly"] }
leptos_router = { version = "0.6", features = ["csr", "nightly"] }
web-sys = "0.3.69"
reqwasm = "0.5.0"
scraper = "0.19.0"
wasm-bindgen-futures = "0.4.42"
rand = "0.8.5"

but if you add

postgresql_embedded = { version = "0.14.1", features = ["blocking"]}

then I get the following error:

error: could not compile mio (lib) due to 44 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for openssl-sys v0.9.102

Caused by:
  process didn't exit successfully: /Users/smir-ant/VSCodeProjects/sql_train/target/debug/build/openssl-sys-a84602623c43a1a4/build-script-main (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=WASM32_UNKNOWN_UNKNOWN_OPENSSL_LIB_DIR
  WASM32_UNKNOWN_UNKNOWN_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=WASM32_UNKNOWN_UNKNOWN_OPENSSL_INCLUDE_DIR
  WASM32_UNKNOWN_UNKNOWN_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=WASM32_UNKNOWN_UNKNOWN_OPENSSL_DIR
  WASM32_UNKNOWN_UNKNOWN_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_wasm32-unknown-unknown
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_wasm32_unknown_unknown
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_wasm32-unknown-unknown
  cargo:rerun-if-env-changed=PKG_CONFIG_wasm32_unknown_unknown
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_wasm32-unknown-unknown
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_wasm32_unknown_unknown
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: pkg-config has not been configured to support cross-compilation.

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.

  --- stderr
  thread 'main' panicked at /Users/smir-ant/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.102/build/find_normal.rs:190:5:

  Could not find directory of OpenSSL installation, and this -sys crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the OPENSSL_DIR environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, libssl-dev on Ubuntu or openssl-devel on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = aarch64-apple-darwin
  $TARGET = wasm32-unknown-unknown
  openssl-sys = 0.9.102

  note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
2024-07-18T21:09:38.473552Z ERROR ❌ error
error from build pipeline

I am still learning the rust language, but chatgpt told me the following: The problem you are facing is related to the fact that you are trying to build a project for the wasm32-unknown-unknown target platform, but postgresql_embedded and its dependencies, such as openssl-sys, require the installation of libraries that are not supported for this platform.

is it possible to fix it? how?

thanks

brianheineman commented 1 month ago

Hello @smir-ant, this project is installing PostgreSQL binaries and providing a wrapper so that Rust programs can treat it as if it were an embedded database. This means that this project will not work in a WASM context. I believe sqlite supports being compiled/run with WASM now; you might want to take a look at the rusqlite project if you are looking for an embedded database for a WASM project.

Cheers, -Brian

brianheineman commented 1 month ago

@smir-ant you might be interested in the pglite project.