rust-bitcoin / rust-secp256k1

Rust language bindings for Bitcoin secp256k1 library.
Creative Commons Zero v1.0 Universal
351 stars 270 forks source link

secp256k1-sys cannot be cross compiled using rust cross. #734

Closed KernelPanic0 closed 2 months ago

KernelPanic0 commented 2 months ago

I am trying to cross compile a rust application from Ubuntu to a Windows machine. With podman installed, I run the following: cross build --release --target x86_64-pc-windows-msvc Everything is fine, up until the compiler reaches the secp256k1-sys crate.

   Compiling same-file v1.0.6
The following warnings were emitted during compilation:

warning: secp256k1-sys@0.10.0: GNU compiler is not supported for this target
warning: secp256k1-sys@0.10.0: GNU compiler is not supported for this target
warning: secp256k1-sys@0.10.0: In file included from /usr/include/stdio.h:894,
warning: secp256k1-sys@0.10.0:                  from depend/secp256k1/src/util.h:14,
warning: secp256k1-sys@0.10.0:                  from depend/secp256k1/src/field.h:10,
warning: secp256k1-sys@0.10.0:                  from depend/secp256k1/src/group.h:10,
warning: secp256k1-sys@0.10.0:                  from depend/secp256k1/src/precomputed_ecmult_gen.c:3:
warning: secp256k1-sys@0.10.0: /usr/include/x86_64-linux-gnu/bits/stdio2.h:111:1: error: expected identifier or ‘(’ before ‘{’ token
warning: secp256k1-sys@0.10.0:   111 | {
warning: secp256k1-sys@0.10.0:       | ^
warning: secp256k1-sys@0.10.0: GNU compiler is not supported for this target
warning: secp256k1-sys@0.10.0: GNU compiler is not supported for this target
warning: secp256k1-sys@0.10.0: GNU compiler is not supported for this target
warning: secp256k1-sys@0.10.0: GNU compiler is not supported for this target
warning: secp256k1-sys@0.10.0: GNU compiler is not supported for this target

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

Caused by:
  process didn't exit successfully: `/var/www/Kraken/target/release/build/secp256k1-sys-af278a91dc73c6d7/build-script-build` (exit status: 1)
  --- stdout
  OUT_DIR = Some(/var/www/Kraken/target/x86_64-pc-windows-msvc/release/build/secp256k1-sys-6b3c23eb15e9fc2b/out)
  TARGET = Some(x86_64-pc-windows-msvc)
  OPT_LEVEL = Some(3)
  HOST = Some(x86_64-unknown-linux-gnu)
  cargo:rerun-if-env-changed=VCINSTALLDIR
  VCINSTALLDIR = None
  cargo:rerun-if-env-changed=CC_x86_64-pc-windows-msvc
  CC_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CC_x86_64_pc_windows_msvc
  CC_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  RUSTC_LINKER = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  RUSTC_WRAPPER = None
  cargo:warning=GNU compiler is not supported for this target
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some(false)
  CARGO_CFG_TARGET_FEATURE = Some(cmpxchg16b,fxsr,sse,sse2,sse3)
  cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc
  CFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc
  CFLAGS_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  OUT_DIR = Some(/var/www/Kraken/target/x86_64-pc-windows-msvc/release/build/secp256k1-sys-6b3c23eb15e9fc2b/out)
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some(cmpxchg16b,fxsr,sse,sse2,sse3)
  cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc
  CFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc
  CFLAGS_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  OUT_DIR = Some(/var/www/Kraken/target/x86_64-pc-windows-msvc/release/build/secp256k1-sys-6b3c23eb15e9fc2b/out)
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some(cmpxchg16b,fxsr,sse,sse2,sse3)
  cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc
  CFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc
  CFLAGS_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:warning=GNU compiler is not supported for this target
  cargo:warning=In file included from /usr/include/stdio.h:894,
  cargo:warning=                 from depend/secp256k1/src/util.h:14,
  cargo:warning=                 from depend/secp256k1/src/field.h:10,
  cargo:warning=                 from depend/secp256k1/src/group.h:10,
  cargo:warning=                 from depend/secp256k1/src/precomputed_ecmult_gen.c:3:
  cargo:warning=/usr/include/x86_64-linux-gnu/bits/stdio2.h:111:1: error: expected identifier or ‘(’ before ‘{’ token
  cargo:warning=  111 | {
  cargo:warning=      | ^
  cargo:warning=GNU compiler is not supported for this target
  cargo:warning=GNU compiler is not supported for this target
  cargo:warning=GNU compiler is not supported for this target
  cargo:warning=GNU compiler is not supported for this target
  cargo:rerun-if-env-changed=AR_x86_64-pc-windows-msvc
  AR_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=AR_x86_64_pc_windows_msvc
  AR_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=TARGET_AR
  TARGET_AR = None
  cargo:rerun-if-env-changed=AR
  AR = None
  cargo:warning=GNU compiler is not supported for this target
  cargo:rerun-if-env-changed=ARFLAGS_x86_64-pc-windows-msvc
  ARFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=ARFLAGS_x86_64_pc_windows_msvc
  ARFLAGS_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=TARGET_ARFLAGS
  TARGET_ARFLAGS = None
  cargo:rerun-if-env-changed=ARFLAGS
  ARFLAGS = None

  --- stderr

  error occurred: Failed to find tool. Is `lib.exe` installed?

Am I missing something obivous?

apoelstra commented 2 months ago

We should add a patch which drops that stdio.h code. It's totally dead, so I guess the compilers we test on filter it out early enough that it doesn't cause problems, but it shouldn't be there.

I'll PR to delete that code, and backport to 0.10.0 which should hopefully fix your issue.

Having said that, the problem is in your copy of stdio.h so I feel I should say "not our fault" :).

Kixunil commented 2 months ago

Having said that, the problem is in your copy of stdio.h so I feel I should say "not our fault" :).

I agree. Most of our build issues are either bug in cc or wrong C compiler and I'd rather not pollute our code with special exceptions to fix these. (I believe there's a way to print a message "please check your compiler before filing an issue" on build failure.)

That being said, if we can easily delete dead code and it's likely to improve reliability on multiple targets then I don't object to it.

apoelstra commented 2 months ago

@Kixunil in this case we are already trying to eliminate all calls into the C standard library because they don't need them and they break wasm (at runtime).

So deleting this code is totally within the normal goals of this crate ... it's just that fixing this particular bug is not something we'd be willing to take too many pains to fix. (But fortunately it turns out to be zero marginal pain because we want to delete the code anyway.)