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

How to use the no_std variant #576

Closed
Kofituo opened this issue May 20, 2023 · 9 comments
Closed

How to use the no_std variant #576

Kofituo opened this issue May 20, 2023 · 9 comments
Labels
Z6-question Further information is requested

Comments

@Kofituo
Copy link

Kofituo commented May 20, 2023

I'm running a Yew app and I want to import this crate.
Here's my Cargo.toml

[package]
name = "trunk-template"
version = "0.1.0"
edition = "2021"
description = "Template for starting a Yew project using Trunk"
readme = "README.md"
repository = "https://github.com/yewstack/yew-trunk-minimal-template"
license = "MIT OR Apache-2.0"
keywords = ["yew", "trunk"]
categories = ["gui", "wasm", "web-programming"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yew = { version = "0.20", features = ["csr"] }
schnorrkel = { features = ["nightly"], version = "0.9.1" }
getrandom = { version = "0.2", features = ["js"] }
tiny-bip39 = "1.0.0"
substrate-bip39 = "0.4.4"
web-sys = { version = "0.3", features = ["Event", "EventTarget", "InputEvent"] }
wasm-bindgen = "0.2"
hex = "0.4.3"
gloo-dialogs = "0.1.1"
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", default-features = false, features = ["disable_target_static_assertions"] }

[dev-dependencies]
tokio = { version = "1.23.0", features = ["full"] }

This is the error I get after running trunk build:

INFO 📦 starting build
2023-05-20T09:09:38.178102Z  INFO spawning asset pipelines
2023-05-20T09:09:41.199472Z  INFO building trunk-template
2023-05-20T09:09:41.200462Z  INFO compiling sass/scss path="index.scss"
2023-05-20T09:09:41.383644Z  INFO finished compiling sass/scss path="index.scss"
   Compiling secp256k1-sys v0.6.1
The following warnings were emitted during compilation:

warning: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
warning: 1 error generated.

error: failed to run custom build command for `secp256k1-sys v0.6.1`

Caused by:
  process didn't exit successfully: `/Users/kofiotuo/IdeaProjects/TESTING/target/debug/build/secp256k1-sys-c2d9d7632b759a2b/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("wasm32-unknown-unknown")
  OPT_LEVEL = Some("0")
  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=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
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  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=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
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/Users/kofiotuo/IdeaProjects/TESTING/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-7037fd93db318062/out/wasm/wasm.o" "-c" "wasm/wasm.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" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/Users/kofiotuo/IdeaProjects/TESTING/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-7037fd93db318062/out/wasm/wasm.o" "-c" "wasm/wasm.c" with args "clang" did not execute successfully (status code exit status: 1).


2023-05-20T09:09:42.763641Z ERROR ❌ error
error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: error during cargo build execution
    2: cargo call returned a bad status
Error: error from HTML pipeline

Caused by:
    0: error from asset pipeline
    1: error during cargo build execution
    2: cargo call returned a bad status

When I remove the substrate api client dependency, I don't face this error so it's save to assume this crate causes it.

@Kofituo
Copy link
Author

Kofituo commented May 20, 2023

After a lot of research, I was finally able to get it to work by first installing llvm with homebrew and then running
AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang trunk build
But I also had to use the sync-api feature since the default async doesn't work with wasm.
That said, I'm unable to use the Request trait in the master branch. I'll probably downgrade in the meantime so I'm able to use that functionality. Or I might fork this repo and modify that bit

@haerdib
Copy link
Contributor

haerdib commented May 22, 2023

@Niederb can you help here?

@Niederb
Copy link
Contributor

Niederb commented May 22, 2023

I will have a look

@Niederb
Copy link
Contributor

Niederb commented May 23, 2023

I tried to reproduce the issue on my machine but it compiled fine. I used the yew-trunk-minimal-template and added your dependencies (plus the sync/api feature). I would additional details to further look into this (Cargo.lock and rust toolchain version)
Regarding the Request trait: As you talk about downgrading I'm wondering if this worked previously for you? Because I don't think we had changes recently regarding the availability of the Request trait. In general the wasm support is still quite limited. See #513

@haerdib haerdib added the Z6-question Further information is requested label May 23, 2023
@Kofituo
Copy link
Author

Kofituo commented May 23, 2023

I think the error had to do with M1 macs. But I got that fixed using the method I explained earlier.
And about downgrading, I realised previous versions of this repository made the the Request trait available to all features instead of just the async feature so I wanted to downgrade to try it out. But that also didn't work - it came with difficulty trying to implement the Index and FrameSystemConfig trait and so on.

For now, I've defaulted to using subxt. That seems to work fine so far.

@Niederb
Copy link
Contributor

Niederb commented May 24, 2023

The Request trait should be available for sync and async. Maybe the sync-api feature was not active when you tested it?

@Kofituo
Copy link
Author

Kofituo commented May 26, 2023

I might have to look into that again to confirm.

@masapr
Copy link
Collaborator

masapr commented Jun 20, 2023

Hi @Kofituo, could you look into this issue? Can we close it?

@Kofituo
Copy link
Author

Kofituo commented Jun 23, 2023

Yes. It's resolved now

@Kofituo Kofituo closed this as completed Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z6-question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants