From 17013fe1e592e169fc34f2aa75a418386a60c85c Mon Sep 17 00:00:00 2001 From: asepharyana Date: Tue, 11 Aug 2026 18:32:09 +0700 Subject: [PATCH] =?UTF-8?q?build(nix):=20gateway=20binding=20=E2=80=94=20g?= =?UTF-8?q?yp=20env-var=20paths,=20correct=20cwd,=20tolerant=20install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - binding.gyp: resolve libdatachannel include/.so via LDC_INCLUDE/LDC_LIB env (node -e expression) instead of hardcoded /tmp/ldc-build paths - flake buildPhase: run node-gyp from native/libdatachannel-min root (was build/ subdir → 'binding.gyp not found'); export LDC_INCLUDE (fetchFromGitHub source) + LDC_LIB (cmake build dir) - flake installPhase: tolerate missing binding (screen share disabled, gateway still starts); copy .so real files via -rL --- flake.nix | 34 +++++++++++++++---- .../native/libdatachannel-min/binding.gyp | 4 +-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 0d0c4c9..85d7b5f 100644 --- a/flake.nix +++ b/flake.nix @@ -209,16 +209,21 @@ WRAPPER # build with CMake, then node-gyp links against the .so. mkdir -p build/ldc cd build/ldc - cmake -DCMAKE_BUILD_TYPE=Release \ + OPENSSL_ROOT_DIR="${opensslDevEnv}" cmake -DCMAKE_BUILD_TYPE=Release \ -DNO_EXAMPLES=ON -DNO_TESTS=ON -DNO_WEBSOCKET=ON \ -DNO_MEDIA=OFF \ -DCMAKE_INSTALL_PREFIX=$PWD/install \ - "${opensslDevEnv}" ${libdatachannel-src} 2>&1 || true + ${libdatachannel-src} 2>&1 || true make -j"$NIX_BUILD_CORES" 2>&1 || true - cd .. - LD_LIBRARY_PATH=$PWD/ldc node-gyp rebuild 2>&1 || true - cp -r build/Release/datachannel_min.node . 2>/dev/null || true - echo "libdatachannel-min binding: $(ls -la datachannel_min.node 2>/dev/null | awk '{print $5}') bytes" + LDC_DIR=$PWD + cd ../.. + # binding.gyp resolves include/lib from env (LDC_INCLUDE = source + # dir with rtc/rtc.hpp, LDC_LIB = cmake build dir with the .so). + LDC_INCLUDE=${libdatachannel-src} LDC_LIB=$LDC_DIR \ + npx node-gyp rebuild 2>&1 || true + ls -la build/Release/datachannel_min.node 2>/dev/null \ + && echo "libdatachannel-min binding OK: $(stat -c%s build/Release/datachannel_min.node) bytes" \ + || echo "WARN: libdatachannel-min binding build FAILED (screen share disabled)" ) echo "=== Compiling TypeScript ====" npx tsc 2>&1 @@ -254,6 +259,22 @@ WRAPPER mkdir -p $out/lib/gmw-discord-gateway cp -r dist node_modules package.json tsconfig.json $out/lib/gmw-discord-gateway/ + # GoLive native binding — loadNative resolves it relative to + # dist/goLive/native.js, i.e. /native/libdatachannel-min/ + # build/Release/datachannel_min.node; libdatachannel .so must sit + # next to it and be on LD_LIBRARY_PATH at runtime. + mkdir -p $out/lib/gmw-discord-gateway/native/libdatachannel-min/build/Release + cp native/libdatachannel-min/build/Release/datachannel_min.node \ + $out/lib/gmw-discord-gateway/native/libdatachannel-min/build/Release/ 2>/dev/null || true + mkdir -p $out/lib/gmw-discord-gateway/native/libdatachannel-min/build/ldc + cp -rL native/libdatachannel-min/build/ldc/libdatachannel.so* \ + $out/lib/gmw-discord-gateway/native/libdatachannel-min/build/ldc/ 2>/dev/null || true + # If the binding failed to build, screen share is simply disabled — + # the gateway itself must still start. + if [ ! -f $out/lib/gmw-discord-gateway/native/libdatachannel-min/build/Release/datachannel_min.node ]; then + echo "WARN: datachannel_min.node missing — GoLive screen share disabled in this build" + fi + # Also include drizzle migrations if they exist cp -r drizzle $out/lib/gmw-discord-gateway/ 2>/dev/null || true @@ -262,6 +283,7 @@ WRAPPER #!${pkgs.runtimeShell} cd $out/lib/gmw-discord-gateway export PATH=${pkgs.ffmpeg-headless}/bin:${pkgs.yt-dlp}/bin:\$PATH +export LD_LIBRARY_PATH=$out/lib/gmw-discord-gateway/native/libdatachannel-min/build/ldc:\$LD_LIBRARY_PATH exec ${nodejs}/bin/node dist/index.js WRAPPER chmod +x $out/bin/gmw-discord-gateway diff --git a/services/discord-gateway/native/libdatachannel-min/binding.gyp b/services/discord-gateway/native/libdatachannel-min/binding.gyp index f352b50..cfa3257 100644 --- a/services/discord-gateway/native/libdatachannel-min/binding.gyp +++ b/services/discord-gateway/native/libdatachannel-min/binding.gyp @@ -5,10 +5,10 @@ "sources": ["binding.cpp"], "include_dirs": [ "