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

Bug: dependency ring cannot target wasm32_unknown_unknown #3321

Closed
2 tasks done
itsezc opened this issue Jan 14, 2024 · 10 comments
Closed
2 tasks done

Bug: dependency ring cannot target wasm32_unknown_unknown #3321

itsezc opened this issue Jan 14, 2024 · 10 comments
Labels
bug Something isn't working topic:rust This is related to the Rust embedded library triage This issue is new

Comments

@itsezc
Copy link
Contributor

itsezc commented Jan 14, 2024

Describe the bug

While trying to build a project with Dioxus and Surreal, I've tried following the guide laid out on docs.rs and ran through dx serve Surreal is preventing a successful build because of its dependency on ring.

Steps to reproduce

[INFO] 🚅 Running build command...
/ 💼 Waiting to start build the project...                                                                                                                     error: Broken pipe (os error 32)
The following warnings were emitted during compilation:


error: could not compile `psm` (lib) due to 2 previous errors
| 💼 Waiting to start build the project...                                                                                                                     The following warnings were emitted during compilation:


error: failed to run custom build command for `ring v0.17.7`

Caused by:
  process didn't exit successfully: `/../target/debug/build/ring-7e7f18b78a597f7d/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("0")
  TARGET = Some("wasm32-unknown-unknown")
  HOST = Some("aarch64-apple-darwin")
  cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown
  CC_wasm32-unknown-unknown = None
  cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown
  CC_wasm32_unknown_unknown = 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("true")
  cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown
  CFLAGS_wasm32-unknown-unknown = None
  cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown
  CFLAGS_wasm32_unknown_unknown = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "include" "-I" "/../target/wasm32-unknown-unknown/debug/build/ring-2d61977de46e0644/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-nostdlibinc" "-DNDEBUG" "-DRING_CORE_NOSTDLIBINC=1" "-o" "/../target/wasm32-unknown-unknown/debug/build/ring-2d61977de46e0644/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"
  cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'

  cargo:warning=1 error generated.

  exit status: 1

Expected behaviour

For a successful build and to use Surreal rs library through WASM

SurrealDB version

1.1.0

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@itsezc itsezc added bug Something isn't working triage This issue is new labels Jan 14, 2024
@kearfy kearfy added the topic:rust This is related to the Rust embedded library label Jan 16, 2024
@MDM23
Copy link

MDM23 commented Jan 16, 2024

I think I'm encountering a similar issue when trying to build the wasm32 part of Surrealist. The official build seems to work fine though.

  = note: rust-lld: error: unknown file type: /tmp/Surrealist/src-embed/target/wasm32-unknown-unknown/debug/deps/libring-7a9c2e89961580ad.rlib(curve25519.o)

build.log

@itsezc
Copy link
Contributor Author

itsezc commented Jan 22, 2024

This is a huge blocker for anyone trying to use the Surreal crate as client on their Rust frontend projects, would be interested on advice regarding whether to take this issue upstream (to ring) or leave it here.

@itsezc
Copy link
Contributor Author

itsezc commented Jan 22, 2024

Related: briansmith/ring#1824

@itsezc
Copy link
Contributor Author

itsezc commented Jan 23, 2024

Issue is only persistent on Apple Silicone Macs and not on elsewhere from my findings. Upstream issue comments suggest it's due to Apple Clang fork being different to LLMVs not supporting wasm compilation target.

Reference: briansmith/ring#1824 (comment)

Solutions:

@itsezc itsezc closed this as completed Jan 23, 2024
@MDM23
Copy link

MDM23 commented Jan 24, 2024

For reference - in order to be built with Nix, the following was required:

rustPlatform.buildRustPackage {

  # ...

  nativeBuildInputs = [
    rustc.llvmPackages.clangNoLibc
    rustc.llvmPackages.lld
  ];

  buildPhase = ''
    CC=clang CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER=lld cargo build \
      --target wasm32-unknown-unknown \
      --release
  '';
}

@rushmorem
Copy link
Collaborator

@itsezc Does this still happen for you on nightly? We merged a fix for ring two days ago.

@itsezc
Copy link
Contributor Author

itsezc commented Jan 24, 2024

@itsezc Does this still happen for you on nightly? We merged a fix for ring two days ago.

Yes it does @rushmorem, does not build on MacOS (due to what I believe to be an upstream issue with ring and custom clang Apple ships).

Here's how I have my Cargo.toml setup for surreal:

[dependencies]
	dioxus.workspace = true
	dioxus-web.workspace = true
	dioxus-router.workspace = true
	serde.workspace = true
	surrealdb = { git = 'https://github.com/surrealdb/surrealdb' }

Log:

The following warnings were emitted during compilation:


error: failed to run custom build command for `ring v0.17.7`

Caused by:
  process didn't exit successfully: `/Users/chiru/.../sites/target/debug/build/ring-0e1d20d85261a0d0/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("0")
  TARGET = Some("wasm32-unknown-unknown")
  HOST = Some("aarch64-apple-darwin")
  cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown
  CC_wasm32-unknown-unknown = None
  cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown
  CC_wasm32_unknown_unknown = 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("true")
  cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown
  CFLAGS_wasm32-unknown-unknown = None
  cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown
  CFLAGS_wasm32_unknown_unknown = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "include" "-I" "/Users/chiru/.../sites/target/wasm32-unknown-unknown/debug/build/ring-30cd627142dd0570/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-nostdlibinc" "-DNDEBUG" "-DRING_CORE_NOSTDLIBINC=1" "-o" "/Users/chiru/.../sites/target/wasm32-unknown-unknown/debug/build/ring-30cd627142dd0570/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"
  cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'

  cargo:warning=1 error generated.

  exit status: 1

  --- stderr


  error occurred: Command "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "include" "-I" "/Users/chiru/.../sites/target/wasm32-unknown-unknown/debug/build/ring-30cd627142dd0570/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-nostdlibinc" "-DNDEBUG" "-DRING_CORE_NOSTDLIBINC=1" "-o" "/Users/chiru/.../sites/target/wasm32-unknown-unknown/debug/build/ring-30cd627142dd0570/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c" with args "clang" did not execute successfully (status code exit status: 1).

@itsezc itsezc reopened this Jan 24, 2024
@rushmorem
Copy link
Collaborator

Can you try disabling rustls to see if the issue still persists?

surrealdb = { version = "1", default-features = false, features = ["protocol-ws"], package = "surrealdb-nightly" }

@itsezc
Copy link
Contributor Author

itsezc commented Jan 24, 2024

Can you try disabling rustls to see if the issue still persists?

surrealdb = { version = "1", default-features = false, features = ["protocol-ws"], package = "surrealdb-nightly" }

Using this config:

[dependencies]
	dioxus.workspace = true
	dioxus-web.workspace = true
	dioxus-router.workspace = true
	serde.workspace = true
	surrealdb = { version = "1", default-features = false, features = [
		"protocol-ws",
	], package = "surrealdb-nightly" }

Running dx serve or dx build results in:

dx serve
[INFO] 🚅 Running build command...
error: Broken pipe (os error 32)
Error: 🚫 Serving project failed: error: failed to build archive: 'wasm32.o': section too large


The following warnings were emitted during compilation:


error: could not compile `psm` (lib) due to 2 previous errors

Note: I'm using Dioxus 0.4.3

@rushmorem
Copy link
Collaborator

I think that new error is related to surrealdb/surrealdb.wasm#41. There is a potential workaround here surrealdb/surrealdb.wasm#41 (comment).

@itsezc itsezc closed this as completed Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic:rust This is related to the Rust embedded library triage This issue is new
Projects
None yet
Development

No branches or pull requests

4 participants