librespot-org / librespot

Open Source Spotify client library
MIT License
4.52k stars 545 forks source link

Can't successfully cross-compile `librespot` for arm-unknown-linux-musleabihf on ubuntu 22.04 #1184

Open BliemHax opened 1 year ago

BliemHax commented 1 year ago

Question: Can't successfully cross-compile ‘librespot’ for arm-unknown-linux-musleabihf on ubuntu 22.04.

Error Log on run cargo build:

......
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `stderr@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `nanosleep@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `setsockopt@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `__ctype_b_loc@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `getgrnam_r@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `sigaction@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `regcomp@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `semop@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `sigemptyset@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `connect@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `versionsort@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `regexec@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `waitpid@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `dladdr1@GLIBC_2.34'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `__sprintf_chk@GLIBC_2.4'
          /opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `__errno_location@GLIBC_2.4'
          collect2: error: ld returned 1 exit status

  = note: some extern functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the -l flag to specify native libraries to link
  = note: use the cargo:rustc-link-lib directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

cargo build Command:

RUSTFLAGS="-C link-args=-Wl,-rpath-link,/lib -C target-feature=-crt-static" PKG_CONFIG_PATH_arm_unknown_linux_musleabihf="/usr/lib/arm-linux-gnueabihf/pkgconfig" PKG_CONFIG_ALLOW_CROSS=1 cargo build --release --target arm-unknown-linux-musleabihf

Full Log:

https://pastebin.com/yU2UTiK1

Environment:

Action that I did:

  1. Install the rustup with the Chinese mirror server (run as root):

    export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
    export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
    curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
  2. Downloaded the musl compilation toolchain from musl.cc, version cross arm-linux-musleabihf, and added the toolchain path to the PATH: https://musl.cc/arm-linux-musleabihf-cross.tgz PATH is: /opt/arm-linux-musleabihf/bin

  3. Add armhf support to dpkg and change armhf software source to "China Tsinghua University open source software mirror":

    
    /etc/apt/sources.list

deb cdrom:[Ubuntu 22.04.2 LTS Jammy Jellyfish - Release amd64 (20230223)]/ jammy main restricted

See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to

newer versions of the distribution.

deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted

deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted

Major bug fix updates produced after the final release of the

distribution.

deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu

team. Also, please note that software in universe WILL NOT receive any

review or updates from the Ubuntu security team.

deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe

deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe

deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe

deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe

N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu

team, and may not be under a free licence. Please satisfy yourself as to

your rights to use the software. Also, please note that software in

multiverse WILL NOT receive any review or updates from the Ubuntu

security team.

deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse

deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse

deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse

deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse

N.B. software from this repository may not have been tested as

extensively as that contained in the main release, although it includes

newer versions of some applications which may provide useful features.

Also, please note that software in backports WILL NOT receive any review

or updates from the Ubuntu security team.

deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu jammy-security main restricted

deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted

deb http://security.ubuntu.com/ubuntu jammy-security universe

deb-src http://security.ubuntu.com/ubuntu jammy-security universe

deb http://security.ubuntu.com/ubuntu jammy-security multiverse

deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse

This system was installed using small removable media

(e.g. netinst, live or single CD). The matching "deb cdrom"

entries were disabled at the end of the installation process.

For information about how to configure apt package sources,

see the sources.list(5) manual.

默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释

deb [arch=armhf,arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse

deb [arch=armhf,arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse

deb [arch=armhf,arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse

deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse

deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse

预发布软件源,不建议启用

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse

deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse


4. Install crossbuild-essential-armhf, libasound2-dev:armhf(run as root):
```shell
apt update
apt install crossbuild-essential-armhf libasound2-dev:armhf
  1. cargo build
  2. Error.

Additional context The dockerfile provided by repo does not compile to musl. my attempts to use rust-musl-cross and install the environment manually also failed, so I tried to compile it manually myself instead of docker, if you have any good ideas please let me know. I will try to compile on Pi4 on July 4, 2023 at +8 PM GMT.

herrernst commented 9 months ago

So your compilation fails when linking with libasound. In my experience, linking to system binaries is the most painful thing when cross-compiling rust. As a workaround/test you could try adding the flag --no-default-features to cargo build so that the default audio backend rodio-backend doesn't get compiled. Then you would only have a stdout/pipe audio device which you propably could just pipe to aplay.

gpajot commented 3 months ago

Hello @BliemHax, if you are still interested, this might be of some help: https://github.com/librespot-org/librespot/pull/1263 What makes it work is using ubuntu 18.04 and fixing C/openssl/sound library links.