FiloSottile / homebrew-musl-cross

Homebrew Formula for static-friendly musl-based GCC macOS-to-Linux cross-compilers

Home Page:https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

x86_64-unknown-linux-musl: not found

Dmdv opened this issue · comments

commented

I've installed brew install filosottile/musl-cross/musl-cross on M1
But still have same issues

I have the following dockerfile

FROM rust:latest as builder

RUN rustup target add x86_64-unknown-linux-musl

RUN apt -y update
RUN apt install -y musl-tools musl-dev
RUN apt install -y pkg-config libssl-dev
RUN apt install -y build-essential

RUN update-ca-certificates

WORKDIR /app
COPY ./ .

# For a musl build on M1 Mac these ENV variables have to be set
ENV RUSTFLAGS='-C linker=x86_64-unknown-linux-musl'
ENV CC='gcc'
ENV CC_x86_64_unknown_linux_musl=x86_64-unknown-linux-musl
ENV CC_x86_64-unknown-linux-musl=x86_64-unknown-linux-musl

RUN cargo build --target x86_64-unknown-linux-musl --release

#FROM gcr.io/distroless/cc
FROM scratch

WORKDIR /app

COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/rebot ./

CMD ["/app/rebot"]

and the Cargo.toml

[package]
name = "rebot"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "rebot"
path = "src/main.rs"

[profile.release]
lto = true
codegen-units = 1
strip = true

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"

[target.x86_64-unknown-linux-gnu]
linker = "x86_64-unknown-linux-gnu-gcc"

[dependencies]
teloxide = { version = "0.12.2", features = ["macros"] }
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"]}
log = "0.4"
pretty_env_logger = "0.4"
rand = "0.8.5"
dptree = "0.3.0"
openssl-sys = "0.9.82"
openssl = { version = "0.10.47", features = ["vendored"] }
#openssl = "0.10.47"

[dev-dependencies]
tracing-subscriber = "0.3.16"

output:

#15 147.0 error: failed to run custom build command for `openssl-sys v0.9.82`
#15 147.0
#15 147.0 Caused by:
#15 147.0   process didn't exit successfully: `/app/target/release/build/openssl-sys-8c478482b3038f24/build-script-main` (exit status: 101)
#15 147.0   --- stdout
#15 147.0   cargo:rustc-cfg=const_fn
#15 147.0   cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_NO_VENDOR
#15 147.0   X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_NO_VENDOR unset
#15 147.0   cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
#15 147.0   OPENSSL_NO_VENDOR unset
#15 147.0   cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-musl
#15 147.0   CC_x86_64-unknown-linux-musl = None
#15 147.0   cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_musl
#15 147.0   CC_x86_64_unknown_linux_musl = Some("x86_64-unknown-linux-musl")
#15 147.0   cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-musl
#15 147.0   CFLAGS_x86_64-unknown-linux-musl = None
#15 147.0   cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_musl
#15 147.0   CFLAGS_x86_64_unknown_linux_musl = None
#15 147.0   cargo:rerun-if-env-changed=TARGET_CFLAGS
#15 147.0   TARGET_CFLAGS = None
#15 147.0   cargo:rerun-if-env-changed=CFLAGS
#15 147.0   CFLAGS = None
#15 147.0   cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
#15 147.0   CRATE_CC_NO_DEFAULTS = None
#15 147.0   DEBUG = Some("false")
#15 147.0   CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
#15 147.0   cargo:rerun-if-env-changed=AR_x86_64-unknown-linux-musl
#15 147.0   AR_x86_64-unknown-linux-musl = None
#15 147.0   cargo:rerun-if-env-changed=AR_x86_64_unknown_linux_musl
#15 147.0   AR_x86_64_unknown_linux_musl = None
#15 147.0   cargo:rerun-if-env-changed=TARGET_AR
#15 147.0   TARGET_AR = None
#15 147.0   cargo:rerun-if-env-changed=AR
#15 147.0   AR = None
#15 147.0   RUSTC_LINKER = None
#15 147.0   cargo:rerun-if-env-changed=CROSS_COMPILE
#15 147.0   CROSS_COMPILE = None
#15 147.0   cargo:rerun-if-env-changed=ARFLAGS_x86_64-unknown-linux-musl
#15 147.0   ARFLAGS_x86_64-unknown-linux-musl = None
#15 147.0   cargo:rerun-if-env-changed=ARFLAGS_x86_64_unknown_linux_musl
#15 147.0   ARFLAGS_x86_64_unknown_linux_musl = None
#15 147.0   cargo:rerun-if-env-changed=TARGET_ARFLAGS
#15 147.0   TARGET_ARFLAGS = None
#15 147.0   cargo:rerun-if-env-changed=ARFLAGS
#15 147.0   ARFLAGS = None
#15 147.0   cargo:rerun-if-env-changed=RANLIB_x86_64-unknown-linux-musl
#15 147.0   RANLIB_x86_64-unknown-linux-musl = None
#15 147.0   cargo:rerun-if-env-changed=RANLIB_x86_64_unknown_linux_musl
#15 147.0   RANLIB_x86_64_unknown_linux_musl = None
#15 147.0   cargo:rerun-if-env-changed=TARGET_RANLIB
#15 147.0   TARGET_RANLIB = None
#15 147.0   cargo:rerun-if-env-changed=RANLIB
#15 147.0   RANLIB = None
#15 147.0   cargo:rerun-if-env-changed=RANLIBFLAGS_x86_64-unknown-linux-musl
#15 147.0   RANLIBFLAGS_x86_64-unknown-linux-musl = None
#15 147.0   cargo:rerun-if-env-changed=RANLIBFLAGS_x86_64_unknown_linux_musl
#15 147.0   RANLIBFLAGS_x86_64_unknown_linux_musl = None
#15 147.0   cargo:rerun-if-env-changed=TARGET_RANLIBFLAGS
#15 147.0   TARGET_RANLIBFLAGS = None
#15 147.0   cargo:rerun-if-env-changed=RANLIBFLAGS
#15 147.0   RANLIBFLAGS = None
#15 147.0   running cd "/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src" && AR="ar" CC="x86_64-unknown-linux-musl" RANLIB="ranlib" "perl" "./Configure" "--prefix=/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/install" "--openssldir=/usr/local/ssl" "no-dso" "no-shared" "no-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-engine" "no-async" "linux-x86_64" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-DOPENSSL_NO_SECURE_MEMORY"
#15 147.0   Configuring OpenSSL version 1.1.1t (0x1010114fL) for linux-x86_64
#15 147.0   Using os-specific seed configuration
#15 147.0   Creating configdata.pm
#15 147.0   Creating Makefile
#15 147.0
#15 147.0   **********************************************************************
#15 147.0   ***                                                                ***
#15 147.0   ***   OpenSSL has been successfully configured                     ***
#15 147.0   ***                                                                ***
#15 147.0   ***   If you encounter a problem while building, please open an    ***
#15 147.0   ***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
#15 147.0   ***   and include the output from the following command:           ***
#15 147.0   ***                                                                ***
#15 147.0   ***       perl configdata.pm --dump                                ***
#15 147.0   ***                                                                ***
#15 147.0   ***   (If you are new to OpenSSL, you might want to consult the    ***
#15 147.0   ***   'Troubleshooting' section in the INSTALL file first)         ***
#15 147.0   ***                                                                ***
#15 147.0   **********************************************************************
#15 147.0   running cd "/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src" && "make" "depend"
#15 147.0   running cd "/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src" && MAKEFLAGS="-j --jobserver-fds=9,14 --jobserver-auth=9,14" "make" "build_libs"
#15 147.0   /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
#15 147.0       "-oMakefile" include/crypto/bn_conf.h.in > include/crypto/bn_conf.h
#15 147.0   /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
#15 147.0       "-oMakefile" include/crypto/dso_conf.h.in > include/crypto/dso_conf.h
#15 147.0   /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
#15 147.0       "-oMakefile" include/openssl/opensslconf.h.in > include/openssl/opensslconf.h
#15 147.0   make depend && make _build_libs
#15 147.0   make[1]: Entering directory '/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src'
#15 147.0   make[1]: Leaving directory '/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src'
#15 147.0   make[1]: Entering directory '/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src'
#15 147.0   x86_64-unknown-linux-musl  -I. -Iinclude -fPIC -pthread -m64 -Wall -O3 -O2 -ffunction-sections -fdata-sections -fPIC -m64 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/install/lib/engines-1.1\"" -DNDEBUG -DOPENSSL_NO_SECURE_MEMORY  -c -o apps/app_rand.o apps/app_rand.c
#15 147.0   make[1]: Leaving directory '/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src'
#15 147.0
#15 147.0   --- stderr
#15 147.0   /bin/sh: 1: x86_64-unknown-linux-musl: not found
#15 147.0   make[1]: *** [Makefile:671: apps/app_rand.o] Error 127
#15 147.0   make: *** [Makefile:175: build_libs] Error 2
#15 147.0   thread 'main' panicked at '
#15 147.0
#15 147.0
#15 147.0   Error building OpenSSL:
#15 147.0       Command: cd "/app/target/x86_64-unknown-linux-musl/release/build/openssl-sys-6ec6467337584455/out/openssl-build/build/src" && MAKEFLAGS="-j --jobserver-fds=9,14 --jobserver-auth=9,14" "make" "build_libs"
#15 147.0       Exit status: exit status: 2
#15 147.0
#15 147.0
#15 147.0       ', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/openssl-src-111.25.2+1.1.1t/src/lib.rs:505:13
#15 147.0   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
#15 147.0 warning: build failed, waiting for other jobs to finish...
------
executor failed running [/bin/sh -c cargo build --target x86_64-unknown-linux-musl --release]: exit code: 101

It looks like you installed musl-cross on macOS, not inside the Docker container.

Unfortunately, I can't offer support for how to use the cross-compiler once installed, because the array of build systems and configurations is too diverse.