Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .ci/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
GCC_VERSION=14
LINUX_PACKAGES="make \
autoconf \
automake \
build-essential \
cargo \
curl \
git \
golang-go \
libtool \
nasm \
ninja-build \
pkg-config \
python3.12 \
python3.12-dev \
python3.12-venv \
python3-pip \
gcc-$GCC_VERSION \
g++-$GCC_VERSION \
unzip \
zip \
nano"

MACOS_PACKAGES="make \
autoconf \
automake \
rust \
curl \
git \
go \
libtool \
nasm \
ninja \
pkg-config \
[email protected] \
unzip \
zip"

CMAKE_VERSION=3.31.1
DEBIAN_FRONTEND=noninteractive
#VCPKG_FORCE_SYSTEM_BINARIES=1
23 changes: 23 additions & 0 deletions .ci/scripts/detect_os.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt >/dev/null 2>&1; then
echo "linux_deb"
else
echo "linux_other"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
else
echo "unknown"
fi
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script is intended to be sourced or used as a library."
echo "Exported functions: detect_os"
exit 1
fi
40 changes: 40 additions & 0 deletions .ci/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x
trap 'echo "=== Error on line $LINENO"; exit 1' ERR

SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
OS_SELECT=$(source ${SCRIPT_DIR}/detect_os.sh && detect_os)

set -o allexport && . ${SCRIPT_DIR}/../.env && set +o allexport

main() {
case "$OS_SELECT" in
linux_deb)
echo "=== Detected Linux system with apt"
apt update && apt install -y $LINUX_PACKAGES
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 90
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-$GCC_VERSION 90
;;
linux_other)
echo "=== Detected Linux system without apt"
echo "=== Support for other package managers is not added"
;;
macos)
echo "=== Detected macOS system"
if command -v brew >/dev/null 2>&1; then
echo "=== Homebrew found. Installing packages..."
brew update && brew install $MACOS_PACKAGES
else
echo "=== Homebrew is not installed. Install it before proceeding: https://brew.sh"
fi
;;
*)
echo "=== Unknown system"
;;
esac
}

main

exit 0
17 changes: 17 additions & 0 deletions .ci/scripts/init_py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

init_py() {
echo "$VENV"
python3 -m venv "$VENV"
source $VENV/bin/activate
pip3 install cmake==${CMAKE_VERSION}
pip3 install --no-cache-dir asn1tools
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script is intended to be sourced or used as a library."
echo "Exported functions: init_py"
exit 1
fi
23 changes: 23 additions & 0 deletions .ci/scripts/init_vcpkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

init_vcpkg() {
if [[ ! -d $VCPKG || -z "$(ls -A $VCPKG 2>/dev/null)" ]]; then
echo "Directory $VCPKG does not exist or is empty. Cloning vcpkg..."
git clone https://github.com/microsoft/vcpkg.git $VCPKG
fi

if [[ ! -e $VCPKG/vcpkg ]]; then
echo "vcpkg executable not found. Bootstrapping vcpkg..."
$VCPKG/bootstrap-vcpkg.sh -disableMetrics
fi

echo "vcpkg is initialized at $VCPKG."
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script is intended to be sourced or used as a library."
echo "Exported functions: init_vcpkg"
exit 1
fi
85 changes: 85 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Run Tests

on:
push:
branches:
- master
pull_request:
workflow_dispatch:
inputs:
use_cache:
description: 'Use cache for build'
required: true
default: 'true'
type: 'choice'
options:
- 'true'
- 'false'

env:
USE_CACHE: ${{ github.event.inputs.use_cache || 'true' }}
CACHE_VERSION: v02
CACHE_PATH: |
~/.hunter
~/.cache/pip
~/.cache/vcpkg
.vcpkg
.venv
.build


jobs:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-24.04, macos-15]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: "Restore cache dependencies"
id: cache-restore
if: ${{ env.USE_CACHE == 'true' }}
uses: actions/cache/restore@v4
with:
path: ${{ env.CACHE_PATH }}
key: lean-${{ runner.os }}-${{ github.job }}-${{ env.CACHE_VERSION }}-${{ github.run_id }}
restore-keys: |
lean-${{ runner.os }}-${{ github.job }}-${{ env.CACHE_VERSION }}
lean-${{ runner.os }}-${{ github.job }}
lean-${{ runner.os }}

- name: "Basic init"
run: |
if [[ $RUNNER_OS == "Linux" ]]; then
sudo ./.ci/scripts/init.sh
else
./.ci/scripts/init.sh
fi

- name: "Init all dependencies"
run: |
make init_py
make init_vcpkg

- name: "Configure"
run: make configure

- name: "Build"
run: make build

- name: "Test"
run: make test

- name: "Always Save Cache"
id: cache-save
if: always() && ( steps.cache-restore.outputs.cache-hit != 'true' )
uses: actions/cache/save@v4
with:
path: ${{ env.CACHE_PATH }}
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.25)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
project(leanp2p)

set(CMAKE_CXX_STANDARD 23)
Expand Down
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SHELL := /bin/bash
PROJECT := $(shell pwd)
CI_DIR := $(PROJECT)/.ci

VENV ?= $(PROJECT)/.venv
BUILD ?= $(PROJECT)/.build
VCPKG ?= $(PROJECT)/.vcpkg
PATH = $(VENV)/bin:$(shell echo $$PATH)

ifneq (,$(wildcard $(CI_DIR)/.env))
include $(CI_DIR)/.env
export
endif

OS_TYPE := $(shell bash -c 'source $(CI_DIR)/scripts/detect_os.sh && detect_os')


all: init_all configure build test

init_all: init init_py init_vcpkg

os:
@echo "=== Detected OS: $(OS_TYPE)"

init:
@echo "=== Initializing..."
$(CI_DIR)/scripts/init.sh

init_py:
@echo "=== Initializing Python..."
source $(CI_DIR)/scripts/init_py.sh && init_py

init_vcpkg:
@echo "=== Initializing Vcpkg..."
source $(CI_DIR)/scripts/init_vcpkg.sh && init_vcpkg

configure:
@echo "=== Configuring..."
VCPKG_ROOT=$(VCPKG) cmake --preset=default -DPython3_EXECUTABLE="$(VENV)/bin/python3" -B $(BUILD) $(PROJECT)

build:
@echo "=== Building..."
cmake --build $(BUILD)

test:
@echo "=== Testing..."
ctest --test-dir $(BUILD)

clean_all:
@echo "=== Cleaning..."
rm -rf $(VENV) $(BUILD) $(VCPKG)

.PHONY: all init_all os init init_py init_vcpkg configure build test clean_all
4 changes: 2 additions & 2 deletions include/libp2p/coro/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace libp2p {
class CoroOutcomeChannel {
public:
CoroOutcome<T> receive() {
co_return (co_await channel_.async_receive(boost::asio::use_awaitable))
.value();
auto result = co_await channel_.async_receive(boost::asio::use_awaitable);
co_return result.value();
}

void send(outcome::result<T> result) {
Expand Down
1 change: 1 addition & 0 deletions include/libp2p/transport/tcp/tcp_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace libp2p::transport::detail {
return dns;
}
default:
break;
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Adding a break statement in the default case of a switch where all other cases return is unnecessary. The break statement serves no purpose here since the function will return immediately after the switch block anyway.

Suggested change
break;
// no-op

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was needed to fix gcc-14 build

}
return std::errc::protocol_not_supported;
}
Expand Down
Loading
Loading