Replies: 21 comments 1 reply
-
I would be interested in this as well. AFAIU, it will not work because C compilation is involved and that is currently not supported/broken for this target. |
Beta Was this translation helpful? Give feedback.
-
@paulyoung random question, but is there a reason you are targeting My understanding is that sqlite expects to do I/O internally and the Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
@ipetkov yes, the platform I’m using has a custom Wasm environment that doesn’t support Wasi and requires The branch of |
Beta Was this translation helpful? Give feedback.
-
@paulyoung ah I see! Unfortunately I'm not very familiar with Are you able to successfully build the project outside of Nix? If yes, then clearly there is some part of the toolchain which is missing in the Nix version and needs to be included (or have the right environment variables set) to make the compilation work |
Beta Was this translation helpful? Give feedback.
-
@paulyoung I just saw this comment and taking it's advice to set diff --git a/flake.nix b/flake.nix
index 6b73a79..85751b4 100644
--- a/flake.nix
+++ b/flake.nix
@@ -43,17 +43,16 @@
# our specific toolchain there.
craneLib = (crane.mkLib pkgs).overrideToolchain rustWithWasmTarget;
+ stdenv = pkgs.llvmPackages_14.stdenv;
+
rusqlite-wasm32-unknown-unknown-nix = craneLib.buildPackage ({
+ inherit stdenv;
src = ./.;
cargoExtraArgs = "--package rusqlite-wasm32-unknown-unknown-nix";
# crane tries to run the Wasm file as if it were a binary
doCheck = false;
- # Without setting TARGET_CC we run into:
- #
- # "valid target CPU values are: mvp, bleeding-edge, generic"
- #
- # https://github.com/rusqlite/rusqlite/pull/1010#issuecomment-1247333415
- TARGET_CC = "${pkgs.stdenv.cc.nativePrefix}cc";
+ CC = "${stdenv.cc.nativePrefix}cc";
+ AR = "${stdenv.cc.nativePrefix}ar";
});
in
{ |
Beta Was this translation helpful? Give feedback.
-
Did it work? |
Beta Was this translation helpful? Give feedback.
-
I'm about to try this. It looks very promising! |
Beta Was this translation helpful? Give feedback.
-
I applied the changes above in paulyoung/rusqlite-wasm32-unknown-unknown-nix@8698a65 and ran into the same error as when I didn't set Full logcargoArtifacts not set, will not reuse any cargo artifacts @nix { "action": "setPhase", "phase": "unpackPhase" } unpacking sources unpacking source archive /nix/store/zym8hl55jd14f7ymznkkrm7bs3y9v1qg-dummy-src source root is dummy-src @nix { "action": "setPhase", "phase": "patchPhase" } patching sources Executing configureCargoCommonVars @nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" } updateAutotoolsGnuConfigScriptsPhase @nix { "action": "setPhase", "phase": "configurePhase" } configuring will append /private/tmp/nix-build-cargo-package-deps-0.0.1.drv-0/dummy-src/.cargo-home/config.toml with contents of /nix/store/awr9r66x6dldaiqzv4l20c3dal2j2h31-vendor-cargo-deps/config.toml no configure script, doing nothing @nix { "action": "setPhase", "phase": "buildPhase" } building ++ command cargo --version cargo 1.63.0-nightly (39ad1039d 2022-05-25) ++ command cargo check --profile release --all-targets --package rusqlite-wasm32-unknown-unknown-nix �[0m�[0m�[1m�[32m Compiling�[0m proc-macro2 v1.0.43 �[0m�[0m�[1m�[32m Compiling�[0m quote v1.0.21 �[0m�[0m�[1m�[32m Compiling�[0m unicode-ident v1.0.4 �[0m�[0m�[1m�[32m Compiling�[0m log v0.4.17 �[0m�[0m�[1m�[32m Compiling�[0m wasm-bindgen-shared v0.2.83 �[0m�[0m�[1m�[32m Compiling�[0m syn v1.0.99 �[0m�[0m�[1m�[32m Compiling�[0m cfg-if v1.0.0 �[0m�[0m�[1m�[32m Compiling�[0m bumpalo v3.11.0 �[0m�[0m�[1m�[32m Compiling�[0m once_cell v1.14.0 �[0m�[0m�[1m�[32m Compiling�[0m wasm-bindgen v0.2.83 �[0m�[0m�[1m�[32m Compiling�[0m version_check v0.9.4 �[0m�[0m�[1m�[32m Compiling�[0m vcpkg v0.2.15 �[0m�[0m�[1m�[32m Compiling�[0m cc v1.0.73 �[0m�[0m�[1m�[32m Compiling�[0m pkg-config v0.3.25 �[0m�[0m�[1m�[32m Compiling�[0m memchr v2.5.0 �[0m�[0m�[1m�[32m Compiling�[0m rusqlite-wasm32-unknown-unknown-nix v0.1.0 (/private/tmp/nix-build-cargo-package-deps-0.0.1.drv-0/dummy-src/crates/rusqlite-wasm32-unknown-unknown-nix) �[0m�[0m�[1m�[32m Checking�[0m fallible-streaming-iterator v0.1.9 �[0m�[0m�[1m�[32m Checking�[0m bitflags v1.3.2 �[0m�[0m�[1m�[32m Checking�[0m fallible-iterator v0.2.0 �[0m�[0m�[1m�[32m Checking�[0m smallvec v1.9.0 �[0m�[0m�[1m�[32m Compiling�[0m ahash v0.7.6 �[0m�[0m�[1m�[32m Compiling�[0m libsqlite3-sys v0.23.2 (https://github.com/trevyn/rusqlite.git?branch=wasm32-unknown-unknown#004cf263) �[0m�[0m�[1m�[32m Checking�[0m hashbrown v0.11.2 �[0m�[0m�[1m�[32m Checking�[0m hashlink v0.7.0 The following warnings were emitted during compilation: |
Beta Was this translation helpful? Give feedback.
-
I'm confused how things are supposed to work, and I'm struggling with my own project that I need to compile to wasm32. The binaries produced by C compilers invoked by When I google how to do cross compilation in Nix, it always points me to https://nixos.org/guides/cross-compilation.html . But |
Beta Was this translation helpful? Give feedback.
-
@paulyoung one thing I noticed is your flake is trying to build on darwin. In my experience the Apple/system toolchains present in nixpkgs tend to be a bit behind the latest and greatest versions released by Apple. Looking at the logs it seems like If I update your flake to include "x86_64-linux" it builds just fine for me. Unfortunately I don't know enough about the state of nixpkgs and its interaction with Apple SDKs to figure out where the misconfiguration is happening |
Beta Was this translation helpful? Give feedback.
-
@dpc Nix's cross compiling utilities (via Fwiw nixpkgs does have |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hmmmm, based on this comment: https://stackoverflow.com/questions/69039082/nixs-clang-wont-build-wasm/69124536#69124536 What if you change the |
Beta Was this translation helpful? Give feedback.
-
If you use Nix-unwrapped ( |
Beta Was this translation helpful? Give feedback.
-
I have figured out compilation for our project for Android and wasm32: https://github.com/fedimint/fedimint/blob/9fb4a608d7f3a5cd1d9775a3178fb0098c10d449/flake.nix#L50 |
Beta Was this translation helpful? Give feedback.
-
@dpc can you share anything about how you figured this out? I'm wondering if I can do anything similar to determine exactly what I need. |
Beta Was this translation helpful? Give feedback.
-
The general idea is to just use unwrapped compilers and set all the C flags that |
Beta Was this translation helpful? Give feedback.
-
@dpc how did you figure that out exactly? I tried using an unwrapped compiler and ran into the exact issue you described above with |
Beta Was this translation helpful? Give feedback.
-
I wonder how relevant this is these days (from rustwasm/team#291)
|
Beta Was this translation helpful? Give feedback.
-
Lots of googling, reading and trying things out.
We use clang_14 or just https://github.com/fedimint/fedimint/actions/runs/3352395658 |
Beta Was this translation helpful? Give feedback.
-
I saw this was converted to a discussion so I thought I’d share a comment I left on an unrelated issue which also explains why I’m not pursuing this for now:
|
Beta Was this translation helpful? Give feedback.
-
I've described my issues with building rusqlite/rusqlite#1010 using crane in detail at https://discourse.nixos.org/t/help-building-rusqlite-for-wasm32-unknown-unknown-with-crane/21724 and created a standalone project at https://github.com/paulyoung/rusqlite-wasm32-unknown-unknown-nix . I'd appreciate it if someone could take a look.
My main motivation for filing this issue is that I (perhaps incorrectly) suspect that crane might be doing something to the build that I don't understand (perhaps via automatic handling of git dependencies?) such as trying to set certain environment variables.
Apologies if this is not an appropriate use of issues for this project. I suspect it might be an interesting use case to discuss and helpful for other crane users in the future.
Thanks for crane; this is my first time using it and I like it a lot so far.
Beta Was this translation helpful? Give feedback.
All reactions