Open thomas725 opened 11 months ago
Hi! First up, targeting powerpc-unknown-linux-gnu
is getting trickier since it's deprecated and not supported by Ubuntu for libncurses-dev
. Instead, you should probably use powerpc64le-unknown-linux-gnu
The main issue you're encountering stems from cross
running in a container that doesnt include libncurses-dev
. Installing it on your local system won't affect this isolated container.
To fix this, you'll want to set up a Cross.toml
file in your project directory and add:
# Cross.toml
[build]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get install --assume-yes libncurses-dev:$CROSS_DEB_ARCH"
]
This will install the necessary library in the container for whichever target you're using, see [build]
and Linking external libraries
. That should make cross run --target powerpc64le-unknown-linux-gnu
and cross run --target x86_64-unknown-linux-gnu
work just fine.
As for powerpc-unknown-linux-gnu
, your options are:
jessie
repo to obtain the library. The wiki has more details./usr/powerpc-linux-gnu/lib
.powerpc64le-unknown-linux-gnu
.If you have more questions, feel free to ask.
Thanks for the detailed explanation and the clear guide how to proceed, will try it next!
I'm unsure if powerpc64le is the right architecture for my target system, it's an OpenWRT device with a Freescale MPC85xx P1014 SoC, which I believe is a 32bit PowerPC architecture, but I'm not sure. I'll try with powerpc64le-unknown-linux-gnu in a few hours and report back on my results afterwards :)
Okey, so first result, the ncurses.h not found vanished, but it still fails, but I don't understand what the new error is trying to say:
$ cross build --release --target powerpc64le-unknown-linux-gnu
...
error: failed to run custom build command for `ncurses v5.101.0`
Caused by:
process didn't exit successfully: `/target/release/build/ncurses-3b76e5da4c5551fd/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=NCURSESW5_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_powerpc64le_unknown_linux_gnu
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_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=NCURSESW5_STATIC
cargo:rerun-if-env-changed=NCURSESW5_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=NCURSESW_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_powerpc64le_unknown_linux_gnu
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_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=NCURSESW_STATIC
cargo:rerun-if-env-changed=NCURSESW_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=SYSROOT
cargo:rerun-if-env-changed=NCURSESW_STATIC
cargo:rerun-if-env-changed=NCURSESW_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rustc-link-lib=ncursesw
cargo:rustc-link-lib=tinfo
cargo:rustc-link-arg=-Wl,-Bsymbolic-functions
cargo:rerun-if-env-changed=PKG_CONFIG_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=NCURSESW_STATIC
cargo:rerun-if-env-changed=NCURSESW_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_powerpc64le-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_powerpc64le_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
OPT_LEVEL = Some("z")
TARGET = Some("powerpc64le-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
cargo:rerun-if-env-changed=CC_powerpc64le-unknown-linux-gnu
CC_powerpc64le-unknown-linux-gnu = None
cargo:rerun-if-env-changed=CC_powerpc64le_unknown_linux_gnu
CC_powerpc64le_unknown_linux_gnu = Some("powerpc64le-linux-gnu-gcc")
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = None
cargo:rerun-if-env-changed=CFLAGS_powerpc64le-unknown-linux-gnu
CFLAGS_powerpc64le-unknown-linux-gnu = None
cargo:rerun-if-env-changed=CFLAGS_powerpc64le_unknown_linux_gnu
CFLAGS_powerpc64le_unknown_linux_gnu = None
cargo:rerun-if-env-changed=TARGET_CFLAGS
TARGET_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
--- stderr
thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ncurses-5.101.0/build.rs:107:10:
/target/powerpc64le-unknown-linux-gnu/release/build/ncurses-e10af3e277872a3d/out/chtype_size failed: Os { code: 8, kind: Uncategorized, message: "Exec format error" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
okey, so next I've tried this:
CROSS_CONTAINER_ENGINE=podman cross build --target x86_64-unknown-linux-gnu --release
which worked fine. So my problems are related to the lesser used cpu architecture targets...
okey, so now I found that if I replace my code which was the most basic sample from the Cursive CUI library with a simple println!("hello")
(and removing the Cursive dependency) I can compile it just fine using cross build --release --target powerpc-unknown-linux-gnu
.
So the problem seem to be specific to ncurses (or it's dependencies?) which are used by the Cursive CUI library when compiling for a powerpc archetecture.
okey, but copying the resulting binary to my openwrt device and running it there doesn't print the string passed to the println macro, but instead:
-ash: rust-p2p-chat_ppc: not found
ah, so after reading this: https://stackoverflow.com/questions/31385121/elf-file-exists-in-usr-bin-but-turns-out-ash-file-not-found
I believe I got differing versions of libc between the build container and the openwrt device, and the build has dynamically linked to that libc present during building.
OpenWRT:
$ opkg list-installed | grep libc
libc - 1.2.3-4
The error you're getting when building ncurses is the same as https://github.com/jeaye/ncurses-rs/issues/184
I'd say what ncurses-rs is doing here is a bit iffy. It compiles using the target cc, and tries to run it.It does then seem like this is not a cross issue, but a general cross-compilation issue for the ncurses crate.
I do know a way to fix this for users of cross (and more) maybe, utilize the runner thats been specified here. Ill see if i can get a fix up for that crate.
Also, you are correct, MPC8540 is powerpc, not ppc64el
There we go, adding
[patch.crates-io]
ncurses = { git = "https://github.com/Emilgardis/ncurses-rs", branch = "fix-runner" }
should fix the issue. Interestingly, I couldn't reproduce the exec error on windows, not sure why :3
as for powerpc, I'm not able to use debian ports nor jessie to install libncurses-dev, something in the repo is fundamentally broken. I'm not sure how to proceed except for maybe to not use ncurses and instead use something rust native like ratatui
wow, amazing how much effort you put into solving anonymous peoples problems, thank you for being an amazing human beeing ❤️
For getting to a running binary faster I already downgraded my sample from using Cursive (CUI lib) which is using ncurses, to a only std rust using prtinln!("hello world") - but still failed because of the very old libc version on my OpenWRT router.
Can you help me with that also? Should I create a separate issue for this? I've so far documented my research on that problem here: https://users.rust-lang.org/t/compile-rust-for-powerpc-openwrt-device-with-libc-1-2-3/101147/
Checklist
Describe your issue
I tried building my almost empty Rust + Cursive playground application, and failed:
This error says I'm missng ncurses.h, but I'm not:
What target(s) are you cross-compiling for?
powerpc-unknown-linux-gnu
Which operating system is the host (e.g computer cross is on) running?
What architecture is the host?
What container engine is cross using?
cross version
cross 0.2.5 (3c21f9e 2023-10-11)
Example
Gives the error message
/target/x86_64-unknown-linux-gnu/release/build/ncurses-e7af6b71caf2e572/out/chtype_size.c:6:10: fatal error: ncurses.h: No such file or directory
Additional information / notes
The normal
cargo build --release
works fine.