Skip to content

OpenSpace distro‐independent builds

hn-88 edited this page Dec 7, 2025 · 2 revisions

Gemini3 says, Via aistudio.google.com,

There are a few standard, distro-independent ways to achieve this. The most robust method is using Docker, which completely isolates the build environment. Alternatively, you can use a cross-platform package manager like vcpkg (which OpenSpace already uses for Windows) or Nix. Here are the three best approaches, ranked from easiest to most advanced.

1. The Containerized Way (Recommended)

This is the true "write once, run anywhere" solution. Instead of installing dependencies on your host machine, you create a standard build environment inside a Docker container. OpenSpace actually provides official Dockerfiles for this purpose. You can look at the docker/ folder in their repository, or create a simple Dockerfile that replicates your script: Create a file named Dockerfile:

Dockerfile

#Use a specific Ubuntu version so this build works forever,
#regardless of what distro your host machine runs.
FROM ubuntu:24.04

# Avoid interactive prompts during install
ENV DEBIAN_FRONTEND=noninteractive

# Run the exact commands you listed
RUN apt-get update && apt-get install -y \
    glew-utils libpng-dev freeglut3-dev git libxrandr-dev \
    libxinerama-dev xorg-dev libxcursor-dev libcurl4-openssl-dev \
    libxi-dev libasound2-dev libgdal-dev libboost-all-dev \
    qt6-base-dev libmpv-dev libvulkan-dev \
    software-properties-common gcc g++ \
    libasound2t64 cmake ninja-build

# Set the working directory
WORKDIR /openspace

# Default command
CMD ["/bin/bash"]
How to use it:

Bash
# 1. Build the environment (only do this once)
docker build -t openspace-env .

# 2. Compile OpenSpace inside it (assuming you are in the source code folder)
docker run --rm -v $(pwd):/openspace openspace-env \
    cmake -S . -B build -G Ninja && cmake --build build

Pros: Guaranteed to work on Ubuntu, Arch, Fedora, macOS, and Windows.

Cons: Requires Docker installed; binaries built inside are for Linux.

2. The C++ Package Manager Way (vcpkg)

OpenSpace officially uses vcpkg for its Windows builds. You can use vcpkg on Linux to replace apt for the C++ libraries (Boost, GLEW, GDAL, Qt, etc.). This keeps your system clean. Build Script (build.sh):

Bash

#!/bin/bash

# 1. Bootstrap vcpkg (distro-independent)
if [ ! -d "vcpkg" ]; then
    git clone https://github.com/microsoft/vcpkg.git
    ./vcpkg/bootstrap-vcpkg.sh
fi

# 2. Install dependencies via vcpkg
# (Note: vcpkg package names differ slightly from apt)
./vcpkg/vcpkg install \
    glew libpng freeglut curl gdal boost qt6-base mpv vulkan \
    --triplet=x64-linux

# 3. Configure CMake to use vcpkg
cmake -B build -S . \
    -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake

Pros: Native binary speed; no virtualization; standard in the C++ world.

Cons: You still need a few system basics (compiler, raw X11 libraries) installed via your OS package manager.

3. The Purely Functional Way (Nix)

If you want a truly reproducible shell that works on any Linux distro (and macOS) without containers, Nix is the modern standard. Create a flake.nix in your repo root:

Nix
{
  description = "OpenSpace Build Environment";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      devShells.${system}.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          cmake
          gcc
          glew
          libpng
          freeglut
          xorg.libXrandr
          xorg.libXinerama
          xorg.libXcursor
          xorg.libXi
          curl
          alsa-lib
          gdal
          boost
          qt6.qtbase
          mpv
          vulkan-loader
        ];
        
        shellHook = ''
            echo "Environment ready for OpenSpace compilation."
        '';
      };
    };
}

How to use it:

Run nix develop in that folder. You will instantly be dropped into a shell with gcc, cmake, and all libraries available.

Pros: Perfectly reproducible; isolates dependencies from your system - nixos.org

Cons: Steeper learning curve if you haven't used Nix before.

Clone this wiki locally