OverviewFilesCommitsIssuesDocsReleasesPeers

hyperswarm-peer / tools / build_swarm_probe.sh

51 lines · bash ref:
#!/bin/bash
# Build swarm-probe. Same object set as the session daemon — this drives
# UdxTransport (HyperDht/DhtConnector/SwarmManager) plus protomux.
#
# ⚠ DEV BUILD (plain g++). Anything SHIPPED must go through the Zig wrappers;
# a plain build links a newer glibc than some fleet machines have.
set -e
cd "$(dirname "$0")"

SRCDIR=../src
UDX_INC=../thirdparty/libudx/include
COMPACT_INC="-I../thirdparty/libcompact/include -I../thirdparty/libutf/include"
CXXFLAGS="-std=c++17 -O2 -D_GNU_SOURCE -I. -I$SRCDIR -I$UDX_INC $COMPACT_INC"
LDFLAGS="-luv -lsodium -lpthread"

OBJ=/tmp/hsp-obj
if [ ! -d "$OBJ" ]; then
    echo "ERROR: $OBJ missing. Run ../test/build_tests.sh first — it compiles the"
    echo "shared transport objects this links against."
    exit 1
fi

SHARED="noise_ik noise_handshake noise_stream dht_rpc holepuncher hyperdht \
        dht_connector udx_transport swarm_manager protomux"

# ⛔ A HALF-UPDATED OBJECT CACHE LINKS FINE AND IS DEAD ON ARRIVAL — a class
# layout is a contract between translation units, and ../test/build_tests.sh
# runs under `set -e`, so an error anywhere in it leaves this cache half-new.
# That produced a committed daemon binary that aborted in malloc on every start.
NEWEST=$(ls -t $SRCDIR/*.h $SRCDIR/*.cpp | head -1)
STALE=""
for o in $SHARED; do
    if [ ! -f "$OBJ/$o.o" ] || [ "$NEWEST" -nt "$OBJ/$o.o" ]; then
        STALE="$STALE $o.o"
    fi
done
if [ -n "$STALE" ]; then
    echo "ERROR: object cache is older than $NEWEST:$STALE"
    echo "       Run ../test/build_tests.sh first."
    exit 1
fi

g++ $CXXFLAGS -c -o $OBJ/swarm_probe.o swarm_probe.cpp
g++ -o swarm-probe \
    $OBJ/swarm_probe.o \
    $(for o in $SHARED; do echo -n "$OBJ/$o.o "; done) \
    $(ls $OBJ/udx_*.o | grep -v "/udx_transport.o$") \
    $(ls $OBJ/compact_*.o) \
    $LDFLAGS
echo "  OK: swarm-probe"