mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-02-16 12:03:08 +00:00
Merge 733772c5e574737cb24d0eb04407b96d4a8f8d5e into 5525f2fb33b182b80aa3148f842731bc29094fba
This commit is contained in:
commit
c65c1ff8a0
106
.github/workflows/ci.yml
vendored
Normal file
106
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths-ignore:
|
||||
- "**README.md"
|
||||
- ".gitignore"
|
||||
- "LICENSE"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
# Cache the Nim compiler built by nimbus-build-system (NBS).
|
||||
# Building Nim from source is the slowest part of `make update`.
|
||||
# Keyed on the NBS submodule commit — auto-invalidates when NBS is bumped.
|
||||
- id: nbs
|
||||
run: echo "hash=$(git rev-parse HEAD:vendor/nimbus-build-system)" >> $GITHUB_OUTPUT
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor/nimbus-build-system/vendor/Nim
|
||||
key: ${{ runner.os }}-nbs-${{ steps.nbs.outputs.hash }}
|
||||
- run: make update
|
||||
- run: make all
|
||||
|
||||
test:
|
||||
needs: build
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
- id: nbs
|
||||
run: echo "hash=$(git rev-parse HEAD:vendor/nimbus-build-system)" >> $GITHUB_OUTPUT
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor/nimbus-build-system/vendor/Nim
|
||||
key: ${{ runner.os }}-nbs-${{ steps.nbs.outputs.hash }}
|
||||
- run: make update
|
||||
- run: make tests
|
||||
|
||||
test-windows:
|
||||
needs: build
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
env:
|
||||
MSYSTEM: MINGW64
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
update: true
|
||||
install: >-
|
||||
git
|
||||
base-devel
|
||||
mingw-w64-x86_64-toolchain
|
||||
make
|
||||
cmake
|
||||
upx
|
||||
mingw-w64-x86_64-rust
|
||||
mingw-w64-x86_64-postgresql
|
||||
mingw-w64-x86_64-gcc
|
||||
mingw-w64-x86_64-gcc-libs
|
||||
mingw-w64-x86_64-libwinpthread-git
|
||||
mingw-w64-x86_64-zlib
|
||||
mingw-w64-x86_64-openssl
|
||||
mingw-w64-x86_64-python
|
||||
mingw-w64-x86_64-cmake
|
||||
mingw-w64-x86_64-llvm
|
||||
mingw-w64-x86_64-clang
|
||||
- run: |
|
||||
echo "/usr/bin:$PATH" >> $GITHUB_PATH
|
||||
echo "/mingw64/bin:$PATH" >> $GITHUB_PATH
|
||||
echo "/usr/lib:$PATH" >> $GITHUB_PATH
|
||||
echo "/mingw64/lib:$PATH" >> $GITHUB_PATH
|
||||
- run: which upx gcc g++ make cmake cargo rustc python make mingw32-make
|
||||
- id: nbs
|
||||
run: echo "hash=$(git rev-parse HEAD:vendor/nimbus-build-system)" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor/nimbus-build-system/vendor/Nim
|
||||
key: ${{ runner.os }}-nbs-${{ steps.nbs.outputs.hash }}
|
||||
- run: make update
|
||||
- run: |
|
||||
cd vendor/nwaku/vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc
|
||||
make -f Makefile.mingw CC=gcc CXX=g++ libminiupnpc.a V=1
|
||||
- run: |
|
||||
cd vendor/nwaku/vendor/nim-nat-traversal/vendor/libnatpmp-upstream
|
||||
make CC="gcc -fPIC -D_WIN32_WINNT=0x0600 -DNATPMP_STATICLIB" libnatpmp.a V=1
|
||||
- run: make tests
|
||||
76
.github/workflows/test-windows.yml
vendored
76
.github/workflows/test-windows.yml
vendored
@ -1,76 +0,0 @@
|
||||
name: test-windows
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths-ignore:
|
||||
- '**README.md'
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
jobs:
|
||||
tests-tasks:
|
||||
runs-on: windows-latest
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
|
||||
env:
|
||||
MSYSTEM: MINGW64
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup MSYS2
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
update: true
|
||||
install: >-
|
||||
git
|
||||
base-devel
|
||||
mingw-w64-x86_64-toolchain
|
||||
make
|
||||
cmake
|
||||
upx
|
||||
mingw-w64-x86_64-rust
|
||||
mingw-w64-x86_64-postgresql
|
||||
mingw-w64-x86_64-gcc
|
||||
mingw-w64-x86_64-gcc-libs
|
||||
mingw-w64-x86_64-libwinpthread-git
|
||||
mingw-w64-x86_64-zlib
|
||||
mingw-w64-x86_64-openssl
|
||||
mingw-w64-x86_64-python
|
||||
mingw-w64-x86_64-cmake
|
||||
mingw-w64-x86_64-llvm
|
||||
mingw-w64-x86_64-clang
|
||||
|
||||
- name: Add UPX to PATH
|
||||
run: |
|
||||
echo "/usr/bin:$PATH" >> $GITHUB_PATH
|
||||
echo "/mingw64/bin:$PATH" >> $GITHUB_PATH
|
||||
echo "/usr/lib:$PATH" >> $GITHUB_PATH
|
||||
echo "/mingw64/lib:$PATH" >> $GITHUB_PATH
|
||||
|
||||
- name: Verify dependencies
|
||||
run: |
|
||||
which upx gcc g++ make cmake cargo rustc python make mingw32-make
|
||||
|
||||
- name: Update
|
||||
run: make update
|
||||
|
||||
- name: Building miniupnpc
|
||||
run: |
|
||||
cd vendor/nwaku/vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc
|
||||
make -f Makefile.mingw CC=gcc CXX=g++ libminiupnpc.a V=1
|
||||
cd ../../../../../../..
|
||||
|
||||
- name: Building libnatpmp
|
||||
run: |
|
||||
cd vendor/nwaku/vendor/nim-nat-traversal/vendor/libnatpmp-upstream
|
||||
make CC="gcc -fPIC -D_WIN32_WINNT=0x0600 -DNATPMP_STATICLIB" libnatpmp.a V=1
|
||||
cd ../../../../../../
|
||||
|
||||
- name: Tests
|
||||
run: make tests
|
||||
23
.github/workflows/test.yml
vendored
23
.github/workflows/test.yml
vendored
@ -1,23 +0,0 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths-ignore:
|
||||
- '**README.md'
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
jobs:
|
||||
tests-tasks:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
- name: Update
|
||||
run: make update
|
||||
- name: Tests
|
||||
run: make tests
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
/waku_vibe_template
|
||||
/waku_vibe_template.dSYM
|
||||
/nim_chat_poc
|
||||
/logos_chat
|
||||
*.dSYM
|
||||
nimble.develop
|
||||
nimble.paths
|
||||
@ -21,7 +21,7 @@ nimble.paths
|
||||
/tags
|
||||
|
||||
# a symlink that can't be added to the repo because of Windows
|
||||
/nim_chat_poc.nims
|
||||
/logos_chat.nims
|
||||
|
||||
# Ignore dynamic, static libs and libtool archive files
|
||||
*.so
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
```mermaid
|
||||
flowchart TD
|
||||
|
||||
NIM("<a href="https://github.com/logos-messaging/nim-chat-poc"><b>nim-chat-poc</b><br>c-bingings, process control, networking</a>")
|
||||
NIM("<a href="https://github.com/logos-messaging/logos-chat"><b>Logos-Chat</b><br>c-bingings, process control, networking</a>")
|
||||
LIB("<a href="https://github.com/logos-messaging/libchat"><b>libchat</b><br>encryption, encoding</a>")
|
||||
PROTO("<a href="https://github.com/logos-messaging/chat_proto"><b>chat_proto</b><br>protobufs, language specific types</a>")
|
||||
PROTO("<a href="https://github.com/logos-messaging/chat-proto"><b>chat-proto</b><br>protobufs, language specific types</a>")
|
||||
LMN("<a href="https://github.com/logos-messaging/logos-messaging-nim"><b>logos-messaging-nim</b><br>p2p networking</a>")
|
||||
|
||||
|
||||
@ -22,13 +22,13 @@ style LMN fill:#fff
|
||||
|
||||
## Repositories
|
||||
|
||||
### nim-chat-poc
|
||||
### logos-chat
|
||||
Root of the Logos chat SDK, written in Nim.
|
||||
|
||||
Handles async operations and bridges network operations with the cryptographic backend.
|
||||
|
||||
**Responsibilities:**
|
||||
- C bindings to libchat
|
||||
- C bindings to Libchat
|
||||
- Async execution (Chronos)
|
||||
- Network integration
|
||||
|
||||
@ -42,12 +42,12 @@ Operates as a pipeline: accepts either encrypted payloads or plaintext content,
|
||||
- Encoding/decoding
|
||||
|
||||
|
||||
### logos-messaging-nim
|
||||
### logos-message-delivery
|
||||
P2P networking layer using logos-messaging protocol.
|
||||
|
||||
Provides decentralized message transport. This is an external dependency.
|
||||
|
||||
### chat_proto
|
||||
### chat-proto
|
||||
Protobuf definitions.
|
||||
|
||||
Defines the protobufs used in the logos-chat protocol and provides generated types for various languages.
|
||||
22
Makefile
22
Makefile
@ -34,19 +34,19 @@ endif
|
||||
.PHONY: all update clean
|
||||
|
||||
# default target, because it's the first one that doesn't start with '.'
|
||||
all: | bot_echo pingpong
|
||||
all: | bot_echo pingpong liblogoschat
|
||||
|
||||
test_file := $(word 2,$(MAKECMDGOALS))
|
||||
define test_name
|
||||
$(shell echo '$(MAKECMDGOALS)' | cut -d' ' -f3-)
|
||||
endef
|
||||
|
||||
nim_chat_poc.nims:
|
||||
ln -s nim_chat_poc.nimble $@
|
||||
logos_chat.nims:
|
||||
ln -s logos_chat.nimble $@
|
||||
|
||||
update: | update-common
|
||||
rm -rf nim_chat_poc.nims && \
|
||||
$(MAKE) nim_chat_poc.nims $(HANDLE_OUTPUT)
|
||||
rm -rf logos_chat.nims && \
|
||||
$(MAKE) logos_chat.nims $(HANDLE_OUTPUT)
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
@ -88,9 +88,9 @@ build-waku-nat:
|
||||
@echo "Completed building nat-libs"
|
||||
|
||||
.PHONY: tests
|
||||
tests: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
tests: | build-waku-librln build-waku-nat logos_chat.nims
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
$(ENV_SCRIPT) nim tests $(NIM_PARAMS) nim_chat_poc.nims
|
||||
$(ENV_SCRIPT) nim tests $(NIM_PARAMS) logos_chat.nims
|
||||
|
||||
|
||||
##########
|
||||
@ -98,9 +98,9 @@ tests: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
##########
|
||||
|
||||
# Ensure there is a nimble task with a name that matches the target
|
||||
tui bot_echo pingpong: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
tui bot_echo pingpong: | build-waku-librln build-waku-nat logos_chat.nims
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
$(ENV_SCRIPT) nim $@ $(NIM_PARAMS) --path:src nim_chat_poc.nims
|
||||
$(ENV_SCRIPT) nim $@ $(NIM_PARAMS) --path:src logos_chat.nims
|
||||
|
||||
###########
|
||||
## Library ##
|
||||
@ -118,9 +118,9 @@ endif
|
||||
LIBLOGOSCHAT := build/liblogoschat.$(LIBLOGOSCHAT_EXT)
|
||||
|
||||
.PHONY: liblogoschat
|
||||
liblogoschat: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
liblogoschat: | build-waku-librln build-waku-nat logos_chat.nims
|
||||
echo -e $(BUILD_MSG) "$(LIBLOGOSCHAT)" && \
|
||||
$(ENV_SCRIPT) nim liblogoschat $(NIM_PARAMS) --path:src nim_chat_poc.nims && \
|
||||
$(ENV_SCRIPT) nim liblogoschat $(NIM_PARAMS) --path:src logos_chat.nims && \
|
||||
echo -e "\n\x1B[92mLibrary built successfully:\x1B[39m" && \
|
||||
echo " $(shell pwd)/$(LIBLOGOSCHAT)"
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# Nim Chat POC
|
||||
# Logos Chat
|
||||
|
||||
This is the technical proof of a modular e2ee chat protocol using Waku. You can find discussion and details [here](https://github.com/waku-org/specs/pull/73)
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import ffi
|
||||
import src/chat/client
|
||||
|
||||
declareLibrary("chat")
|
||||
declareLibrary("logoschat")
|
||||
|
||||
proc set_event_callback(
|
||||
ctx: ptr FFIContext[ChatClient],
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
## liblogoschat - C bindings for the Chat SDK
|
||||
## liblogoschat - C bindings for Logos-Chat
|
||||
## Main entry point for the shared library
|
||||
##
|
||||
## This library exposes the Chat SDK functionality through a C-compatible FFI interface.
|
||||
## This library exposes the chat functionality through a C-compatible FFI interface.
|
||||
## It uses nim-ffi for thread-safe async request handling.
|
||||
|
||||
import std/[json, options]
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
# Package
|
||||
|
||||
version = "0.1.0"
|
||||
author = "jazzz"
|
||||
description = "An example of the chat sdk in Nim"
|
||||
author = "Logos.co"
|
||||
description = "LogosChat is a decentralized permissionless messaging protocol."
|
||||
license = "MIT"
|
||||
srcDir = "src"
|
||||
bin = @["nim_chat_poc"]
|
||||
bin = @["logos_chat"]
|
||||
|
||||
# Dependencies
|
||||
|
||||
@ -39,17 +39,17 @@ proc buildLibrary(name: string, srcDir = "library/", params = "", lang = "c") =
|
||||
## Build a shared library (.so on Linux, .dylib on macOS, .dll on Windows)
|
||||
if not dirExists "build":
|
||||
mkDir "build"
|
||||
|
||||
|
||||
# Determine library extension based on OS
|
||||
let libExt = when defined(macosx): "dylib"
|
||||
elif defined(windows): "dll"
|
||||
else: "so"
|
||||
|
||||
|
||||
var extra_params = params
|
||||
for i in 2 ..< paramCount():
|
||||
extra_params &= " " & paramStr(i)
|
||||
|
||||
exec "nim " & lang & " --app:lib --out:build/lib" & name & "." & libExt &
|
||||
|
||||
exec "nim " & lang & " --app:lib --out:build/lib" & name & "." & libExt &
|
||||
" --mm:refc --nimMainPrefix:lib" & name & " " & extra_params & " " &
|
||||
srcDir & "lib" & name & ".nim"
|
||||
|
||||
@ -59,6 +59,7 @@ proc test(name: string, params = "-d:chronicles_log_level=DEBUG", lang = "c") =
|
||||
|
||||
task tests, "Build & run tests":
|
||||
test "all_tests", "-d:chronicles_log_level=ERROR -d:chronosStrictException"
|
||||
test "smoke_test", "-d:chronicles_log_level=ERROR"
|
||||
|
||||
task waku_example, "Build Waku based simple example":
|
||||
let name = "waku_example"
|
||||
@ -74,8 +75,8 @@ task bot_echo, "Build the EchoBot example":
|
||||
|
||||
task pingpong, "Build the Pingpong example":
|
||||
let name = "pingpong"
|
||||
buildBinary name, "examples/", "-d:chronicles_log_level='INFO' -d:chronicles_disabled_topics='waku node' "
|
||||
buildBinary name, "./", "-d:chronicles_log_level='INFO' -d:chronicles_disabled_topics='waku node' "
|
||||
|
||||
task liblogoschat, "Build the Chat SDK shared library (C bindings)":
|
||||
task liblogoschat, "Build the Logos-Chat shared library (C bindings)":
|
||||
buildLibrary "logoschat", "library/",
|
||||
"-d:chronicles_log_level='INFO' -d:chronicles_enabled=on --path:src --path:vendor/nim-ffi"
|
||||
21
tests/smoke_test.nim
Normal file
21
tests/smoke_test.nim
Normal file
@ -0,0 +1,21 @@
|
||||
# Smoke test: validates that the binary links all dependencies at runtime.
|
||||
# No networking, no start(), no message exchange — just instantiation.
|
||||
|
||||
import ../src/chat
|
||||
|
||||
proc main() =
|
||||
try:
|
||||
let waku = initWakuClient(DefaultConfig())
|
||||
let ident = createIdentity("SmokeTest")
|
||||
var client = newClient(waku, ident)
|
||||
if client.isNil:
|
||||
raise newException(CatchableError, "newClient returned nil")
|
||||
let id = client.getId()
|
||||
echo "smoke_test: OK (client id: " & id & ")"
|
||||
quit(QuitSuccess)
|
||||
except CatchableError as e:
|
||||
echo "smoke_test: FAILED — " & e.msg
|
||||
quit(QuitFailure)
|
||||
|
||||
when isMainModule:
|
||||
main()
|
||||
Loading…
x
Reference in New Issue
Block a user