ethereum / c-kzg-4844

A minimal implementation of the Polynomial Commitments API for EIP-4844 and EIP-7594, written in C.
Apache License 2.0
118 stars 109 forks source link

Rust binding can't cross compile on Apple Silicon #383

Closed alexlee85 closed 7 months ago

alexlee85 commented 12 months ago

can't cross complile on apple sillicon to x86_64-unknown-linux-musl error message is:

error: failed to run custom build command for `c-kzg v0.1.1`

Caused by:
  process didn't exit successfully: `/Users/alex/Sources/.../target/release/build/c-kzg-403929aca7b2a5f5/build-script-build` (exit status: 101)
  --- stdout
  TARGET = Some("x86_64-unknown-linux-musl")
  OPT_LEVEL = Some("3")
  HOST = Some("aarch64-apple-darwin")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-musl
  CC_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_musl
  CC_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = Some("x86_64-linux-musl-gcc")
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-musl
  CFLAGS_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_musl
  CFLAGS_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "/opt/homebrew/bin/sccache" "x86_64-linux-musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "/Users/alex/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/c-kzg-0.1.1/c-kzg-sys/blst/bindings" "-DLIB_PREFIX=ckzg" "-DFIELD_ELEMENTS_PER_BLOB=4096" "-o" "/Users/alex/Sources/.../target/x86_64-unknown-linux-musl/release/build/c-kzg-e2f31d1d25c1329b/out/80278201fb9c16c7-c_kzg_4844.o" "-c" "/Users/alex/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/c-kzg-0.1.1/c-kzg-sys/src/c_kzg_4844.c"
  exit status: 0
  cargo:rerun-if-env-changed=AR_x86_64-unknown-linux-musl
  AR_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=AR_x86_64_unknown_linux_musl
  AR_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=TARGET_AR
  TARGET_AR = None
  cargo:rerun-if-env-changed=AR
  AR = None
  RUSTC_LINKER = Some("x86_64-linux-musl-gcc")
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  cargo:rerun-if-env-changed=ARFLAGS_x86_64-unknown-linux-musl
  ARFLAGS_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=ARFLAGS_x86_64_unknown_linux_musl
  ARFLAGS_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=TARGET_ARFLAGS
  TARGET_ARFLAGS = None
  cargo:rerun-if-env-changed=ARFLAGS
  ARFLAGS = None
  running: ZERO_AR_DATE="1" "x86_64-linux-musl-ar" "cq" "/Users/alex/Sources/..../target/x86_64-unknown-linux-musl/release/build/c-kzg-e2f31d1d25c1329b/out/libckzg.a" "/Users/alex/Sources/..../target/x86_64-unknown-linux-musl/release/build/c-kzg-e2f31d1d25c1329b/out/80278201fb9c16c7-c_kzg_4844.o"
  exit status: 0
  running: "x86_64-linux-musl-ar" "s" "/Users/alex/Sources/..../target/x86_64-unknown-linux-musl/release/build/c-kzg-e2f31d1d25c1329b/out/libckzg.a"
  exit status: 0
  cargo:rustc-link-lib=static=ckzg
  cargo:rustc-link-search=native=/Users/alex/Sources/..../target/x86_64-unknown-linux-musl/release/build/c-kzg-e2f31d1d25c1329b/out
  cargo:rerun-if-env-changed=TARGET
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS

  --- stderr
  Using LIB_PREFIX=ckzg
  Using FIELD_ELEMENTS_PER_BLOB=4096
  /Users/alex/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/c-kzg-0.1.1/c-kzg-sys/src/c_kzg_4844.h:27:10: fatal error: 'stdio.h' file not found
  thread 'main' panicked at /Users/alex/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/c-kzg-0.1.1/build.rs:160:10:
  called `Result::unwrap()` on an `Err` value: ClangDiagnostic("/Users/alex/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/c-kzg-0.1.1/c-kzg-sys/src/c_kzg_4844.h:27:10: fatal error: 'stdio.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
jtraglia commented 12 months ago

Hi there. I think you're working on macOS with homebrew's musl-cross package.

I think the core issue is that the compiler doesn't know where this header file is:

fatal error: 'stdio.h' file not found

You will need to include the following headers somehow:

$(brew --prefix musl-cross)/libexec/x86_64-linux-musl/include

Lemme know if this helps. If you're still having problems I'll try it out for myself.

alexlee85 commented 12 months ago

I use revm crate in myproject, and c-kzg is a dependency of revm. yes, as you said, I use musl-cross at first, error happen, and then macos-cross-toolchains, error still there. finally I removed revm from my project depencencies, no error happpen again.

so I don't think the problem is like what you've said, because after remove revm, the whole project with other dependencies compiled successfully.

jtraglia commented 7 months ago

Hey @alexlee85 is this still an issue for you?