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

build: target wasm32-unknown-unknown failed on 0.11.0-beta.1 #66

Closed
shuimuliang opened this issue Dec 6, 2023 · 6 comments · Fixed by #72
Closed

build: target wasm32-unknown-unknown failed on 0.11.0-beta.1 #66

shuimuliang opened this issue Dec 6, 2023 · 6 comments · Fixed by #72
Assignees
Milestone

Comments

@shuimuliang
Copy link

cargo new demo

  1. for v0.10.11

Cargo.toml

[dependencies]
bp-core = { version = "0.10.11" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
rand = { version = "0.8.4", optional = true }
getrandom = { version = "0.2", features = ["js"] }
cargo build --target wasm32-unknown-unknown
Finished dev [unoptimized + debuginfo] target(s) in 9.02s
  1. for v.0.11.0-beta.1

Cargo.toml

[dependencies]
bp-core = { version = "~0.11.0-beta.1" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
rand = { version = "0.8.4", optional = true }
getrandom = { version = "0.2", features = ["js"] }
cargo build --target wasm32-unknown-unknown
    Updating crates.io index
   Compiling secp256k1-sys v0.9.0
   Compiling single_use_seals v0.11.0-beta.1
   Compiling commit_verify v0.11.0-beta.1
The following warnings were emitted during compilation:

warning: In file included from depend/secp256k1/src/precomputed_ecmult_gen.c:3:
warning: In file included from depend/secp256k1/src/group.h:10:
warning: In file included from depend/secp256k1/src/field.h:10:
warning: depend/secp256k1/src/util.h:32:5: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning:    32 |     printf("{");
warning:       |     ^
warning: depend/secp256k1/src/util.h:32:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
warning: depend/secp256k1/src/util.h:150:17: error: call to undeclared library function 'malloc' with type 'void *(unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning:   150 |     void *ret = malloc(size);
warning:       |                 ^
warning: depend/secp256k1/src/util.h:150:17: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
warning: 2 errors generated.
warning: In file included from depend/secp256k1/src/precomputed_ecmult_gen.c:3:
warning: In file included from depend/secp256k1/src/group.h:10:
warning: In file included from depend/secp256k1/src/field.h:10:
warning: depend/secp256k1/src/util.h:32:5: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning:    32 |     printf("{");
warning:       |     ^
warning: depend/secp256k1/src/util.h:32:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
warning: depend/secp256k1/src/util.h:150:17: error: call to undeclared library function 'malloc' with type 'void *(unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning:   150 |     void *ret = malloc(size);
warning:       |                 ^
warning: depend/secp256k1/src/util.h:150:17: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
warning: 2 errors generated.

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

Caused by:
  process didn't exit successfully: `/private/tmp/m2/target/debug/build/secp256k1-sys-4a891837fe0332c7/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=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
  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
  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" "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" "-DENABLE_MODULE_ELLSWIFT=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-o" "/private/tmp/m2/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-3d2166817edfbebd/out/wasm/wasm.o" "-c" "wasm/wasm.c"
  exit status: 0
  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" "-DENABLE_MODULE_ELLSWIFT=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-o" "/private/tmp/m2/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-3d2166817edfbebd/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"
  exit status: 0
  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" "-DENABLE_MODULE_ELLSWIFT=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-o" "/private/tmp/m2/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-3d2166817edfbebd/out/depend/secp256k1/src/precomputed_ecmult_gen.o" "-c" "depend/secp256k1/src/precomputed_ecmult_gen.c"
  cargo:warning=In file included from depend/secp256k1/src/precomputed_ecmult_gen.c:3:

  cargo:warning=In file included from depend/secp256k1/src/group.h:10:

  cargo:warning=In file included from depend/secp256k1/src/field.h:10:

  cargo:warning=depend/secp256k1/src/util.h:32:5: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

  cargo:warning=   32 |     printf("{");

  cargo:warning=      |     ^

  cargo:warning=depend/secp256k1/src/util.h:32:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'

  cargo:warning=depend/secp256k1/src/util.h:150:17: error: call to undeclared library function 'malloc' with type 'void *(unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

  cargo:warning=  150 |     void *ret = malloc(size);

  cargo:warning=      |                 ^

  cargo:warning=depend/secp256k1/src/util.h:150:17: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'

  cargo:warning=2 errors generated.

  exit status: 1
  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" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DENABLE_MODULE_ELLSWIFT=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-o" "/private/tmp/m2/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-3d2166817edfbebd/out/wasm/wasm.o" "-c" "wasm/wasm.c"
  exit status: 0
  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" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DENABLE_MODULE_ELLSWIFT=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-o" "/private/tmp/m2/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-3d2166817edfbebd/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"
  exit status: 0
  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" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DENABLE_MODULE_ELLSWIFT=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-o" "/private/tmp/m2/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-3d2166817edfbebd/out/depend/secp256k1/src/precomputed_ecmult_gen.o" "-c" "depend/secp256k1/src/precomputed_ecmult_gen.c"
  cargo:warning=In file included from depend/secp256k1/src/precomputed_ecmult_gen.c:3:

  cargo:warning=In file included from depend/secp256k1/src/group.h:10:

  cargo:warning=In file included from depend/secp256k1/src/field.h:10:

  cargo:warning=depend/secp256k1/src/util.h:32:5: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

  cargo:warning=   32 |     printf("{");

  cargo:warning=      |     ^

  cargo:warning=depend/secp256k1/src/util.h:32:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'

  cargo:warning=depend/secp256k1/src/util.h:150:17: error: call to undeclared library function 'malloc' with type 'void *(unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

  cargo:warning=  150 |     void *ret = malloc(size);

  cargo:warning=      |                 ^

  cargo:warning=depend/secp256k1/src/util.h:150:17: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'

  cargo:warning=2 errors 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" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DENABLE_MODULE_ELLSWIFT=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-o" "/private/tmp/m2/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-3d2166817edfbebd/out/depend/secp256k1/src/precomputed_ecmult_gen.o" "-c" "depend/secp256k1/src/precomputed_ecmult_gen.c" with args "clang" did not execute successfully (status code exit status: 1).


warning: build failed, waiting for other jobs to finish...
@shuimuliang
Copy link
Author

shuimuliang commented Dec 6, 2023

in bp-core
Cargo.toml
if secp256k1 = { version = "0.27.0", features = ["global-context"] }
it works.
if secp256k1 = { version = "0.28.0", features = ["global-context"] }
it failed.

@shuimuliang
Copy link
Author

rust-bitcoin/rust-secp256k1@023d50b
Merge rust-bitcoin/rust-secp256k1#663: Patch out any instances of printf in upstream
.define("printf(...)", Some(""));

               .include("depend/secp256k1/include")
               .include("depend/secp256k1/src")
               .flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
               .flag_if_supported("-Wno-unused-parameter") // patching out printf causes this warning
               .define("SECP256K1_API", Some(""))
               .define("ENABLE_MODULE_ECDH", Some("1"))
               .define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
               .define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
               .define("ENABLE_MODULE_ELLSWIFT", Some("1"));
               .define("ENABLE_MODULE_ELLSWIFT", Some("1"))
               // upstream sometimes introduces calls to printf, which we cannot compile
               // with WASM due to its lack of libc. printf is never necessary and we can
               // just #define it away.
               .define("printf(...)", Some(""));

@shuimuliang
Copy link
Author

shuimuliang commented Dec 6, 2023

temp solution

Patch the secp256k1 crate with the latest version, or publish secp256k1 with a new version v0.28.1

bp-core = { version = "~0.11.0-beta.1" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
rand = { version = "0.8.4", optional = true }
getrandom = { version = "0.2", features = ["js"] }

[patch.crates-io]
secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1/", features = ["alloc"]}

The chain of crates being called:
https://github.com/RGB-WG/rgb-core, Cargo.toml, bp-core = { version = "~0.11.0-beta.1" }
->
https://github.com/BP-WG/bp-core, Cargo.toml, secp256k1 = { version = "0.28.0", features = ["global-context"] }

@dr-orlovsky
Copy link
Member

Thank you for the investigation. It seems to be an upstream issue. Is it filed in rust-secp256k1 repo?

@shuimuliang
Copy link
Author

will do.

@dr-orlovsky
Copy link
Member

Fixed in #72

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

Successfully merging a pull request may close this issue.

2 participants