forked from continuwuation/continuwuity
324 lines
13 KiB
Makefile
324 lines
13 KiB
Makefile
# List available commands
|
|
_help:
|
|
@just --list
|
|
|
|
# --- Pre-building C/C++ Libraries ---
|
|
# Note: Building these from source avoids Cargo constantly recompiling them
|
|
# and trashing your target/ directory. After building, use the install commands
|
|
# to make them available to Cargo, RustRover, and your system.
|
|
|
|
# Initialize the global build directory
|
|
init-prebuild:
|
|
@echo "Creating /usr/local/build and assigning ownership to $USER... (Requires sudo)"
|
|
sudo mkdir -p /usr/local/build
|
|
sudo chown -R $USER:$USER /usr/local/build
|
|
@echo "Done. You can now run prebuild commands."
|
|
|
|
# Pre-build all C/C++ dependencies
|
|
prebuild-all: init-prebuild prebuild-jemalloc prebuild-lz4 prebuild-snappy prebuild-zstd prebuild-rocksdb
|
|
|
|
# Install all pre-built C/C++ dependencies
|
|
install-all: install-jemalloc install-lz4 install-snappy install-zstd install-rocksdb
|
|
|
|
# Builds liburing
|
|
prebuild-liburing:
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
sudo mkdir -p /usr/local/build && sudo chown -R $USER:$USER /usr/local/build
|
|
echo "Cloning and building liburing (attempting to match project version {{version}})"...
|
|
[ ! -d "/usr/local/build/liburing" ] && git clone https://github.com/axboe/liburing.git /usr/local/build/liburing || true
|
|
cd /usr/local/build/liburing
|
|
git checkout liburing-{{version}} || echo "Warning: Tag liburing-{{version}} not found. Building from latest master instead."
|
|
./configure
|
|
make -j$(nproc)
|
|
|
|
# Installs liburing
|
|
install-liburing:
|
|
@echo "Installing liburing (requires sudo)..."
|
|
cd /usr/local/build/liburing && sudo make install
|
|
@echo "Done! You might need to run 'sudo ldconfig' to update library cache."
|
|
|
|
# Builds bzip2
|
|
prebuild-bzip2:
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
sudo mkdir -p /usr/local/build && sudo chown -R $USER:$USER /usr/local/build
|
|
echo "Cloning and building bzip2..."
|
|
[ ! -d "/usr/local/build/bzip2" ] && git clone git://sourceware.org/git/bzip2.git /usr/local/build/bzip2 || true
|
|
cd /usr/local/build/bzip2
|
|
make -f Makefile-libbz2_so
|
|
make
|
|
|
|
# Installs bzip2
|
|
install-bzip2:
|
|
@echo "Installing bzip2 (requires sudo)..."
|
|
cd /usr/local/build/bzip2 && sudo make install PREFIX=/usr/local
|
|
cd /usr/local/build/bzip2 && sudo cp -f libbz2.so.1.0.* /usr/local/lib/
|
|
cd /usr/local/build/bzip2 && sudo ln -sf /usr/local/lib/libbz2.so.1.0.* /usr/local/lib/libbz2.so
|
|
sudo ldconfig
|
|
@echo "Done! Installed libbz2.so to /usr/local/lib"
|
|
|
|
# Pre-build jemalloc
|
|
prebuild-jemalloc:
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
TAG="5.3.0"
|
|
sudo mkdir -p /usr/local/build && sudo chown -R $USER:$USER /usr/local/build
|
|
echo "Cloning jemalloc $TAG..."
|
|
[ ! -d "/usr/local/build/jemalloc" ] && git clone --depth 1 --branch $TAG https://github.com/jemalloc/jemalloc.git /usr/local/build/jemalloc || true
|
|
echo "Building jemalloc..."
|
|
cd /usr/local/build/jemalloc
|
|
git checkout $TAG
|
|
[ -f configure ] || ./autogen.sh
|
|
[ -f Makefile ] || ./configure --prefix=/usr/local
|
|
make -j$(nproc)
|
|
|
|
# Install jemalloc globally (requires sudo)
|
|
install-jemalloc:
|
|
@echo "Installing jemalloc to /usr/local... (Requires sudo)"
|
|
cd /usr/local/build/jemalloc && sudo make install_lib_static install_lib_shared install_include
|
|
sudo ldconfig
|
|
|
|
# Pre-build lz4
|
|
prebuild-lz4:
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
VER=$(cargo pkgid lz4-sys | cut -d'@' -f2 | grep -o 'lz4-[0-9.]*' | cut -d '-' -f2)
|
|
TAG="v$VER"
|
|
sudo mkdir -p /usr/local/build && sudo chown -R $USER:$USER /usr/local/build
|
|
echo "Cloning lz4 $TAG..."
|
|
[ ! -d "/usr/local/build/lz4" ] && git clone --depth 1 --branch $TAG https://github.com/lz4/lz4.git /usr/local/build/lz4 || true
|
|
echo "Building lz4..."
|
|
cd /usr/local/build/lz4
|
|
git checkout $TAG
|
|
make lib -j$(nproc)
|
|
|
|
# Install lz4 globally (requires sudo)
|
|
install-lz4:
|
|
@echo "Installing lz4 to /usr/local... (Requires sudo)"
|
|
cd /usr/local/build/lz4 && sudo make install PREFIX=/usr/local
|
|
sudo ldconfig
|
|
|
|
# Pre-build RocksDB shared and statically
|
|
prebuild-rocksdb:
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
TAG="continuwuity-v0.5.0"
|
|
sudo mkdir -p /usr/local/build && sudo chown -R $USER:$USER /usr/local/build
|
|
echo "Cloning rocksdb $TAG..."
|
|
[ ! -d "/usr/local/build/rocksdb" ] && git clone --recursive --depth 1 --branch $TAG https://forgejo.ellis.link/continuwuation/rocksdb.git /usr/local/build/rocksdb || true
|
|
echo "Building RocksDB..."
|
|
cd /usr/local/build/rocksdb
|
|
git checkout $TAG
|
|
env DISABLE_JEMALLOC=1 EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS:-} -I/usr/local/include -Wno-error=unused-parameter" EXTRA_LDFLAGS="-L/usr/local/lib" PORTABLE=1 make shared_lib static_lib -j$(nproc)
|
|
|
|
# Install RocksDB globally (requires sudo)
|
|
install-rocksdb:
|
|
@echo "Installing RocksDB to /usr/local... (Requires sudo)"
|
|
cd /usr/local/build/rocksdb && sudo make install-shared INSTALL_PATH=/usr/local
|
|
cd /usr/local/build/rocksdb && sudo make install-static INSTALL_PATH=/usr/local
|
|
sudo ldconfig
|
|
@echo "Remember to set ROCKSDB_LIB_DIR=/usr/local/lib if Cargo doesn't see it."
|
|
|
|
# Pre-build snappy
|
|
prebuild-snappy:
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
TAG="1.2.1"
|
|
sudo mkdir -p /usr/local/build && sudo chown -R $USER:$USER /usr/local/build
|
|
echo "Cloning snappy $TAG..."
|
|
[ ! -d "/usr/local/build/snappy" ] && git clone --depth 1 --branch $TAG https://github.com/google/snappy.git /usr/local/build/snappy || true
|
|
echo "Building snappy..."
|
|
cd /usr/local/build/snappy
|
|
git checkout $TAG
|
|
sed -i 's/cmake_minimum_required(VERSION 3.1)/cmake_minimum_required(VERSION 3.10)/' CMakeLists.txt
|
|
mkdir -p build_static && cd build_static
|
|
cmake -DBUILD_SHARED_LIBS=OFF -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF ..
|
|
make -j$(nproc)
|
|
cd ..
|
|
mkdir -p build_shared && cd build_shared
|
|
cmake -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF ..
|
|
make -j$(nproc)
|
|
|
|
# Install snappy globally (requires sudo)
|
|
install-snappy:
|
|
@echo "Installing snappy to /usr/local... (Requires sudo)"
|
|
cd /usr/local/build/snappy/build_static && sudo make install
|
|
cd /usr/local/build/snappy/build_shared && sudo make install
|
|
sudo ldconfig
|
|
|
|
# Pre-build zstd
|
|
prebuild-zstd:
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
VER=$(cargo pkgid zstd-sys | cut -d'@' -f2 | grep -o 'zstd\.[0-9.]*' | cut -d '.' -f2-)
|
|
TAG="v$VER"
|
|
sudo mkdir -p /usr/local/build && sudo chown -R $USER:$USER /usr/local/build
|
|
echo "Cloning zstd $TAG..."
|
|
[ ! -d "/usr/local/build/zstd" ] && git clone --depth 1 --branch $TAG https://github.com/facebook/zstd.git /usr/local/build/zstd || true
|
|
echo "Building zstd..."
|
|
cd /usr/local/build/zstd
|
|
git checkout $TAG
|
|
make lib-release -j$(nproc)
|
|
|
|
# Install zstd globally (requires sudo)
|
|
install-zstd:
|
|
@echo "Installing zstd to /usr/local... (Requires sudo)"
|
|
cd /usr/local/build/zstd && sudo make install -C lib PREFIX=/usr/local
|
|
sudo ldconfig
|
|
|
|
# --- CPU Profiling ---
|
|
|
|
# Run CPU flamegraph profiling on release build (requires sudo for perf)
|
|
profile-runtime-cpu *args:
|
|
cargo flamegraph --root --features local_profiling --bin conduwuit -- {{args}}
|
|
@echo "Flamegraph saved to flamegraph.svg"
|
|
|
|
# Run CPU flamegraph profiling on dev build (requires sudo for perf)
|
|
profile-runtime-cpu-dev *args:
|
|
cargo flamegraph --root --dev --features local_profiling --bin conduwuit -- {{args}}
|
|
@echo "Flamegraph saved to flamegraph.svg"
|
|
|
|
# --- Async & I/O Profiling ---
|
|
|
|
# Run with tokio-console instrumentation active
|
|
profile-runtime-async *args:
|
|
@echo "Run 'tokio-console' in a separate terminal"
|
|
env RUSTFLAGS="--cfg tokio_unstable ${RUSTFLAGS:-}" cargo run --features local_profiling --bin conduwuit -- {{args}}
|
|
|
|
# --- Memory Profiling (jemalloc) ---
|
|
|
|
# Run release build and dump jemalloc heap profiles
|
|
profile-runtime-mem *args:
|
|
cargo build --release --features local_profiling --bin conduwuit
|
|
@echo "Starting with jemalloc profiling..."
|
|
env MALLOC_CONF="prof:true,lg_prof_interval:24,prof_prefix:jeprof.out" ./target/release/conduwuit {{args}}
|
|
|
|
# Generate heap_profile.svg from collected jemalloc dumps
|
|
profile-runtime-mem-analyze:
|
|
jeprof --svg ./target/release/conduwuit jeprof.out.*
|
|
@echo "Saved heap_profile.svg"
|
|
|
|
# Clean up jemalloc dump files
|
|
profile-runtime-mem-clean:
|
|
rm -f jeprof.out.* heap_profile.svg
|
|
|
|
# --- Compile-time Profiling ---
|
|
|
|
# Profile cargo build times
|
|
profile-build-times:
|
|
cargo build --profile ${PROFILE:-release} --timings
|
|
@echo "Report saved to target/cargo-timings/"
|
|
|
|
# Analyze binary size by crates
|
|
profile-build-bloat-crates:
|
|
cargo bloat --profile ${PROFILE:-release} -p conduwuit --crates
|
|
|
|
# Analyze binary size by functions
|
|
profile-build-bloat-functions:
|
|
cargo bloat --profile ${PROFILE:-release} -p conduwuit --bin conduwuit -n 50
|
|
|
|
# Analyze generic instantiation (Monomorphization)
|
|
profile-build-llvm-lines:
|
|
cargo llvm-lines --profile ${PROFILE:-release} -p conduwuit --lib
|
|
|
|
# --- Cross Compilation ---
|
|
|
|
# Cross-compile using cargo-zigbuild for specific glibc versions
|
|
# Usage: just build-cross-compile <target-glibc-version> <cpu-arch>
|
|
# Example: just build-cross-compile 2.36 skylake
|
|
build-cross-compile glibc_version="2.36" cpu_arch="skylake":
|
|
@echo "Building for glibc {{glibc_version}} with CPU target {{cpu_arch}} using cargo-zigbuild..."
|
|
@if ! command -v cargo-zigbuild >/dev/null 2>&1; then \
|
|
echo "Error: cargo-zigbuild is not installed. Run: cargo install cargo-zigbuild"; \
|
|
exit 1; \
|
|
fi
|
|
@if ! command -v zig >/dev/null 2>&1; then \
|
|
echo "Error: zig is not installed. Run: sudo pacman -S zig (or your package manager's equivalent)"; \
|
|
exit 1; \
|
|
fi
|
|
rustup target add x86_64-unknown-linux-gnu
|
|
env RUSTFLAGS="-C target-cpu={{cpu_arch}}" cargo zigbuild --release --target x86_64-unknown-linux-gnu.{{glibc_version}}
|
|
|
|
# Extracts the workspace version from Cargo.toml
|
|
version := "$(grep -m1 '^version = ' Cargo.toml | cut -d \" -f 2)"
|
|
|
|
# Start gdbserver for lightweight remote debugging (POC)
|
|
# Usage: just remote-debug-poc /path/to/conduwuit.toml
|
|
remote-debug-poc config="conduwuit-example.toml":
|
|
@echo "Starting gdbserver on :1234 using config: {{config}}"
|
|
sudo -u conduwuit gdbserver :1234 ./target/debug/continuwuity --config {{config}}
|
|
|
|
# Run Complement tests (requires complement-src)
|
|
# Usage: just complement TestName
|
|
complement args=".":
|
|
env COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_RUN="{{args}}" ./bin/complement ./complement-src
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Complement CI
|
|
# -----------------------------------------------------------------------------
|
|
|
|
COMPLEMENT_IMAGE := env_var_or_default("COMPLEMENT_IMAGE", "continuwuity:complement")
|
|
COMPLEMENT_BASE_IMAGE := env_var_or_default("COMPLEMENT_BASE_IMAGE", "ubuntu:latest")
|
|
PROFILE := env_var_or_default("PROFILE", "release")
|
|
|
|
# Build docker image from existing binary
|
|
ci-complement-docker:
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
echo "Copying dynamically linked libraries to target/{{PROFILE}}/lib/..."
|
|
mkdir -p target/{{PROFILE}}/lib && rm -f target/{{PROFILE}}/lib/*
|
|
|
|
LD_LIBRARY_PATH="${ROCKSDB_LIB_DIR:-}:$(echo ${LD_LIBRARY_PATH:-})" \
|
|
ldd target/latest/conduwuit | awk '/=> \// {print $3}' \
|
|
| grep -vE 'libc\.so|libm\.so|libgcc_s\.so|libstdc\+\+\.so|ld-linux|libdl\.so|libpthread\.so|librt\.so' \
|
|
| xargs -I {} cp "{}" target/{{PROFILE}}/lib/ || true
|
|
|
|
rm -rf target/latest/lib
|
|
ln -sfn ../{{PROFILE}}/lib target/latest/lib
|
|
|
|
echo "Building Complement Docker image using base image: {{COMPLEMENT_BASE_IMAGE}}..."
|
|
DOCKER_BUILDKIT=1 docker buildx build \
|
|
--build-arg BASE_IMAGE={{COMPLEMENT_BASE_IMAGE}} \
|
|
--build-arg BINARY_PATH=target/latest/conduwuit \
|
|
--build-arg LIB_PATH=target/{{PROFILE}}/lib \
|
|
--build-arg UID="$(id -u)" \
|
|
--build-arg GID="$(id -g)" \
|
|
-t {{COMPLEMENT_IMAGE}} \
|
|
-f ./docker/complement.Dockerfile \
|
|
--load .
|
|
|
|
# Aggregates test results generated by complement
|
|
ci-complement-stats:
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
RESULTS="tests/test_results/complement/test_results.jsonl"
|
|
if [ ! -f "$RESULTS" ]; then
|
|
echo "ERROR: $RESULTS does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Parsing Complement test results..."
|
|
PASS=$(jq -s '[.[] | select(.Action == "pass")] | length' "$RESULTS")
|
|
FAIL=$(jq -s '[.[] | select(.Action == "fail")] | length' "$RESULTS")
|
|
SKIP=$(jq -s '[.[] | select(.Action == "skip")] | length' "$RESULTS")
|
|
TOTAL=$((PASS + FAIL + SKIP))
|
|
|
|
echo ""
|
|
if [ "$FAIL" -gt 0 ] && [ "${VERBOSE:-0}" = "1" ]; then
|
|
echo "Failed Tests:"
|
|
jq -r 'select(.Action == "fail") | .Test' "$RESULTS" | sort -u
|
|
echo ""
|
|
fi
|
|
|
|
echo "=== Complement Test Stats ==="
|
|
echo "✓ Passed: $PASS"
|
|
echo "✗ Failed: $FAIL"
|
|
echo "⚠ Skipped: $SKIP"
|
|
echo "Overall: $TOTAL tests"
|
|
|
|
echo ""
|
|
echo "Last modified by:"
|
|
git log -5 --format="%an (%ad) %H" origin/main -- tests/test_results/complement/test_results.jsonl
|