Building audiopus_sys Rust crate
laggy_computer
HOBBYOP

10 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

Pinned Solution

colinrm000
HOBBY

9 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.

7 Replies

colinrm000
HOBBY

10 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 `nixLibs` Example: `[phases.setup]` `nixPkgs = [` ` "cmake",` ` "pkg-config"` `]` `nixLibs = [` ` "opus"` `]` After redeploying with this config, the build should succeed! 🙂

laggy_computer
HOBBYOP

10 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: 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:info`pkg_config` could not find `Opus`. cargo:info=Opus source path used: "/root/.cargo/registry/src/[index.crates.io](http://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](http://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](http://index.crates.io)\-1949cf8c6b5b557f/cmake-0.1.54/src/[lib.rs:1119](http://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... \`\`\`

colinrm000
HOBBY

10 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

9 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

9 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

9 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

9 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 10 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...