summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 278233ef728c3a513897df475bc299be372d46a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Maintainer: Yakov Till <yakov.till@gmail.com>
pkgname=lichtfeld-studio
pkgver=0.5.3
pkgrel=1
pkgdesc="Real-time 3D Gaussian Splatting studio for point cloud visualization and editing"
arch=('x86_64')
url="https://github.com/MrNeRF/LichtFeld-Studio"
license=('GPL-3.0-only')
depends=(
    'assimp'
    'boost'
    'cuda'
    'dbus'
    'ffmpeg'
    'freetype2'
    'gcc-libs'
    'glibc'
    'gtk3'  # libgtk-3/libgdk-3, linked via nativefiledialog-extended's GTK backend
    'hicolor-icon-theme'
    'libarchive'
    'libdeflate'  # find_package(libdeflate CONFIG); links libdeflate.so
    'libglvnd'
    'libwebp'
    'nvidia-utils'  # driver >= 570 required at runtime
    'openimageio'
    'onetbb'
    'openssl'
    'python312'
    'python312-packaging'
    'sdl3'
    'spdlog'
    'vulkan-icd-loader'  # libvulkan.so (volk loads it; find_package(Vulkan))
    'zeromq'  # libzmq.so for the TCP/cppzmq layer
)
makedepends=(
    'autoconf'
    'autoconf-archive'
    'automake'
    'cmake>=3.30'
    'cppzmq'  # header-only ZMQ C++ binding, ships cppzmqConfig.cmake
    'curl'
    'git'
    'glm'
    'libtool'
    'nanobind'
    'nasm'
    'ninja'
    'nlohmann-json'
    'patchelf'
    'pkgconf'
    'python312'
    'robin-map'
    'tar'
    'unzip'
    'volk'  # find_package(volk CONFIG); header-only loader
    'vulkan-headers'  # find_package(Vulkan) + VMA/volk compile against these
    'zip'
)
provides=('lichtfeld-studio')
conflicts=('lichtfeld-studio-git')
options=(!lto !debug)  # !lto: CUDA gcc-14 can't link GCC 15 LTO; !debug: mixed vcpkg debug info unusable
_libvtermcommit=934bc2fbf21800ac3458a499df8820ca5fb45fd3
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/MrNeRF/LichtFeld-Studio/archive/refs/tags/v${pkgver}.tar.gz"
        'vcpkg::git+https://github.com/microsoft/vcpkg.git'
        "libvterm-${_libvtermcommit}.tar.gz::https://github.com/neovim/libvterm/archive/${_libvtermcommit}.tar.gz"
        'lichtfeld-studio.desktop')
sha256sums=('2f8427f685d935f71874966a952a2671a49995639bf8b769a9fcd72261243357'
            'SKIP'
            'f09525eb2a02679be0eb50bc1c294569e8cbaa4b59fb867d606236de2830045f'
            'a07642f575ad454ef6783e0a49d03afc96cc7df14d82db7a9de2ccad045fde65')

latestver() {
    curl -fsSL "https://api.github.com/repos/MrNeRF/LichtFeld-Studio/tags" |
        jq -r '.[]?.name | select(startswith("v"))' |
        head -n1 | sed 's/^v//'
}

prepare() {
    cd "LichtFeld-Studio-${pkgver}"

    # Populate libvterm (submodule not included in release tarball)
    rm -rf external/libvterm
    cp -a "$srcdir/libvterm-${_libvtermcommit}" external/libvterm

    # Bootstrap vcpkg (makepkg manages clone/fetch via source array).
    # Copy instead of symlink: bootstrap downloads binary to vcpkg/vcpkg
    # which collides with the symlink target path.
    rm -rf vcpkg
    cp -a "$srcdir/vcpkg" vcpkg
    rm -f vcpkg/vcpkg  # remove stale binary/symlink so bootstrap can write fresh
    rm -f vcpkg/.git/refs/remotes/origin/patch-2026-04-02  # remove stale remote-tracking ref (deleted upstream)
    ./vcpkg/bootstrap-vcpkg.sh -disableMetrics

    # Skip vcpkg debug builds (we only use release libs);
    # strip $srcdir from __FILE__ macros in vcpkg-built libs
    cat >> vcpkg/triplets/x64-linux.cmake <<EOF
set(VCPKG_BUILD_TYPE release)
set(VCPKG_C_FLAGS "-ffile-prefix-map=${srcdir}/=")
set(VCPKG_CXX_FLAGS "-ffile-prefix-map=${srcdir}/=")
EOF

    # Fix vendored zep missing <cstdint> for GCC 15
    sed -i '5i #include <cstdint>' external/zep/include/zep/glyph_iterator.h

    # Remove $srcdir reference from binary (PROJECT_ROOT_PATH is a dev fallback;
    # production path resolution uses exe/../share/LichtFeld-Studio/ which works with FHS)
    sed -i 's|get_filename_component(PROJ_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)|set(PROJ_ROOT_DIR "/usr/share/LichtFeld-Studio")|' CMakeLists.txt

    # Remove dev-only fallback paths that leak $srcdir into binaries
    # (runtime uses FHS paths from getAssetsDir()/getShadersDir(); these are #ifdef guards)
    sed -i '/PROJECT_ROOT_PATH="\${PROJECT_SOURCE_DIR}"/d;
            /VISUALIZER_.*_PATH="\${VISUALIZER_BUILD_RESOURCE_DIR}/d;
            /VISUALIZER_SOURCE_.*_PATH="\${VISUALIZER_SOURCE_RESOURCE_DIR}/d' \
        src/visualizer/CMakeLists.txt
    # Use the packaged interpreter path instead of whatever build-local Python
    # path CMake resolved.
    sed -i 's|LFS_PYTHON_EXECUTABLE="\${Python_EXECUTABLE}"|LFS_PYTHON_EXECUTABLE="/usr/bin/python3.12"|' \
        src/python/CMakeLists.txt

    # Point the vulkan rasterizer's dev SPV fallback at the installed shaders
    # instead of the build tree (unconditional compile def; runtime primary is
    # already getResourceBaseDir()/shaders/vulkan_rasterizer via FHS).
    sed -i 's|LFS_VULKAN_RASTERIZER_DEV_SPV_DIR="\${LFS_VULKAN_RASTERIZER_SPV_DIR}/"|LFS_VULKAN_RASTERIZER_DEV_SPV_DIR="/usr/share/LichtFeld-Studio/shaders/vulkan_rasterizer/"|' \
        src/rendering/rasterizer/vulkan/CMakeLists.txt

    # Trim vcpkg.json to only deps without system equivalents.
    # Everything else comes from Arch packages (faster build, smaller footprint).
    python3.12 -c "
import json
with open('vcpkg.json') as f:
    cfg = json.load(f)

# Keep only deps that have no system equivalent or feature gaps
keep = {
    'imgui',              # needs docking-experimental branch
    'implot',             # must match vcpkg imgui
    'rmlui',              # AUR package lacks SVG feature
    'args',               # tiny, no Arch package
    'nativefiledialog-extended',  # no Arch package
    'usd',                # OpenUSD, no Arch package
    'vulkan-memory-allocator',  # not in official Arch repos
    'shader-slang',       # not in official Arch (cachyos-only); provides slangc tool
    'glslang',            # visualizer FORCE-pins glslang_DIR to vcpkg dir
}

cfg['dependencies'] = [
    d for d in cfg['dependencies']
    if (d if isinstance(d, str) else d['name']) in keep
]

with open('vcpkg.json', 'w') as f:
    json.dump(cfg, f, indent=2)
"
}

build() {
    cd "LichtFeld-Studio-${pkgver}"

    export VCPKG_ROOT="$srcdir/LichtFeld-Studio-${pkgver}/vcpkg"
    export PATH="/opt/cuda/bin:$PATH"

    local _nanobind_dir
    _nanobind_dir=$(dirname "$(readlink -f /usr/lib/cmake/nanobind/nanobind-config.cmake)")

    # nvcc needs a host compiler within CUDA's supported range. Arch's cuda package
    # strips the gcc-version guard from host_config.h, so on a current system nvcc
    # silently uses the system gcc (16), which CUDA <= 13.3 rejects (host_config.h
    # caps at gcc 15) -> deep, non-obvious compile failures. Pin the CUDA host
    # compiler to the exact gcc the installed cuda depends on (gcc15 for cuda 13.3,
    # gcc14 for cuda-pascal). Non-CUDA C++ is unaffected and keeps the system compiler.
    local _cuda_pkg _cuda_gcc _cuda_host_cxx
    _cuda_pkg=$(pacman -Qoq /opt/cuda/bin/nvcc)
    _cuda_gcc=$(pacman -Qi "$_cuda_pkg" | grep -oP '\bgcc\K[0-9]+' | head -1)
    _cuda_host_cxx="/usr/bin/g++-${_cuda_gcc}"
    [[ -x "$_cuda_host_cxx" ]] || _cuda_host_cxx="/opt/cuda/bin/g++"
    echo "==> CUDA host compiler: $_cuda_host_cxx (from $_cuda_pkg -> gcc$_cuda_gcc)"

    cmake -B build \
        -DCUDAToolkit_ROOT=/opt/cuda \
        -DCMAKE_CUDA_HOST_COMPILER="${_cuda_host_cxx}" \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_RPATH=/usr/lib \
        -DCMAKE_C_FLAGS="-ffile-prefix-map=${srcdir}/=" \
        -DCMAKE_CXX_FLAGS="-ffile-prefix-map=${srcdir}/=" \
        -DCMAKE_CUDA_FLAGS="-Xcompiler=-ffile-prefix-map=${srcdir}/=" \
        -DBUILD_PYTHON_STUBS=OFF \
        -DBUILD_TESTS=OFF \
        -DLFS_DEV_IMPORT_SOURCE_RESOURCES=OFF \
        -DLFS_DEV_IMPORT_SOURCE_PYTHON=OFF \
        -DPython_EXECUTABLE=/usr/bin/python3.12 \
        -DPython_ROOT_DIR=/usr \
        -DPython_FIND_STRATEGY=LOCATION \
        -Dnanobind_DIR="${_nanobind_dir}" \
        -G Ninja

    cmake --build build
}

package() {
    cd "LichtFeld-Studio-${pkgver}"
    DESTDIR="$pkgdir" cmake --install build

    # License to proper FHS location (upstream installs to prefix root)
    install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
    rm -f "$pkgdir/usr/LICENSE"

    # Upstream resolves embedded Python modules from /usr/lib/python.
    if [[ -d "$pkgdir/python" ]]; then
        install -d "$pkgdir/usr/lib"
        mv "$pkgdir/python" "$pkgdir/usr/lib/python"
    fi

    # liblfs_rmlui.so is built but not installed by cmake
    install -Dm755 build/liblfs_rmlui.so -t "$pkgdir/usr/lib/"

    # Vendored OpenMesh libs (built under build/Build/lib, not installed by cmake;
    # needed at runtime by the main binary and the python module). No Arch package.
    install -Dm755 build/Build/lib/libOpenMeshCore.so.11.0 \
        build/Build/lib/libOpenMeshTools.so.11.0 -t "$pkgdir/usr/lib/"

    # OpenUSD shared libs (vcpkg-built, not installed by cmake but needed at runtime
    # by liblfs_mcp.so). Exact transitive closure from readelf NEEDED walk.
    local _vcpkg_lib="build/vcpkg_installed/x64-linux/lib"
    local _usd_libs=(
        libusd_ar libusd_arch libusd_gf libusd_js libusd_kind libusd_pcp
        libusd_plug libusd_sdf libusd_tf libusd_trace libusd_ts libusd_usd
        libusd_usdGeom libusd_usdVol libusd_vt libusd_work
    )
    for _lib in "${_usd_libs[@]}"; do
        install -Dm755 "$_vcpkg_lib/$_lib.so" -t "$pkgdir/usr/lib/"
    done

    # Fix RUNPATH: replace vcpkg build paths with /usr/lib
    for f in $(find "$pkgdir" -type f \( -name '*.so' -o -name '*.so.*' -o -executable \)); do
        if readelf -d "$f" 2>/dev/null | grep -q RUNPATH; then
            local _rpath
            _rpath=$(patchelf --print-rpath "$f" 2>/dev/null) || continue
            # Replace build-tree and unnecessary absolute CUDA paths; ldconfig
            # already exposes CUDA libs from the system package.
            _rpath=$(echo "$_rpath" | tr ':' '\n' | grep -v "$srcdir" | grep -v '^/opt/cuda/' | paste -sd:)
            [[ -z "$_rpath" ]] && _rpath="/usr/lib"
            patchelf --set-rpath "$_rpath" "$f"
        fi
    done

    # Remove bundled uv (users should use system uv)
    rm -f "$pkgdir/usr/bin/uv"

    # Remove development headers (not needed for end users)
    rm -rf "$pkgdir/usr/include"

    # Desktop entry and icon (upstream doesn't ship these)
    install -Dm644 "$srcdir/lichtfeld-studio.desktop" -t "$pkgdir/usr/share/applications/"
    install -Dm644 src/visualizer/gui/assets/icon/icon.svg \
        "$pkgdir/usr/share/icons/hicolor/scalable/apps/lichtfeld-studio.svg"
}