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

Consistently getting compilation error when compiling to wasm32 #660

Closed
cryptoquick opened this issue Oct 31, 2023 · 10 comments · Fixed by #663
Closed

Consistently getting compilation error when compiling to wasm32 #660

cryptoquick opened this issue Oct 31, 2023 · 10 comments · Fixed by #663

Comments

@cryptoquick
Copy link

Error log:

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:     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:     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:     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:     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: `/home/hunter/Projects/diba/bitmask-core/target/release/build/secp256k1-sys-0a4816c08568de6a/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("wasm32-unknown-unknown")
  OPT_LEVEL = Some("3")
  HOST = Some("x86_64-unknown-linux-gnu")
  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("false")
  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" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--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" "/home/hunter/Projects/diba/bitmask-core/target/wasm32-unknown-unknown/release/build/secp256k1-sys-9b02d0dd0903a28a/out/wasm/wasm.o" "-c" "wasm/wasm.c"
  exit status: 0
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--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" "/home/hunter/Projects/diba/bitmask-core/target/wasm32-unknown-unknown/release/build/secp256k1-sys-9b02d0dd0903a28a/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"
  exit status: 0
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--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" "/home/hunter/Projects/diba/bitmask-core/target/wasm32-unknown-unknown/release/build/secp256k1-sys-9b02d0dd0903a28a/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=    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=    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" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--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" "/home/hunter/Projects/diba/bitmask-core/target/wasm32-unknown-unknown/release/build/secp256k1-sys-9b02d0dd0903a28a/out/wasm/wasm.o" "-c" "wasm/wasm.c"
  exit status: 0
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--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" "/home/hunter/Projects/diba/bitmask-core/target/wasm32-unknown-unknown/release/build/secp256k1-sys-9b02d0dd0903a28a/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"
  exit status: 0
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--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" "/home/hunter/Projects/diba/bitmask-core/target/wasm32-unknown-unknown/release/build/secp256k1-sys-9b02d0dd0903a28a/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=    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=    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" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--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" "/home/hunter/Projects/diba/bitmask-core/target/wasm32-unknown-unknown/release/build/secp256k1-sys-9b02d0dd0903a28a/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).
@dpc
Copy link
Contributor

dpc commented Oct 31, 2023

Compiling C deps in Rust projects is a source of continuous problems, as it depends on the host system.

At minimum debugging this requires capturing the exact OS version, and specifically clang versions being used.

My recommendation would be to invest in Nix development shell to ensure developers and build machines always use desired and tested versions. We use it at Fedimint, BDK is moving to Nix dev shells and CI
. I particular I have a project: Flakebox which is what we've extracted from and now use for Fedimint and among many thing is auto-configures toolchains for native builds and cross-compilation to wasm, android and partially) iOS.

@cryptoquick
Copy link
Author

Perhaps, but that's not going to work for us in the short term with our tight deadlines. For now I've just downgraded to 0.27.0 and that resolved the issue.

For others who might be running into this:

cargo update -p [email protected] --precise 0.27.0

@cryptoquick
Copy link
Author

cryptoquick commented Oct 31, 2023

I'm running Garuda Linux, an Arch derivative... uname -a:

Linux hephaestus 6.5.9-zen2-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 26 Oct 2023 00:51:53 +0000 x86_64 GNU/Linux

clang -v:

clang version 16.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/13.2.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found HIP installation: /opt/rocm, version 5.6.31062

wasm-pack --version:

wasm-pack 0.12.1

@dpc
Copy link
Contributor

dpc commented Oct 31, 2023

OK. In that case it might be something that [email protected] introduced. Checked and we're at "0.27".

@apoelstra
Copy link
Member

I'll bet upstream introduced a new instance of printf. I'll look into this.

@apoelstra
Copy link
Member

It looks like there is a new PRINT_BUF macro and print_buf_plain function that we should remove. It's a static function and not called anywhere, so it's a little frustrating that it's causing issues like this. But ok, that will make it easy to delete.

@Kixunil
Copy link
Collaborator

Kixunil commented Nov 1, 2023

Can't we just #define printf(x...)?

@apoelstra
Copy link
Member

@Kixunil ooh, that's a cool idea. Let me audit the other code that we're patching out to see if it'd be sufficient to just #define them away. (Our current patches outright delete them, so I know they're not called, but nonetheless with things like malloc we might need to be careful about stubbing them away.)

@apoelstra
Copy link
Member

@Kixunil so, the existing patch-out-function code can't be replaced by this, because the functions that we patch out are replaced by pure Rust code. But I think this particular issue should be resolvable by just defining away printf.

@cryptoquick
Copy link
Author

Can confirm this is resolved by the latest PR into master.

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

Successfully merging a pull request may close this issue.

4 participants