Bootstrap: docker
From: ubuntu:24.04
Stage: build

%files
    . /opt/loki

%post
    # Set noninteractive mode for apt
    export DEBIAN_FRONTEND=noninteractive

    # Update and install dependencies
    apt-get update
    apt-get install -y \
        build-essential \
        cmake \
        git \
        python3 \
        python3-pip \
        wget \
        ca-certificates \
        ccache \
        && apt-get clean \
        && rm -rf /var/lib/apt/lists/*

    # Set working directory
    cd /opt/loki

    # Install native dependencies
    python3 -m pip install --break-system-packages pyyggdrasil>=0.0.11

    # Build Loki
    cmake -S . -B build \
        -DCMAKE_PREFIX_PATH="$(python3 -c 'import pyyggdrasil; print(pyyggdrasil.native_prefix())')" \
        -DCMAKE_BUILD_TYPE=Release \
        -DLOKI_BUILD_TESTS=OFF \
        -DLOKI_BUILD_PROFILING=OFF \
        -DLOKI_BUILD_EXECUTABLES=ON
    cmake --build build -j$(nproc)

    # Install Loki to a staging directory
    cmake --install build --prefix=/opt/loki/install


# Runtime stage
Bootstrap: docker
From: ubuntu:24.04
Stage: runtime

%files from build
    /opt/loki/install /usr/local
    /opt/loki/build/exe/loki /usr/local/bin/loki

%post
    # Install only runtime dependencies
    export DEBIAN_FRONTEND=noninteractive
    apt-get update
    apt-get install -y \
        libstdc++6 \
        libgomp1 \
        && apt-get clean \
        && rm -rf /var/lib/apt/lists/*

    # Update library cache
    ldconfig

%environment
    export LC_ALL=C
    export PATH=/usr/local/bin:$PATH
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

%runscript
    exec loki "$@"

%labels
    Author Dominik Drexler
    Description Loki PDDL parser and translator

%help
    This is a container for Loki, a C++20 library for syntactic and semantic
    parsing and translation of PDDL files.

    Usage:
        apptainer run loki.sif <domain.pddl> <problem.pddl>

    Or start an interactive shell:
        apptainer shell loki.sif

    The loki executable is available at /usr/local/bin/loki
