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

Error on cargo build --release #1346

Closed
fivebanger opened this issue Sep 20, 2024 · 15 comments
Closed

Error on cargo build --release #1346

fivebanger opened this issue Sep 20, 2024 · 15 comments

Comments

@fivebanger
Copy link
Contributor

I'm getting a build error on cargo build --release, running Linux Mint 20.3 (based on Ubuntu 20.04 LTS, still supported). What I did so far:

sudo apt-get update
sudo apt-get upgrade

$ rustup update stable
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.81.0 (eeb90cda1 2024-09-04)

info: checking for self-update

$ rustc --version
rustc 1.81.0 (eeb90cda1 2024-09-04)
$ cargo --version
cargo 1.81.0 (2dbb1af80 2024-08-20)

$ git clone https://github.com/librespot-org/librespot

Building result in following error:

cargo build --release

...

error: failed to run custom build command for `aws-lc-sys v0.21.1`

Caused by:
  process didn't exit successfully: `/home/martin/librespot/librespot-dev/librespot/target/release/build/aws-lc-sys-7936ae7f1dab2471/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX
  cargo:rerun-if-env-changed=AWS_LC_SYS_INTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_SYS_EXTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_ASM
  cargo:rerun-if-env-changed=AWS_LC_SYS_CFLAGS
  cargo:rerun-if-env-changed=AWS_LC_SYS_PREBUILT_NASM
  cargo:rerun-if-env-changed=AWS_LC_SYS_C_STD
  cargo:rustc-cfg=x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=AWS_LC_SYS_CMAKE_BUILDER
  cargo:rerun-if-env-changed=AWS_LC_SYS_STATIC
  default_for Target: 'x86_64-unknown-linux-gnu'
  cargo:rerun-if-env-changed=CARGO_FEATURE_SSL
  default_for Target: 'x86_64-unknown-linux-gnu'
  cargo:rerun-if-env-changed=CARGO_FEATURE_SSL
  cargo:root=/home/martin/librespot/librespot-dev/librespot/target/release/build/aws-lc-sys-a9f24552134098bb/out
  default_for Target: 'x86_64-unknown-linux-gnu'
  HOST = Some(x86_64-unknown-linux-gnu)
  TARGET = Some(x86_64-unknown-linux-gnu)
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  RUSTC_WRAPPER = None
  OUT_DIR = Some(/home/martin/librespot/librespot-dev/librespot/target/release/build/aws-lc-sys-a9f24552134098bb/out)
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some(fxsr,sse,sse2)
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  OPT_LEVEL = Some(3)
  TARGET = Some(x86_64-unknown-linux-gnu)
  OUT_DIR = Some(/home/martin/librespot/librespot-dev/librespot/target/release/build/aws-lc-sys-a9f24552134098bb/out)
  HOST = Some(x86_64-unknown-linux-gnu)
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  RUSTC_WRAPPER = 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-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None

  --- stderr
  thread 'main' panicked at /home/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.21.1/builder/cc_builder.rs:277:13:
  ### COMPILER BUG DETECTED ###
  Your compiler (cc) is not supported due to a memcmp related bug reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189. We strongly recommend against using this compiler. 
  EXECUTED: true
  ERROR: 
  OUTPUT: 

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

I'm not facing any build issues for a version older than 3rd of Sept. Next update for me was 7th of Sept. Since 7th of Sept. I cannot build HEAD of dev anymore. Some commit between 3rd and 7th seems to cause this issue.

Any help welcome.

@fivebanger
Copy link
Contributor Author

It seems that my used gcc version is to old.

gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0

I found some advice to use a newer version of gcc, so I did:

sudo apt remove gcc
sudo apt install gcc-10

Running cargo build leads now to error: linker cc not found. The suggested solution to this issue was to run

sudo apt install build-essential

like also mentioned in the COMPILING.md here.

Now I end up with the original error (see first post). I can see that build-essentials has installed gcc-9 again.

I tried to just remove gcc-9, also does not work. The error on cargo build is now:

  --- stderr
  thread 'main' panicked at /home/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.21.1/builder/cc_builder.rs:258:9:
  COMPILER: "cc"ARGS: ["-O3", "-ffunction-sections", "-fdata-sections", "-fPIC", "-m64", "-Wall", "-Wextra", "/home/martin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.21.1/aws-lc/tests/compiler_features_tests/memcmp_invalid_stripped_check.c", "-Wno-unused-parameter", "-o", "/home/martin/librespot/librespot-dev/librespot/target/release/build/aws-lc-sys-a9f24552134098bb/out/memcmp_invalid_stripped_check"]EXECUTED: falseERROR: OUTPUT: Failed to compile memcmp_invalid_stripped_check

@fivebanger
Copy link
Contributor Author

fivebanger commented Sep 20, 2024

What has fixed the issue for me:

sudo apt remove gcc-9
sudo apt install gcc-10

I missed cargo clean before starting a new build which seems to be important. Otherwise build fails with error.

Maybe it's worth to mention a min. version for gcc in the COMPILING.md?

@kingosticks
Copy link
Contributor

kingosticks commented Sep 20, 2024

Maybe it's worth to mention a min. version for gcc in the COMPILING.md?

I don't think this is realistic. This new gcc requirement comes from a dependency. Downstream projects can't be expected to track this kind of thing. I think if you're building the latest code, you're likely going to need a reasonably recent version of common dev tools like gcc. Ubuntu 20.04 might still be "supported" by Canoncial, but it's two LTS releases behind now and contains software from 4.5 years ago. I think it's fair to say that building latest software isn't what old Ubuntu LTS releases are for.

@fivebanger
Copy link
Contributor Author

Ok. The issue is solved for me at the moment. Regarding "best practice": Who is responsible for closing an issue? The OP? Or should this stay open in case someone else stumbles over the same (whereas can still be found in closed issues)?

@kingosticks
Copy link
Contributor

If there's no further action or tracking required then leaving it open isn't necessary and anyone can close. It can easily be reopened later if required. Google will likely bring anyone else here with the same problem, and the workaround should be clear to them.

@kingosticks
Copy link
Contributor

kingosticks commented Sep 21, 2024

I guess the one thing remaining for me here is why it's dragging this dependency in. I thought that aws-lc package was related to nasm support, and surely that's behind a non-default feature flag...

@kingosticks
Copy link
Contributor

kingosticks commented Sep 21, 2024

Cancel thah. I see it's being brought in by hyper's TLS library that's used by core. So it's required.

@kingosticks
Copy link
Contributor

I think they fixed this in aws-lc-sys v0.21.2 aws/aws-lc-rs#520

@rwjack
Copy link

rwjack commented Sep 29, 2024

So how do we fix this on alpine?

ERROR: unable to select packages:
  build-essential (no such package):
    required by: world[build-essential]
  gcc-10 (no such package):
    required by: world[gcc-10]

I tried using an ubuntu builder (rust:latest), but an alpine image as the final one, and I can't seem to get it working even after installing gcompat on the alpine image.

c8c0c3e8bbde:/# librespot --version
Error relocating /usr/bin/librespot: __res_init: symbol not found
c8c0c3e8bbde:/# ldd /usr/bin/librespot 
        /lib64/ld-linux-x86-64.so.2 (0x7fc9cfb20000)
        libasound.so.2 => /usr/lib/libasound.so.2 (0x7fc9ceb93000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fc9ceb6f000)
        libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc9cfb20000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc9cfb20000)
        ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x7fc9ceb68000)
Error relocating /usr/bin/librespot: __register_atfork: symbol not found
Error relocating /usr/bin/librespot: gnu_get_libc_version: symbol not found
Error relocating /usr/bin/librespot: __res_init: symbol not found

Using this dockerfile:

# Stage 1: Build the Librespot binary
FROM rust:latest AS builder

# Install necessary dependencies for building
RUN apt-get update && apt-get install -y \
    pkg-config \
    libasound2-dev \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /usr/src/librespot

# Clone the Librespot repository
RUN git clone https://github.com/librespot-org/librespot.git .

# Build the project
RUN cargo build --release


ARG BUILD_FROM
#FROM $BUILD_FROM
FROM ghcr.io/hassio-addons/base:16.2.1

# Add env
ENV LANG C.UTF-8

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN \
    apk add --no-cache \
        pulseaudio alsa-plugins-pulse bash gcompat \
    && rm -fr \
        /tmp/*

RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community/ snapcast-server=0.29.0-r0

# Copy the built binary from the builder stage
COPY --from=builder /usr/src/librespot/target/release/librespot /usr/bin/librespot

#RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ librespot=0.4.2-r4

RUN \
    wget https://github.com/badaix/snapweb/releases/download/v0.8.0/snapweb.zip && \
    unzip -o snapweb.zip -d /usr/share/snapserver/snapweb/ && \
    rm snapweb.zip

# Copy data for add-on
COPY run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]

@rwjack
Copy link

rwjack commented Sep 29, 2024

Tried to cross compile like this:

# Stage 1: Build the Librespot binary
FROM rust:latest AS builder

# Install necessary dependencies for building
RUN apt-get update && apt-get install -y \
    pkg-config \
    libasound2-dev \
    musl-tools \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /usr/src/librespot

# Clone the Librespot repository
RUN git clone https://github.com/librespot-org/librespot.git .

# Set up cargo for static linking
RUN rustup target add x86_64-unknown-linux-musl

# Build the project
RUN cargo build --release --target=x86_64-unknown-linux-musl


ARG BUILD_FROM
#FROM $BUILD_FROM
FROM ghcr.io/hassio-addons/base:16.2.1

# Add env
ENV LANG C.UTF-8

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN \
    apk add --no-cache \
        pulseaudio alsa-plugins-pulse bash gcompat \
    && rm -fr \
        /tmp/*

RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community/ snapcast-server=0.29.0-r0

# Copy the built binary from the builder stage
COPY --from=builder /usr/src/librespot/target/x86_64-unknown-linux-musl/release/librespot /usr/bin/librespot

#RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ librespot=0.4.2-r4

RUN \
    wget https://github.com/badaix/snapweb/releases/download/v0.8.0/snapweb.zip && \
    unzip -o snapweb.zip -d /usr/share/snapserver/snapweb/ && \
    rm snapweb.zip

# Copy data for add-on
COPY run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]

But getting this for alsa-sys:

error: failed to run custom build command for `alsa-sys v0.3.1`

Caused by:
  process didn't exit successfully: `/usr/src/librespot/target/release/build/alsa-sys-4e367607089bbaea/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=ALSA_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

  --- stderr
  thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/alsa-sys-0.3.1/build.rs:13:18:
  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.
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

@rwjack
Copy link

rwjack commented Sep 29, 2024

Can't even get it built on an alpine builder:

# Stage 1: Build the Librespot binary
FROM rust:alpine AS builder
                                             
# Install necessary dependencies for building
RUN apk add --no-cache \    build-base \    pkgconfig \       alsa-lib-dev \    alsa-lib \    libc-dev \    git
                           
# Set the working directory
WORKDIR /usr/src/librespot
                                
# Clone the Librespot repository                              
RUN git clone https://github.com/librespot-org/librespot.git .
                                             
# Build the project      
RUN cargo build --release

              
ARG BUILD_FROM   
#FROM $BUILD_FROM                     
FROM ghcr.io/hassio-addons/base:16.2.1
         
# Add env       
ENV LANG C.UTF-8
           
# Set shell                                
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
     
RUN \                       apk add --no-cache \                            pulseaudio alsa-plugins-pulse bash \    && rm -fr \        /tmp/*
                                                                                                                  
RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community/ snapcast-server=0.29.0-r0
                                              
# Copy the built binary from the builder stage                                    
COPY --from=builder /usr/src/librespot/target/release/librespot /usr/bin/librespot
                                                                                                          
#RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ librespot=0.4.2-r4
     
RUN \                                                                                   wget https://github.com/badaix/snapweb/releases/download/v0.8.0/snapweb.zip && \    unzip -o snapweb.zip -d /usr/share/snapserver/snapweb/ && \
    rm snapweb.zip
                      
# Copy data for add-on
COPY run.sh /        
RUN chmod a+x /run.sh
                 
CMD [ "/run.sh" ]
...SNIP...
.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-L" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "-o" "/usr/src/librespot/target/release/deps/librespot-e3048d588e2dd052" "-Wl,--gc-sections" "-static-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o" "/usr/local/rustup/toolchains/1.81.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lasound: No such file or directory
          collect2: error: ld returned 1 exit status
          

error: could not compile `librespot` (bin "librespot") due to 1 previous error
The command '/bin/sh -c cargo build --release' returned a non-zero code: 101

@fivebanger
Copy link
Contributor Author

fivebanger commented Oct 7, 2024

Beside a Linux PC system, I have (tried) to build current librespot also on other targets (native, no cross-compile):

Raspberry Pi OS (64bit) on a Raspberry Pi 4:

  • no issues, compiles out of the box (after installing RUST and the dependencies mentioned in the COMPILING.md)

Raspberry Pi OS (32bit) on a Rasperry Pi 1:

  • Additional installation sudo apt install cmake, sudo apt install libclang-dev for aws-lc-sys v0.21.2
  • Build was successful at the end

Win10 (64bit)

  • Additional installation install NASM for Windows, install CMake for Windows for aws-lc-sys v0.21.2
  • Error memory allocation of 2096928 bytes failed, rustc-LLVM ERROR: out of memory for Compiling oauth2 v4.4.2
  • Build was not successful
  • Edit: Build was successful after rebooting the system

That's the complete error log:

   Compiling oauth2 v4.4.2
memory allocation of 2096928 bytes failed
rustc-LLVM ERROR: out of memory
Allocation failed
rustc-LLVM ERROR: out of memory
Allocation failed
error: could not compile `data-encoding` (lib)

Caused by:
  process didn't exit successfully: `C:\Users\martin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe --crate-name data_encoding --edition=2018 C:\Users\martin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\data-encoding-2.6.0\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg "feature=\"alloc\"" --cfg "feature=\"default\"" --cfg "feature=\"std\"" --check-cfg cfg(docsrs) --check-cfg "cfg(feature, values(\"alloc\", \"default\", \"std\"))" -C metadata=4e21b18e173a4cfa -C extra-filename=-4e21b18e173a4cfa --out-dir c:\rust\librespot-cli_2024_09_03\target\release\deps -C strip=debuginfo -L dependency=c:\rust\librespot-cli_2024_09_03\target\release\deps --cap-lints allow` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
warning: build failed, waiting for other jobs to finish...
error: could not compile `oauth2` (lib)

It seems that aws-lc-sys v0.21.2 brings some trouble for some systems which needs additional installation steps.

I have stopped building librespot on Windows for now. Was anyone successful compiling and building recent librespot on Windows?

Edit:
cargo build --release finished successful after rebooting the Win10 system.

@kingosticks
Copy link
Contributor

Is your windows system likely to be out of memory while compiling? Does building with -j 1 avoid the problem? I'll try a widows build later.

@kingosticks
Copy link
Contributor

And in terms of successful windows builds, they're all fine for CI (else it wouldn't have been merged).

@fivebanger
Copy link
Contributor Author

fivebanger commented Oct 7, 2024

And in terms of successful windows builds, they're all fine for CI (else it wouldn't have been merged).

Thanks for the hint. I just thought there is maybe a general issue with building on Windows.

I have rebooted my Win10 PC and started the build again. I was able to finish the build now using cargo build --release. So maybe you are right, maybe there was an issue with my PC memory. I never had any issue when building v0.4.2, no idea what was the issue now. I'll try to do a clean and build from scratch again the next days, maybe I'm facing the memory issue again.

Edit:
After reboot, cargo clean and cargo build --release again I have not seen any problem. Build was executed without an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants