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

Cross-compilation assistance: Env vars not set when targeting x86_64_unknown_linux_musl from Linux #726

Closed
edmorley opened this issue Nov 9, 2023 · 0 comments · Fixed by #769
Assignees
Labels
bug Something isn't working libcnb-package

Comments

@edmorley
Copy link
Member

edmorley commented Nov 9, 2023

Currently the cross-compile assistance does not set any env vars in this branch:

} else if target_triple.as_ref() == X86_64_UNKNOWN_LINUX_MUSL && cfg!(target_os = "linux") {
match which("musl-gcc") {
Ok(_) => CrossCompileAssistance::Configuration {
cargo_env: Vec::new(),
},

Whilst some compiles will succeed with that implementation (since Rust will automatically use musl-gcc if it's found), it breaks when cross-compiling for a different architecture.

All musl-gcc does is compile using musl rather than glibc, using the same architecture as the host. (As opposed to the wrappers like x86_64-unknown-linux-musl which also target the different architecture.)

In addition, since none of the CC_* type env vars are set, if the buildpack uses any Rust dependencies that contain C components (such as the ring crate used for TLS), then the build will fail like so:

The following warnings were emitted during compilation:

warning: cc1: error: unrecognized command-line option '-m64'

error: failed to run custom build command for `libz-sys v1.1.12`

Caused by:
  process didn't exit successfully: `/buildpacks-python/target/debug/build/libz-sys-bfd25c9fd11b1325/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=LIBZ_SYS_STATIC
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-env-changed=ZLIB_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo-warning=pkg-config has not been configured to support cross-compilation.

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.
  TARGET = Some("x86_64-unknown-linux-musl")
  OPT_LEVEL = Some("0")
  HOST = Some("aarch64-unknown-linux-gnu")
  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 = None
  cargo:rerun-if-env-changed=CC
  CC = None
  RUSTC_LINKER = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  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: "musl-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/zlib" "-fvisibility=hidden" "-DZ_SOLO" "-DSTDC" "-D_LARGEFILE64_SOURCE" "-D_POSIX_SOURCE" "-o" "/buildpacks-python/target/x86_64-unknown-linux-musl/debug/build/libz-sys-672d486ba2008913/out/lib/src/zlib/adler32.o" "-c" "src/zlib/adler32.c"
  cargo:warning=cc1: error: unrecognized command-line option '-m64'

  exit status: 1

  --- stderr


  error occurred: Command "musl-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/zlib" "-fvisibility=hidden" "-DZ_SOLO" "-DSTDC" "-D_LARGEFILE64_SOURCE" "-D_POSIX_SOURCE" "-o" "/buildpacks-python/target/x86_64-unknown-linux-musl/debug/build/libz-sys-672d486ba2008913/out/lib/src/zlib/adler32.o" "-c" "src/zlib/adler32.c" with args "musl-gcc" did not execute successfully (status code exit status: 1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libcnb-package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants