Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error building for wasm32-wasi #1408

Closed
pepperoni505 opened this issue Nov 2, 2023 · 5 comments
Closed

Error building for wasm32-wasi #1408

pepperoni505 opened this issue Nov 2, 2023 · 5 comments

Comments

@pepperoni505
Copy link

I'm trying to add rusqlite as a dependency to a project that is targeted at wasm32-wasi (building on Windows). I have the following in my Cargo.toml:

[dependencies.rusqlite]
features = ["bundled", "wasm32-wasi-vfs", "winsqlite3"]
version = "0.29.0"

Running that gives me this error:

   Compiling libsqlite3-sys v0.26.0
error: failed to run custom build command for `libsqlite3-sys v0.26.0`

Caused by:
  process didn't exit successfully: `C:\Users\jack\Documents\Code\rusqlite-test\target\release\build\libsqlite3-sys-75bb46df9d8d601c\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'Could not copy bindings to output directory: Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." }', C:\Users\jack\.cargo\registry\src\github.com-1ecc6299db9ec823\libsqlite3-sys-0.26.0\build.rs:102:18
  stack backtrace:
     0:     0x7ff6bb8df8d2 - <unknown>
     1:     0x7ff6bb8fb4db - <unknown>
     2:     0x7ff6bb8d98fa - <unknown>
     3:     0x7ff6bb8e24b4 - <unknown>
     4:     0x7ff6bb8e20ea - <unknown>
     5:     0x7ff6bb8e2ca1 - <unknown>
     6:     0x7ff6bb8e2bad - <unknown>
     7:     0x7ff6bb8e05df - <unknown>
     8:     0x7ff6bb8e2870 - <unknown>
     9:     0x7ff6bb901bb5 - <unknown>
    10:     0x7ff6bb901c53 - <unknown>
    11:     0x7ff6bb842e0d - <unknown>
    12:     0x7ff6bb841130 - <unknown>
    13:     0x7ff6bb843585 - <unknown>
    14:     0x7ff6bb842496 - <unknown>
    15:     0x7ff6bb8420a9 - <unknown>
    16:     0x7ff6bb84254c - <unknown>
    17:     0x7ff6bb8d52ae - <unknown>
    18:     0x7ff6bb842527 - <unknown>
    19:     0x7ff6bb84363c - <unknown>
    20:     0x7ff6bb900220 - <unknown>
    21:     0x7fff5247257d - BaseThreadInitThunk
    22:     0x7fff534caa58 - RtlUserThreadStart

Removing the bundled option in features fixes this error, but I do need to use that option. I've taken a look at some of the other issues relating to WASM support but I couldn't really figure anything out. Any insight would be appreciated!

@gwenn
Copy link
Collaborator

gwenn commented Nov 2, 2023

For winsqlite3 feature:
=> #1270
So please, remove it even if you still have the same error.

@thomcc
Copy link
Member

thomcc commented Nov 2, 2023

Nobody should use the winsqlite3 feature in general. But if you're using it when trying to compile to wasm, you'll certainly have a bad time.

@pepperoni505
Copy link
Author

Removed the winsqlite3 feature and my error changed:

warning: sqlite3/sqlite3.c:14183:10: fatal error: 'stdio.h' file not found
warning: #include <stdio.h>
warning:          ^~~~~~~~~
warning: 1 error generated.

error: failed to run custom build command for `libsqlite3-sys v0.26.0`

Caused by:
  process didn't exit successfully: `C:\Users\peppe\Documents\Code\rusqlite-test\target\release\build\libsqlite3-sys-59408460b12e7548\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-changed=sqlite3/sqlite3.c
  cargo:rerun-if-changed=sqlite3/wasm32-wasi-vfs.c
  cargo:rerun-if-env-changed=SQLITE_MAX_VARIABLE_NUMBER
  cargo:rerun-if-env-changed=SQLITE_MAX_EXPR_DEPTH
  cargo:rerun-if-env-changed=LIBSQLITE3_FLAGS
  TARGET = Some("wasm32-wasi")
  OPT_LEVEL = Some("3")
  HOST = Some("x86_64-pc-windows-msvc")
  cargo:rerun-if-env-changed=CC_wasm32-wasi
  CC_wasm32-wasi = None
  cargo:rerun-if-env-changed=CC_wasm32_wasi
  CC_wasm32_wasi = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  cargo:rerun-if-env-changed=CFLAGS_wasm32-wasi
  CFLAGS_wasm32-wasi = None
  cargo:rerun-if-env-changed=CFLAGS_wasm32_wasi
  CFLAGS_wasm32_wasi = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-DSQLITE_CORE" "-DSQLITE_DEFAULT_FOREIGN_KEYS=1" "-DSQLITE_ENABLE_API_ARMOR" "-DSQLITE_ENABLE_COLUMN_METADATA" "-DSQLITE_ENABLE_DBSTAT_VTAB" "-DSQLITE_ENABLE_FTS3" "-DSQLITE_ENABLE_FTS3_PARENTHESIS" "-DSQLITE_ENABLE_FTS5" "-DSQLITE_ENABLE_JSON1" "-DSQLITE_ENABLE_LOAD_EXTENSION=1" "-DSQLITE_ENABLE_MEMORY_MANAGEMENT" "-DSQLITE_ENABLE_RTREE" "-DSQLITE_ENABLE_STAT2" "-DSQLITE_ENABLE_STAT4" "-DSQLITE_SOUNDEX" "-DSQLITE_THREADSAFE=1" "-DSQLITE_USE_URI" "-DHAVE_USLEEP=1" "-D_POSIX_THREAD_SAFE_FUNCTIONS" "-DHAVE_ISNAN" "-DHAVE_LOCALTIME_R" "-o" "C:\\Users\\peppe\\Documents\\Code\\rusqlite-test\\target\\wasm32-wasi\\release\\build\\libsqlite3-sys-855966926157e9d5\\out\\sqlite3/sqlite3.o" "-c" "sqlite3/sqlite3.c"
  cargo:warning=sqlite3/sqlite3.c:14183:10: fatal error: 'stdio.h' file not found

  cargo:warning=#include <stdio.h>

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

  cargo:warning=1 error generated.

  exit code: 1

  --- stderr


  error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-DSQLITE_CORE" "-DSQLITE_DEFAULT_FOREIGN_KEYS=1" "-DSQLITE_ENABLE_API_ARMOR" "-DSQLITE_ENABLE_COLUMN_METADATA" "-DSQLITE_ENABLE_DBSTAT_VTAB" "-DSQLITE_ENABLE_FTS3" "-DSQLITE_ENABLE_FTS3_PARENTHESIS" "-DSQLITE_ENABLE_FTS5" "-DSQLITE_ENABLE_JSON1" "-DSQLITE_ENABLE_LOAD_EXTENSION=1" "-DSQLITE_ENABLE_MEMORY_MANAGEMENT" "-DSQLITE_ENABLE_RTREE" "-DSQLITE_ENABLE_STAT2" "-DSQLITE_ENABLE_STAT4" "-DSQLITE_SOUNDEX" "-DSQLITE_THREADSAFE=1" "-DSQLITE_USE_URI" "-DHAVE_USLEEP=1" "-D_POSIX_THREAD_SAFE_FUNCTIONS" "-DHAVE_ISNAN" "-DHAVE_LOCALTIME_R" "-o" "C:\\Users\\peppe\\Documents\\Code\\rusqlite-test\\target\\wasm32-wasi\\release\\build\\libsqlite3-sys-855966926157e9d5\\out\\sqlite3/sqlite3.o" "-c" "sqlite3/sqlite3.c" with args "clang" did not execute successfully (status code exit code: 1).

Also, should I be using bundled or bundled-windows?

@zrus
Copy link

zrus commented Nov 9, 2023

Any updates on this?

@pepperoni505
Copy link
Author

pepperoni505 commented Nov 9, 2023

Any updates on this?

Yeah, I got this resolved with downloading the wasi-sdk (https://github.com/WebAssembly/wasi-sdk, in my case I used v19). I then made a batch file to set a few environmental variables:

set "CLANG_LIB_WASI=%WASI_SDK%\\lib\\clang\\15.0.7\\lib\\wasi"
set "WASI_SYSROOT=%WASI_SDK%\\share\\wasi-sysroot"
set "CC=%WASI_SDK%\\bin\\clang --sysroot=%WASI_SYSROOT%"
set "AR=%WASI_SDK%\\bin\\llvm-ar"
set "CC_wasm32_wasi=%WASI_SDK%\\bin\\clang"
set "LIBSQLITE3_FLAGS=-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_SHARED_CACHE -D_LARGEFILE64_SOURCE"
set "RUSTFLAGS=-Clink-arg=-L%CLANG_LIB_WASI% -Clink-arg=-lclang_rt.builtins-wasm32 -Clink-arg=--export-table -Clink-arg=--export=malloc -Clink-arg=--export=free"

One of the most important parts of that is linking the clang_rt.builtins-wasm32, as without that my WASM output was trying to import functions that weren't exposed to it/didn't exist on my target platform:
image

Hopefully this works for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants