Skip to content
Sean McNamara edited this page Jul 25, 2020 · 41 revisions

Rust

Rust 1.32.0 or later is required to build librespot, we recommend installing rust using rustup.

If you are building librespot on macOS, the homebrew provided rust may fail due to the way in which homebrew installs rust. In this case, uninstall the homebrew version of rust and use rustup, and librespot should then build.

A kernel version of 3.9 or higher is required. For info on compiling for older kernels see: Compile-librespot-for-kernel-prior-3.9

Build

Once you've cloned this repository you can build librespot using cargo.

cargo build --release

The default for librespot is to build with Rodio for audio playback, and to use lewton as the decoder, which is a pure rust build on Windows and MacOS.

On Linux you'll need to follow the instructions for the ALSA backend.

Optional features

However you can use cargo's feature flags to change these defaults e.g:

cargo build --release --no-default-features --features portaudio-backend

Here is a full list of available "features" and a short description.

Flag Feature
rodio-backend Audio playback using WASAPI/CoreAudio/ALSA via Rodio.
alsa-backend Audio playback using alsa.
portaudio-backend Audio playback using PortAudio.
pulseaudio-backend Audio playback using PulseAudio.
jackaudio-backend Audio playback using JACK.
sdl-backend Audio playback using SDL2.
gstreamer-backend Audio playback using GStreamer.
with-tremor Vorbis decoding using the fixed-point Tremor library.
with-vorbis Vorbis decoding using libvorbis bindings.
with-dns-sd LAN discovery using dns-sd instead of the default mDNS.

Dependencies

Default backend - Rodio

Rodio is a high-level audio library built on top of CPAL. It is the default as it does not require any non-rust dependencies on windows or MacOS, and is able to use the native audio engines. On Linux the dependencies are the same for the ALSA backend.

Alsa backend (including Rodio when on linux)

Additionally requires pkg-config and alsa libs to be installed.

On debian / ubuntu, the following command will install these dependencies :

apt install libasound2-dev pkg-config

Or on fedora the alsa-lib-devel package.

Portaudio backend

Building requires a C compiler, and of-course portaudio.

On debian / ubuntu, the following command will install these dependencies :

sudo apt install build-essential portaudio19-dev

On Fedora systems, the following command will install these dependencies :

sudo dnf install portaudio-devel make gcc

On macOS, using homebrew :

brew install portaudio

Finally enable the feature in cargo:

cargo build --release --features portaudio-backend

GStreamer backend

Building requires a C compiler and an installation of GStreamer 1.x (so, the old 0.10.x releases will not work). It is highly recommended to have at least the gst-plugins-base and gst-plugins-good sets of plugins installed. plugins-bad and plugins-ugly will improve your selection of plugins.

The OS-independent cargo build command with GStreamer support is as follows:

cargo build --release --features gstreamer-backend

GStreamer on Ubuntu/Debian/Mint/Pop_OS:

sudo apt install build-essential gstreamer1.0-plugins-good gstreamer1.0-plugins-base libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev

For additional plugins, add packages of gstreamer1.0-plugins-X replacing X with "bad", "ugly", "ffmpeg", etc. in the above command.

Then, to enable the GStreamer backend during your librespot build using cargo:

GStreamer on MacOS:

Using Homebrew, you can find gstreamer plugin packages. For example, here is the recipe for the -bad plugins. Here's how you'd install all the main plugin packages:

brew install gst-plugins-good gst-plugins-bad gst-plugins-ugly

This should bring in the -base plugins as well as C development headers as dependencies, but if not, use brew search to your advantage to discover additional packages.

GStreamer on Windows:

On Windows, you can configure your build toolchain using one of two approaches: the Visual C++ toolchain or the MinGW64 toolchain. This Wiki does not currently document how to use the Visual C++ toolchain. The MinGW64 toolchain is quite straightforward.

For MinGW64, you should do the following things:

  • Install MSYS2 from here.
  • Install Rust within MSYS's environment (bash) using pacman -S mingw-w64-x86_64-rust.
  • Install GStreamer and dependencies within MSYS using pacman -S mingw-w64-x86_64-gst-plugins-base mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad mingw-w64-x86_64-gst-plugins-ugly mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gcc
  • Build librespot normally using cargo.
  • Copy the librespot.exe binary into the bin directory where all your MinGW DLLs are. You may have to copy some DLLs as well.
  • If librespot.exe crashes or fails to launch due to missing DLLs, you can always copy them from wherever they are in the MinGW/MSYS folder structure into the same directory as librespot.

It is also possible to use third-party GStreamer builds in many cases, because Windows doesn't care whether compiled .DLL files were built with MinGW or Visual C++. There are official GStreamer binaries for Windows available here and you can drop the DLLs into the same directory as your librespot.exe to have it pick them up.

As a final option, in case commonly available builds don't have the plugins you're looking for, you can build GStreamer from source. By far, the easiest way to build GStreamer from source on Windows is using MSYS2.

Clone this wiki locally