v0.1.0 - New minor version
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
nostr_core_lib/
|
nostr_core_lib/
|
||||||
nips/
|
nips/
|
||||||
|
build/
|
||||||
|
|||||||
122
Makefile
122
Makefile
@@ -5,27 +5,108 @@ CFLAGS = -Wall -Wextra -std=c99 -g -O2
|
|||||||
INCLUDES = -I. -Inostr_core_lib -Inostr_core_lib/nostr_core -Inostr_core_lib/cjson -Inostr_core_lib/nostr_websocket
|
INCLUDES = -I. -Inostr_core_lib -Inostr_core_lib/nostr_core -Inostr_core_lib/cjson -Inostr_core_lib/nostr_websocket
|
||||||
LIBS = -lsqlite3 -lwebsockets -lz -ldl -lpthread -lm -L/usr/local/lib -lsecp256k1 -lssl -lcrypto -L/usr/local/lib -lcurl
|
LIBS = -lsqlite3 -lwebsockets -lz -ldl -lpthread -lm -L/usr/local/lib -lsecp256k1 -lssl -lcrypto -L/usr/local/lib -lcurl
|
||||||
|
|
||||||
|
# Build directory
|
||||||
|
BUILD_DIR = build
|
||||||
|
|
||||||
# Source files
|
# Source files
|
||||||
MAIN_SRC = src/main.c
|
MAIN_SRC = src/main.c
|
||||||
NOSTR_CORE_LIB = nostr_core_lib/libnostr_core_x64.a
|
NOSTR_CORE_LIB = nostr_core_lib/libnostr_core_x64.a
|
||||||
|
|
||||||
# Target binary
|
# Architecture detection
|
||||||
TARGET = src/main
|
ARCH = $(shell uname -m)
|
||||||
|
ifeq ($(ARCH),x86_64)
|
||||||
|
TARGET = $(BUILD_DIR)/c_relay_x86
|
||||||
|
else ifeq ($(ARCH),aarch64)
|
||||||
|
TARGET = $(BUILD_DIR)/c_relay_arm64
|
||||||
|
else ifeq ($(ARCH),arm64)
|
||||||
|
TARGET = $(BUILD_DIR)/c_relay_arm64
|
||||||
|
else
|
||||||
|
TARGET = $(BUILD_DIR)/c_relay_$(ARCH)
|
||||||
|
endif
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
# Create build directory
|
||||||
|
$(BUILD_DIR):
|
||||||
|
mkdir -p $(BUILD_DIR)
|
||||||
|
|
||||||
# Check if nostr_core_lib is built
|
# Check if nostr_core_lib is built
|
||||||
$(NOSTR_CORE_LIB):
|
$(NOSTR_CORE_LIB):
|
||||||
@echo "Building nostr_core_lib..."
|
@echo "Building nostr_core_lib..."
|
||||||
cd nostr_core_lib && ./build.sh
|
cd nostr_core_lib && ./build.sh
|
||||||
|
|
||||||
# Build the relay
|
# Build the relay
|
||||||
$(TARGET): $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
$(TARGET): $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
||||||
@echo "Compiling C-Relay..."
|
@echo "Compiling C-Relay for architecture: $(ARCH)"
|
||||||
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(TARGET) $(NOSTR_CORE_LIB) $(LIBS)
|
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(TARGET) $(NOSTR_CORE_LIB) $(LIBS)
|
||||||
@echo "Build complete: $(TARGET)"
|
@echo "Build complete: $(TARGET)"
|
||||||
|
|
||||||
|
# Build for specific architectures
|
||||||
|
x86: $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
||||||
|
@echo "Building C-Relay for x86_64..."
|
||||||
|
$(CC) $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(BUILD_DIR)/c_relay_x86 $(NOSTR_CORE_LIB) $(LIBS)
|
||||||
|
@echo "Build complete: $(BUILD_DIR)/c_relay_x86"
|
||||||
|
|
||||||
|
arm64: $(BUILD_DIR) $(MAIN_SRC) $(NOSTR_CORE_LIB)
|
||||||
|
@echo "Cross-compiling C-Relay for ARM64..."
|
||||||
|
@if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then \
|
||||||
|
echo "ERROR: ARM64 cross-compiler not found."; \
|
||||||
|
echo "Install with: make install-cross-tools"; \
|
||||||
|
echo "Or install manually: sudo apt install gcc-aarch64-linux-gnu"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@echo "Checking for ARM64 development libraries..."
|
||||||
|
@if ! dpkg -l | grep -q "libssl-dev:arm64\|libsqlite3-dev:arm64"; then \
|
||||||
|
echo "ERROR: ARM64 libraries not found. Cross-compilation requires ARM64 versions of:"; \
|
||||||
|
echo " - libssl-dev:arm64"; \
|
||||||
|
echo " - libsqlite3-dev:arm64"; \
|
||||||
|
echo " - libwebsockets-dev:arm64"; \
|
||||||
|
echo " - libsecp256k1-dev:arm64"; \
|
||||||
|
echo " - zlib1g-dev:arm64"; \
|
||||||
|
echo " - libcurl4-openssl-dev:arm64"; \
|
||||||
|
echo ""; \
|
||||||
|
echo "Install ARM64 libraries with: make install-arm64-deps"; \
|
||||||
|
echo "Or use Docker for cross-platform builds."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@echo "Using aarch64-linux-gnu-gcc with ARM64 libraries..."
|
||||||
|
PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig \
|
||||||
|
aarch64-linux-gnu-gcc $(CFLAGS) $(INCLUDES) $(MAIN_SRC) -o $(BUILD_DIR)/c_relay_arm64 $(NOSTR_CORE_LIB) \
|
||||||
|
-L/usr/lib/aarch64-linux-gnu $(LIBS)
|
||||||
|
@echo "Build complete: $(BUILD_DIR)/c_relay_arm64"
|
||||||
|
|
||||||
|
# Install ARM64 cross-compilation dependencies
|
||||||
|
install-arm64-deps:
|
||||||
|
@echo "Installing ARM64 cross-compilation dependencies..."
|
||||||
|
@echo "This requires adding ARM64 architecture and installing cross-libraries..."
|
||||||
|
sudo dpkg --add-architecture arm64
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y \
|
||||||
|
gcc-aarch64-linux-gnu \
|
||||||
|
libc6-dev-arm64-cross \
|
||||||
|
libssl-dev:arm64 \
|
||||||
|
libsqlite3-dev:arm64 \
|
||||||
|
zlib1g-dev:arm64 \
|
||||||
|
libcurl4-openssl-dev:arm64
|
||||||
|
@echo "Note: libwebsockets-dev:arm64 and libsecp256k1-dev:arm64 may need manual building"
|
||||||
|
|
||||||
|
# Install cross-compilation tools
|
||||||
|
install-cross-tools:
|
||||||
|
@echo "Installing cross-compilation tools..."
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross
|
||||||
|
|
||||||
|
# Check what architectures we can actually build
|
||||||
|
check-toolchain:
|
||||||
|
@echo "Checking available toolchains:"
|
||||||
|
@echo "Native compiler: $(shell $(CC) --version | head -1)"
|
||||||
|
@if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then \
|
||||||
|
echo "ARM64 cross-compiler: $(shell aarch64-linux-gnu-gcc --version | head -1)"; \
|
||||||
|
else \
|
||||||
|
echo "ARM64 cross-compiler: NOT INSTALLED (install with 'make install-cross-tools')"; \
|
||||||
|
fi
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
test: $(TARGET)
|
test: $(TARGET)
|
||||||
@echo "Running tests..."
|
@echo "Running tests..."
|
||||||
@@ -38,7 +119,7 @@ init-db:
|
|||||||
|
|
||||||
# Clean build artifacts
|
# Clean build artifacts
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TARGET)
|
rm -rf $(BUILD_DIR)
|
||||||
@echo "Clean complete"
|
@echo "Clean complete"
|
||||||
|
|
||||||
# Clean everything including nostr_core_lib
|
# Clean everything including nostr_core_lib
|
||||||
@@ -56,17 +137,26 @@ help:
|
|||||||
@echo "C-Relay Build System"
|
@echo "C-Relay Build System"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Targets:"
|
@echo "Targets:"
|
||||||
@echo " all Build the relay (default)"
|
@echo " all Build the relay for current architecture (default)"
|
||||||
@echo " test Build and run tests"
|
@echo " x86 Build specifically for x86_64"
|
||||||
@echo " init-db Initialize the database"
|
@echo " arm64 Build for ARM64 (requires cross-compilation setup)"
|
||||||
@echo " clean Clean build artifacts"
|
@echo " test Build and run tests"
|
||||||
@echo " clean-all Clean everything including dependencies"
|
@echo " init-db Initialize the database"
|
||||||
@echo " install-deps Install system dependencies"
|
@echo " clean Clean build artifacts"
|
||||||
@echo " help Show this help"
|
@echo " clean-all Clean everything including dependencies"
|
||||||
|
@echo " install-deps Install system dependencies"
|
||||||
|
@echo " install-cross-tools Install basic ARM64 cross-compiler"
|
||||||
|
@echo " install-arm64-deps Install ARM64 cross-compilation libraries"
|
||||||
|
@echo " check-toolchain Check available compilers"
|
||||||
|
@echo " help Show this help"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Usage:"
|
@echo "Usage:"
|
||||||
@echo " make # Build the relay"
|
@echo " make # Build the relay for current arch"
|
||||||
@echo " make test # Run tests"
|
@echo " make x86 # Build for x86_64"
|
||||||
@echo " make init-db # Set up database"
|
@echo " make arm64 # Build for ARM64 (fails if cross-compilation not set up)"
|
||||||
|
@echo " make install-arm64-deps # Install full ARM64 cross-compilation setup"
|
||||||
|
@echo " make check-toolchain # Check what compilers are available"
|
||||||
|
@echo " make test # Run tests"
|
||||||
|
@echo " make init-db # Set up database"
|
||||||
|
|
||||||
.PHONY: all test init-db clean clean-all install-deps help
|
.PHONY: all x86 arm64 test init-db clean clean-all install-deps install-cross-tools install-arm64-deps check-toolchain help
|
||||||
@@ -60,7 +60,7 @@ show_usage() {
|
|||||||
echo " - Git add, commit, push, and create Gitea release"
|
echo " - Git add, commit, push, and create Gitea release"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Requirements for Release Mode:"
|
echo "Requirements for Release Mode:"
|
||||||
echo " - ARM64 cross-compiler: sudo apt install gcc-aarch64-linux-gnu"
|
echo " - For ARM64 builds: make install-arm64-deps (optional - will build x86_64 only if missing)"
|
||||||
echo " - Gitea token in ~/.gitea_token for release uploads"
|
echo " - Gitea token in ~/.gitea_token for release uploads"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,16 +148,6 @@ compile_project() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for ARM64 cross-compiler
|
|
||||||
check_cross_compiler() {
|
|
||||||
if ! command -v aarch64-linux-gnu-gcc > /dev/null 2>&1; then
|
|
||||||
print_error "ARM64/AArch64 cross-compiler not found!"
|
|
||||||
print_error "Install with: sudo apt install gcc-aarch64-linux-gnu"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to build release binaries
|
# Function to build release binaries
|
||||||
build_release_binaries() {
|
build_release_binaries() {
|
||||||
print_status "Building release binaries..."
|
print_status "Building release binaries..."
|
||||||
@@ -165,9 +155,9 @@ build_release_binaries() {
|
|||||||
# Build x86_64 version
|
# Build x86_64 version
|
||||||
print_status "Building x86_64 version..."
|
print_status "Building x86_64 version..."
|
||||||
make clean > /dev/null 2>&1
|
make clean > /dev/null 2>&1
|
||||||
if make CC=gcc > /dev/null 2>&1; then
|
if make x86 > /dev/null 2>&1; then
|
||||||
if [[ -f "src/main" ]]; then
|
if [[ -f "build/c_relay_x86" ]]; then
|
||||||
cp src/main c-relay-x86_64
|
cp build/c_relay_x86 c-relay-x86_64
|
||||||
print_success "x86_64 binary created: c-relay-x86_64"
|
print_success "x86_64 binary created: c-relay-x86_64"
|
||||||
else
|
else
|
||||||
print_error "x86_64 binary not found after compilation"
|
print_error "x86_64 binary not found after compilation"
|
||||||
@@ -178,25 +168,19 @@ build_release_binaries() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for ARM64 cross-compiler
|
# Try to build ARM64 version
|
||||||
if check_cross_compiler; then
|
print_status "Attempting ARM64 build..."
|
||||||
# Build ARM64 version
|
make clean > /dev/null 2>&1
|
||||||
print_status "Building ARM64 version..."
|
if make arm64 > /dev/null 2>&1; then
|
||||||
make clean > /dev/null 2>&1
|
if [[ -f "build/c_relay_arm64" ]]; then
|
||||||
if make CC=aarch64-linux-gnu-gcc > /dev/null 2>&1; then
|
cp build/c_relay_arm64 c-relay-arm64
|
||||||
if [[ -f "src/main" ]]; then
|
print_success "ARM64 binary created: c-relay-arm64"
|
||||||
cp src/main c-relay-arm64
|
|
||||||
print_success "ARM64 binary created: c-relay-arm64"
|
|
||||||
else
|
|
||||||
print_error "ARM64 binary not found after compilation"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
print_error "ARM64 build failed"
|
print_warning "ARM64 binary not found after compilation"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
print_warning "ARM64 cross-compiler not available, skipping ARM64 build"
|
print_warning "ARM64 build failed - ARM64 cross-compilation not properly set up"
|
||||||
|
print_status "Only x86_64 binary will be included in release"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Restore normal build
|
# Restore normal build
|
||||||
|
|||||||
@@ -15,9 +15,22 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if relay binary exists after build
|
# Check if relay binary exists after build - detect architecture
|
||||||
if [ ! -f "./src/main" ]; then
|
ARCH=$(uname -m)
|
||||||
echo "ERROR: Relay binary not found after build. Build may have failed."
|
case "$ARCH" in
|
||||||
|
x86_64)
|
||||||
|
BINARY_PATH="./build/c_relay_x86"
|
||||||
|
;;
|
||||||
|
aarch64|arm64)
|
||||||
|
BINARY_PATH="./build/c_relay_arm64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
BINARY_PATH="./build/c_relay_$ARCH"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! -f "$BINARY_PATH" ]; then
|
||||||
|
echo "ERROR: Relay binary not found at $BINARY_PATH after build. Build may have failed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -25,7 +38,7 @@ echo "Build successful. Proceeding with relay restart..."
|
|||||||
|
|
||||||
# Kill existing relay if running
|
# Kill existing relay if running
|
||||||
echo "Stopping any existing relay servers..."
|
echo "Stopping any existing relay servers..."
|
||||||
pkill -f "./src/main" 2>/dev/null
|
pkill -f "c_relay_" 2>/dev/null
|
||||||
sleep 2 # Give time for shutdown
|
sleep 2 # Give time for shutdown
|
||||||
|
|
||||||
# Check if port is still bound
|
# Check if port is still bound
|
||||||
@@ -35,7 +48,7 @@ if lsof -i :8888 >/dev/null 2>&1; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Get any remaining processes
|
# Get any remaining processes
|
||||||
REMAINING_PIDS=$(pgrep -f "./src/main" || echo "")
|
REMAINING_PIDS=$(pgrep -f "c_relay_" || echo "")
|
||||||
if [ -n "$REMAINING_PIDS" ]; then
|
if [ -n "$REMAINING_PIDS" ]; then
|
||||||
echo "Force killing remaining processes: $REMAINING_PIDS"
|
echo "Force killing remaining processes: $REMAINING_PIDS"
|
||||||
kill -9 $REMAINING_PIDS 2>/dev/null
|
kill -9 $REMAINING_PIDS 2>/dev/null
|
||||||
@@ -55,10 +68,10 @@ fi
|
|||||||
|
|
||||||
# Start relay in background with output redirection
|
# Start relay in background with output redirection
|
||||||
echo "Starting relay server..."
|
echo "Starting relay server..."
|
||||||
echo "Debug: Current processes: $(ps aux | grep './src/main' | grep -v grep || echo 'None')"
|
echo "Debug: Current processes: $(ps aux | grep 'c_relay_' | grep -v grep || echo 'None')"
|
||||||
|
|
||||||
# Start relay in background and capture its PID
|
# Start relay in background and capture its PID
|
||||||
./src/main > relay.log 2>&1 &
|
$BINARY_PATH > relay.log 2>&1 &
|
||||||
RELAY_PID=$!
|
RELAY_PID=$!
|
||||||
|
|
||||||
echo "Started with PID: $RELAY_PID"
|
echo "Started with PID: $RELAY_PID"
|
||||||
@@ -78,9 +91,10 @@ if ps -p "$RELAY_PID" >/dev/null 2>&1; then
|
|||||||
echo $RELAY_PID > relay.pid
|
echo $RELAY_PID > relay.pid
|
||||||
|
|
||||||
echo "=== Relay server running in background ==="
|
echo "=== Relay server running in background ==="
|
||||||
echo "To kill relay: pkill -f './src/main'"
|
echo "To kill relay: pkill -f 'c_relay_'"
|
||||||
echo "To check status: ps aux | grep src/main"
|
echo "To check status: ps aux | grep c_relay_"
|
||||||
echo "To view logs: tail -f relay.log"
|
echo "To view logs: tail -f relay.log"
|
||||||
|
echo "Binary: $BINARY_PATH"
|
||||||
echo "Ready for Nostr client connections!"
|
echo "Ready for Nostr client connections!"
|
||||||
else
|
else
|
||||||
echo "ERROR: Relay failed to start"
|
echo "ERROR: Relay failed to start"
|
||||||
|
|||||||
1
otp
Submodule
1
otp
Submodule
Submodule otp added at 3d990091eb
Reference in New Issue
Block a user