Building audiopus_sys Rust crate
laggy_computer
HOBBYOP

3 months ago

I'm building a Rust project which depends on the audiopus_sys crate, but that crate fails to build. I have selected the static feature and added this nixpacks.toml

[phase.setup]
nixPkgs = ["...", "pkg-config"]
nixLibs = ["...", "libopus"]

The relevant section of the build log. It is clear that libopus is not found and an attempt is made to build it from source:

  process didn't exit successfully: `/app/target/release/build/audiopus_sys-9601873073ea72a2/build-script-build` (exit status: 101)
  --- stdout
  cargo:info=Static feature or environment variable found.
  cargo:rerun-if-env-changed=OPUS_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:info=`pkg_config` could not find `Opus`.
  cargo:info=Opus source path used: "/root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/audiopus_sys-0.2.2/opus".
  cargo:info=Building Opus via CMake.
  CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
  CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
  CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
  CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-unknown-linux-gnu = None
  CMAKE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE = None
  CMAKE = None
  running: cd "/app/target/release/build/audiopus_sys-69cb3deaefc852a0/out/build" && CMAKE_PREFIX_PATH="" LC_ALL="C" "cmake" "/root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/audiopus_sys-0.2.2/opus" "-DCMAKE_INSTALL_PREFIX=/app/target/release/build/audiopus_sys-69cb3deaefc852a0/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/root/.nix-profile/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/root/.nix-profile/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/root/.nix-profile/bin/cc" "-DCMAKE_BUILD_TYPE=Release"
  --- stderr
  thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cmake-0.1.54/src/lib.rs:1119:5:
  failed to execute command: No such file or directory (os error 2)
  is `cmake` not installed?
  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

What needs to be done to fix this?

Solved$10 Bounty

7 Replies

colinrm000
HOBBY

3 months ago

The error is happening because audiopus_sys falls back to building Opus from source, but the build environment doesn’t have cmake installed. That’s why you see:

failed to execute command: No such file or directory (os error 2)

is cmake not installed?

I believe to fix this, you need to update your nixpacks.toml so cmake is included in nixPkgs along with pkg-config, and keep opus in nixLibs
Example:

[phases.setup]

nixPkgs = [

"cmake",

"pkg-config"

]

nixLibs = [

"opus"

]

After redeploying with this config, the build should succeed!


colinrm000

The error is happening because audiopus_sys falls back to building Opus from source, but the build environment doesn’t have cmake installed. That’s why you see:failed to execute command: No such file or directory (os error 2)is cmake not installed?I believe to fix this, you need to update your nixpacks.toml so cmake is included in nixPkgs along with pkg-config, and keep opus in nixLibsExample:[phases.setup]nixPkgs = ["cmake","pkg-config"]nixLibs = ["opus"]After redeploying with this config, the build should succeed!

laggy_computer
HOBBYOP

3 months ago

Few things:

  1. opus is not a valid Nix library or package

  2. The crate should not even be attempting to build libopus; the intended behavior is that the presence of pkg-config and the libopus is sufficient for the crate discover it and statically link to it.

  3. The proposed solution (including keeping libopus as a library) fails similarly to the original failure:
    ```
    process didn't exit successfully: /app/target/release/build/audiopus_sys-9601873073ea72a2/build-script-build (exit status: 101)

    --- stdout

    cargo:info=Static feature or environment variable found.

    cargo:rerun-if-env-changed=OPUS_NO_PKG_CONFIG

    cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu

    cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu

    cargo:rerun-if-env-changed=HOST_PKG_CONFIG

    cargo:rerun-if-env-changed=PKG_CONFIG

    cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu

    cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu

    cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH

    cargo:rerun-if-env-changed=PKG_CONFIG_PATH

    cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu

    cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu

    cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR

    cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR

    cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu

    cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu

    cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR

    cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

    cargo:infopkg_config could not find Opus.

    cargo:info=Opus source path used: "/root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/audiopus_sys-0.2.2/opus".

    cargo:info=Building Opus via CMake.

    CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None

    CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None

    HOST_CMAKE_TOOLCHAIN_FILE = None

    CMAKE_TOOLCHAIN_FILE = None

    CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None

    CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None

    HOST_CMAKE_GENERATOR = None

    CMAKE_GENERATOR = None

    CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None

    CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None

    HOST_CMAKE_PREFIX_PATH = None

    CMAKE_PREFIX_PATH = None

    CMAKE_x86_64-unknown-linux-gnu = None

    CMAKE_x86_64_unknown_linux_gnu = None

    HOST_CMAKE = None

    CMAKE = None

    running: cd "/app/target/release/build/audiopus_sys-69cb3deaefc852a0/out/build" && CMAKE_PREFIX_PATH="" LC_ALL="C" "cmake" "/root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/audiopus_sys-0.2.2/opus" "-DCMAKE_INSTALL_PREFIX=/app/target/release/build/audiopus_sys-69cb3deaefc852a0/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/root/.nix-profile/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/root/.nix-profile/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/root/.nix-profile/bin/cc" "-DCMAKE_BUILD_TYPE=Release"

    --- stderr

    thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cmake-0.1.54/src/lib.rs:1119:5:

    failed to execute command: No such file or directory (os error 2)

    is cmake not installed?

    build script failed, must exit now

    note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

    warning: build failed, waiting for other jobs to finish...
    ```


laggy_computer

Few things:opus is not a valid Nix library or packageThe crate should not even be attempting to build libopus; the intended behavior is that the presence of pkg-config and the libopus is sufficient for the crate discover it and statically link to it.The proposed solution (including keeping libopus as a library) fails similarly to the original failure:``` process didn't exit successfully: /app/target/release/build/audiopus_sys-9601873073ea72a2/build-script-build (exit status: 101)--- stdoutcargo:info=Static feature or environment variable found.cargo:rerun-if-env-changed=OPUS_NO_PKG_CONFIGcargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnucargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnucargo:rerun-if-env-changed=HOST_PKG_CONFIGcargo:rerun-if-env-changed=PKG_CONFIGcargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnucargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnucargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATHcargo:rerun-if-env-changed=PKG_CONFIG_PATHcargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnucargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnucargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIRcargo:rerun-if-env-changed=PKG_CONFIG_LIBDIRcargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnucargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnucargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIRcargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIRcargo:infopkg_config could not find Opus.cargo:info=Opus source path used: "/root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/audiopus_sys-0.2.2/opus".cargo:info=Building Opus via CMake.CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = NoneCMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = NoneHOST_CMAKE_TOOLCHAIN_FILE = NoneCMAKE_TOOLCHAIN_FILE = NoneCMAKE_GENERATOR_x86_64-unknown-linux-gnu = NoneCMAKE_GENERATOR_x86_64_unknown_linux_gnu = NoneHOST_CMAKE_GENERATOR = NoneCMAKE_GENERATOR = NoneCMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = NoneCMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = NoneHOST_CMAKE_PREFIX_PATH = NoneCMAKE_PREFIX_PATH = NoneCMAKE_x86_64-unknown-linux-gnu = NoneCMAKE_x86_64_unknown_linux_gnu = NoneHOST_CMAKE = NoneCMAKE = Nonerunning: cd "/app/target/release/build/audiopus_sys-69cb3deaefc852a0/out/build" && CMAKE_PREFIX_PATH="" LC_ALL="C" "cmake" "/root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/audiopus_sys-0.2.2/opus" "-DCMAKE_INSTALL_PREFIX=/app/target/release/build/audiopus_sys-69cb3deaefc852a0/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/root/.nix-profile/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/root/.nix-profile/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/root/.nix-profile/bin/cc" "-DCMAKE_BUILD_TYPE=Release"--- stderrthread 'main' panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cmake-0.1.54/src/lib.rs:1119:5:failed to execute command: No such file or directory (os error 2)is cmake not installed?build script failed, must exit nownote: run with RUST_BACKTRACE=1 environment variable to display a backtracewarning: build failed, waiting for other jobs to finish...```

colinrm000
HOBBY

3 months ago

Aaaah! I see. Thank you for that good explanation.

Maybe try updating your nixpacks.toml like so if you haven't tried this already:

[phases.setup]

nixPkgs = [

"cmake",

"pkg-config",

"libopus"

]

pkg-config should detect the system libopus and link against it.

Let me know how that goes!


colinrm000

Aaaah! I see. Thank you for that good explanation.Maybe try updating your nixpacks.toml like so if you haven't tried this already:[phases.setup]nixPkgs = ["cmake","pkg-config","libopus"]pkg-config should detect the system libopus and link against it.Let me know how that goes!

laggy_computer
HOBBYOP

3 months ago

This config still cannot find cmake:

[phase.setup]
nixPkgs = ["...", "pkg-config", "cmake", "libopus"]

laggy_computer

This config still cannot find cmake:[phase.setup] nixPkgs = ["...", "pkg-config", "cmake", "libopus"]

colinrm000
HOBBY

3 months ago

The issue might be with the config section name. It should be [phases.setup] (plural), not [phase.setup]. Because of that, I don't think Nixpacks is actually installing any of your listed packages.


laggy_computer
HOBBYOP

3 months ago

This works even if cmake is removed. Thank you for noticing that.


laggy_computer

This works even if cmake is removed. Thank you for noticing that.

colinrm000
HOBBY

3 months ago

Awesome, I'm happy to hear that!
It's always the little things that cause havoc lol.

Happy deving!


Status changed to Solved jake 3 months ago


Loading...