initial commit for nimble

This commit is contained in:
darshankabariya 2026-01-30 23:28:35 +05:30
parent cad8c66971
commit 70c3f93a32
No known key found for this signature in database
GPG Key ID: 9A92CCD9899F0D22
4 changed files with 86 additions and 405 deletions

View File

@ -1,377 +0,0 @@
{
"version": 2,
"packages": {
"chronicles": {
"version": "0.12.1",
"vcsRevision": "54f5b726025e8c7385e3a6529d3aa27454c6e6ff",
"url": "https://github.com/status-im/nim-chronicles.git",
"downloadMethod": "git",
"dependencies": [
"testutils",
"json_serialization"
]
},
"chronos": {
"version": "4.0.4",
"vcsRevision": "85af4db764ecd3573c4704139560df3943216cf1",
"url": "https://github.com/status-im/nim-chronos.git",
"downloadMethod": "git",
"dependencies": [
"stew",
"bearssl",
"unittest2",
"results"
]
},
"confutils": {
"version": "0.1.0",
"vcsRevision": "e214b3992a31acece6a9aada7d0a1ad37c928f3b",
"url": "https://github.com/status-im/nim-confutils.git",
"downloadMethod": "git",
"dependencies": [
"stew",
"serialization"
]
},
"db_connector": {
"version": "0.1.0",
"vcsRevision": "74aef399e5c232f95c9fc5c987cebac846f09d62",
"url": "https://github.com/nim-lang/db_connector.git",
"downloadMethod": "git",
"dependencies": []
},
"dnsclient": {
"version": "0.3.4",
"vcsRevision": "23214235d4784d24aceed99bbfe153379ea557c8",
"url": "https://github.com/ba0f3/dnsclient.nim.git",
"downloadMethod": "git",
"dependencies": []
},
"dnsdisc": {
"version": "0.1.0",
"vcsRevision": "b71d029f4da4ec56974d54c04518bada00e1b623",
"url": "https://github.com/status-im/nim-dnsdisc.git",
"downloadMethod": "git",
"dependencies": [
"chronos",
"chronicles",
"stew",
"eth",
"dnsclient",
"metrics"
]
},
"eth": {
"version": "1.0.0",
"vcsRevision": "d9135e6c3c5d6d819afdfb566aa8d958756b73a8",
"url": "https://github.com/status-im/nim-eth.git",
"downloadMethod": "git",
"dependencies": [
"nimcrypto",
"stint",
"secp256k1",
"chronos",
"chronicles",
"stew",
"nat_traversal",
"metrics",
"sqlite3_abi",
"results",
"unittest2"
]
},
"faststreams": {
"version": "0.3.0",
"vcsRevision": "c3ac3f639ed1d62f59d3077d376a29c63ac9750c",
"url": "https://github.com/status-im/nim-faststreams.git",
"downloadMethod": "git",
"dependencies": [
"stew",
"testutils",
"unittest2"
]
},
"ffi": {
"version": "0.1.3",
"vcsRevision": "06111de155253b34e47ed2aaed1d61d08d62cc1b",
"url": "https://github.com/logos-messaging/nim-ffi.git",
"downloadMethod": "git",
"dependencies": []
},
"http_utils": {
"version": "0.3.0",
"vcsRevision": "79cbab1460f4c0cdde2084589d017c43a3d7b4f1",
"url": "https://github.com/status-im/nim-http-utils.git",
"downloadMethod": "git",
"dependencies": [
"stew",
"results"
]
},
"json_rpc": {
"version": "0.4.3",
"vcsRevision": "9665c265035f49f5ff94bbffdeadde68e19d6221",
"url": "https://github.com/status-im/nim-json-rpc.git",
"downloadMethod": "git",
"dependencies": [
"json_serialization",
"chronos",
"websock",
"chronicles",
"unittest2",
"stew"
]
},
"json_serialization": {
"version": "0.2.6",
"vcsRevision": "b65fd6a7e64c864dabe40e7dfd6c7d07db0014ac",
"url": "https://github.com/status-im/nim-json-serialization.git",
"downloadMethod": "git",
"dependencies": [
"serialization",
"stew"
]
},
"jwt": {
"version": "0.2",
"vcsRevision": "18f8378de52b241f321c1f9ea905456e89b95c6f",
"url": "https://github.com/vacp2p/nim-jwt.git",
"downloadMethod": "git",
"dependencies": []
},
"libbacktrace": {
"version": "0.0.8",
"vcsRevision": "d8bd4ce5c46bb6d2f984f6b3f3d7380897d95ecb",
"url": "https://github.com/status-im/nim-libbacktrace.git",
"downloadMethod": "git",
"dependencies": []
},
"libp2p": {
"version": "1.6.0",
"vcsRevision": "eb7e6ff89889e41b57515f891ba82986c54809fb",
"url": "https://github.com/vacp2p/nim-libp2p.git",
"downloadMethod": "git",
"dependencies": [
"nimcrypto",
"dnsclient",
"bearssl",
"chronicles",
"chronos",
"metrics",
"secp256k1",
"stew",
"websock",
"results",
"lsquic",
"unittest2"
]
},
"lsquic": {
"version": "0.1.0",
"vcsRevision": "f3fe33462601ea34eb2e8e9c357c92e61f8d121b",
"url": "https://github.com/vacp2p/nim-lsquic.git",
"downloadMethod": "git",
"dependencies": []
},
"metrics": {
"version": "0.0.1",
"vcsRevision": "ecf64c6078d1276d3b7d9b3d931fbdb70004db11",
"url": "https://github.com/status-im/nim-metrics.git",
"downloadMethod": "git",
"dependencies": [
"chronos"
]
},
"minilru": {
"version": "1.0.0",
"vcsRevision": "0c4b2bce959591f0a862e9b541ba43c6d0cf3476",
"url": "https://github.com/status-im/nim-minilru.git",
"downloadMethod": "git",
"dependencies": [
"results"
]
},
"nat_traversal": {
"version": "0.0.1",
"vcsRevision": "860e18c37667b5dd005b94c63264560c35d88004",
"url": "https://github.com/status-im/nim-nat-traversal.git",
"downloadMethod": "git",
"dependencies": [
"chronicles",
"stew",
"results"
]
},
"nimcrypto": {
"version": "0.6.0",
"vcsRevision": "721fb99ee099b632eb86dfad1f0d96ee87583774",
"url": "https://github.com/cheatfate/nimcrypto.git",
"downloadMethod": "git",
"dependencies": []
},
"presto": {
"version": "0.1.0",
"vcsRevision": "92b1c7ff141e6920e1f8a98a14c35c1fa098e3be",
"url": "https://github.com/status-im/nim-presto.git",
"downloadMethod": "git",
"dependencies": [
"chronos",
"chronicles",
"stew",
"results"
]
},
"regex": {
"version": "0.26.1",
"vcsRevision": "4593305ed1e49731fc75af1dc572dd2559aad19c",
"url": "https://github.com/nitely/nim-regex.git",
"downloadMethod": "git",
"dependencies": [
"unicodedb"
]
},
"results": {
"version": "0.5.1",
"vcsRevision": "df8113dda4c2d74d460a8fa98252b0b771bf1f27",
"url": "https://github.com/arnetheduck/nim-results.git",
"downloadMethod": "git",
"dependencies": []
},
"secp256k1": {
"version": "0.6.0",
"vcsRevision": "9dd3df62124aae79d564da636bb22627c53c7676",
"url": "https://github.com/status-im/nim-secp256k1.git",
"downloadMethod": "git",
"dependencies": [
"stew",
"results"
]
},
"serialization": {
"version": "0.2.4",
"vcsRevision": "6f525d5447d97256750ca7856faead03e562ed20",
"url": "https://github.com/status-im/nim-serialization.git",
"downloadMethod": "git",
"dependencies": [
"stew",
"faststreams"
]
},
"sqlite3_abi": {
"version": "1.3.2",
"vcsRevision": "bdf01cf4236fb40788f0733466cdf6708783cbac",
"url": "https://github.com/arnetheduck/nim-sqlite3-abi.git",
"downloadMethod": "git",
"dependencies": []
},
"stew": {
"version": "0.2.0",
"vcsRevision": "e5740014961438610d336cd81706582dbf2c96f0",
"url": "https://github.com/status-im/nim-stew.git",
"downloadMethod": "git",
"dependencies": [
"results"
]
},
"stint": {
"version": "0.9.0",
"vcsRevision": "470b7892561b5179ab20bd389a69217d6213fe58",
"url": "https://github.com/status-im/nim-stint.git",
"downloadMethod": "git",
"dependencies": [
"stew"
]
},
"taskpools": {
"version": "0.0.5",
"vcsRevision": "9e8ccc754631ac55ac2fd495e167e74e86293edb",
"url": "https://github.com/status-im/nim-taskpools.git",
"downloadMethod": "git",
"dependencies": []
},
"testutils": {
"version": "0.5.0",
"vcsRevision": "94d68e796c045d5b37cabc6be32d7bfa168f8857",
"url": "https://github.com/status-im/nim-testutils.git",
"downloadMethod": "git",
"dependencies": [
"unittest2"
]
},
"toml_serialization": {
"version": "0.2.12",
"vcsRevision": "fea85b27f0badcf617033ca1bc05444b5fd8aa7a",
"url": "https://github.com/status-im/nim-toml-serialization.git",
"downloadMethod": "git",
"dependencies": [
"serialization",
"stew"
]
},
"unicodedb": {
"version": "0.12.0",
"vcsRevision": "66f2458710dc641dd4640368f9483c8a0ec70561",
"url": "https://github.com/nitely/nim-unicodedb.git",
"downloadMethod": "git",
"dependencies": []
},
"unittest2": {
"version": "0.2.3",
"vcsRevision": "8b51e99b4a57fcfb31689230e75595f024543024",
"url": "https://github.com/status-im/nim-unittest2.git",
"downloadMethod": "git",
"dependencies": []
},
"web3": {
"version": "0.4.2",
"vcsRevision": "81ee8ce479d86acb73be7c4f365328e238d9b4a3",
"url": "https://github.com/status-im/nim-web3.git",
"downloadMethod": "git",
"dependencies": [
"chronicles",
"chronos",
"json_rpc",
"json_serialization",
"nimcrypto",
"stint",
"stew",
"eth",
"results"
]
},
"websock": {
"version": "0.2.0",
"vcsRevision": "ebe308a79a7b440a11dfbe74f352be86a3883508",
"url": "https://github.com/status-im/nim-websock.git",
"downloadMethod": "git",
"dependencies": [
"chronos",
"http_utils",
"chronicles",
"stew",
"nimcrypto",
"bearssl",
"zlib"
]
},
"zlib": {
"version": "0.1.0",
"vcsRevision": "daa8723fd32299d4ca621c837430c29a5a11e19a",
"url": "https://github.com/status-im/nim-zlib.git",
"downloadMethod": "git",
"dependencies": [
"stew"
]
},
"bearssl": {
"version": "0.2.5",
"vcsRevision": "11e798b62b8e6beabe958e048e9e24c7e0f9ee63",
"url": "https://github.com/status-im/nim-bearssl.git",
"downloadMethod": "git",
"dependencies": [
"unittest2"
]
}
},
"tasks": {}
}

View File

@ -18,10 +18,10 @@ suite "Waku Message - Deterministic hashing":
## Given
let pubsubTopic = DefaultPubsubTopic # /waku/2/rs/0/0
let message = fakeWakuMessage(
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
payload = "\x01\x02\x03\x04TEST\x05\x06\x07\x08".toBytes(),
meta = newSeq[byte](),
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
)
## When
@ -35,7 +35,7 @@ suite "Waku Message - Deterministic hashing":
byteutils.toHex(message.payload) == "010203045445535405060708"
byteutils.toHex(message.meta) == ""
byteutils.toHex(toBytesBE(uint64(message.timestamp))) == "175789bfa23f8400"
messageHash.toHex() ==
byteutils.toHex(messageHash) ==
"cccab07fed94181c83937c8ca8340c9108492b7ede354a6d95421ad34141fd37"
test "digest computation - meta field (12 bytes)":
@ -52,10 +52,10 @@ suite "Waku Message - Deterministic hashing":
## Given
let pubsubTopic = DefaultPubsubTopic # /waku/2/rs/0/0
let message = fakeWakuMessage(
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
payload = "\x01\x02\x03\x04TEST\x05\x06\x07\x08".toBytes(),
meta = "\x73\x75\x70\x65\x72\x2d\x73\x65\x63\x72\x65\x74".toBytes(),
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
)
## When
@ -69,7 +69,7 @@ suite "Waku Message - Deterministic hashing":
byteutils.toHex(message.payload) == "010203045445535405060708"
byteutils.toHex(message.meta) == "73757065722d736563726574"
byteutils.toHex(toBytesBE(uint64(message.timestamp))) == "175789bfa23f8400"
messageHash.toHex() ==
byteutils.toHex(messageHash) ==
"b9b4852f9d8c489846e8bfc6c5ca6a1a8d460a40d28832a966e029eb39619199"
test "digest computation - meta field (64 bytes)":
@ -86,10 +86,10 @@ suite "Waku Message - Deterministic hashing":
## Given
let pubsubTopic = DefaultPubsubTopic # /waku/2/rs/0/0
let message = fakeWakuMessage(
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
payload = "\x01\x02\x03\x04TEST\x05\x06\x07\x08".toBytes(),
meta = toSeq(0.byte .. 63.byte),
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
)
## When
@ -104,7 +104,7 @@ suite "Waku Message - Deterministic hashing":
byteutils.toHex(message.meta) ==
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"
byteutils.toHex(toBytesBE(uint64(message.timestamp))) == "175789bfa23f8400"
messageHash.toHex() ==
byteutils.toHex(messageHash) ==
"653460d04f66c5b11814d235152f4f246e6f03ef80a305a825913636fbafd0ba"
test "digest computation - zero length payload":
@ -121,10 +121,10 @@ suite "Waku Message - Deterministic hashing":
## Given
let pubsubTopic = DefaultPubsubTopic # /waku/2/rs/0/0
let message = fakeWakuMessage(
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
contentTopic = DefaultContentTopic, # /waku/2/default-content/proto
payload = newSeq[byte](),
meta = "\x73\x75\x70\x65\x72\x2d\x73\x65\x63\x72\x65\x74".toBytes(),
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
ts = getNanosecondTime(1681964442), # Apr 20 2023 04:20:42
)
## When
@ -132,7 +132,7 @@ suite "Waku Message - Deterministic hashing":
## Then
check:
messageHash.toHex() ==
byteutils.toHex(messageHash) ==
"0f6448cc23b2db6c696aa6ab4b693eff4cf3549ff346fe1dbeb281697396a09f"
test "waku message - check meta size is enforced":

View File

@ -1,12 +1,13 @@
{.used.}
import
std/options,
std/net,
results,
testutils/unittests,
libp2p/multiaddress,
libp2p/peerid,
libp2p/errors,
confutils/toml/std/net
libp2p/errors
import waku/[waku_core, waku_enr], ../testlib/wakucore
suite "Waku Core - Peers":
@ -155,9 +156,9 @@ suite "Waku Core - Peers":
## When
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
builder.withIpAddressAndPorts(
ipAddr = some(parseIpAddress("127.0.0.1")),
tcpPort = some(Port(0)),
udpPort = some(Port(0)),
ipAddr = options.some(parseIpAddress("127.0.0.1")),
tcpPort = options.some(Port(0)),
udpPort = options.some(Port(0)),
)
builder.withWakuCapabilities(Capabilities.Relay, Capabilities.Store)

View File

@ -1,6 +1,6 @@
#!fmt: off
import os
import os, strutils
mode = ScriptMode.Verbose
### Package
@ -70,11 +70,11 @@ proc getNimblePath(pkgName: string): string =
proc buildModule(filePath, params = "", lang = "c"): bool =
if not dirExists "build":
mkDir "build"
# allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims"
# Filter out nimble's internal params, only pass compiler flags
var extra_params = params
for i in 2 ..< paramCount() - 1:
let param = paramStr(i)
# Skip nimble config files and task names - only pass compiler flags
# Skip nimble config files
if param.endsWith(".nimble") or param.endsWith(".nims") or param.endsWith(".out"):
continue
# Only pass actual compiler flags (those starting with -)
@ -95,11 +95,11 @@ proc buildModule(filePath, params = "", lang = "c"): bool =
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
if not dirExists "build":
mkDir "build"
# allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims"
# Filter out nimble's internal params, only pass compiler flags
var extra_params = params
for i in 2 ..< paramCount():
let param = paramStr(i)
# Skip nimble config files and task names - only pass compiler flags
# Skip nimble config files
if param.endsWith(".nimble") or param.endsWith(".nims") or param.endsWith(".out"):
continue
# Only pass actual compiler flags (those starting with -)
@ -114,8 +114,23 @@ proc buildLibrary(lib_name: string, srcDir = "./", params = "", `type` = "static
mkDir "build"
# allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims"
var extra_params = params
for i in 2 ..< (paramCount() - 1):
extra_params &= " " & paramStr(i)
# Iterate through all params to capture all compiler flags including --passL
for i in 2 .. paramCount():
let param = paramStr(i)
# Skip nimble config files
if param.endsWith(".nimble") or param.endsWith(".nims") or param.endsWith(".out"):
continue
# Skip standalone library files (but not --passL flags referencing them)
if not param.startsWith("-"):
if param.endsWith(".dylib") or param.endsWith(".a") or param.endsWith(".lib") or param.endsWith(".so"):
continue
# Skip task names
if param == "libwakuStatic" or param == "libwakuDynamic":
continue
# Only pass actual compiler flags (those starting with -)
if not param.startsWith("-"):
continue
extra_params &= " " & param
if `type` == "static":
exec "nim c" & " --out:build/" & lib_name &
" --threads:on --app:staticlib --opt:size --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:on -d:discv5_protocol_id=d5waku " &
@ -133,9 +148,17 @@ proc buildMobileAndroid(srcDir = ".", params = "") =
if not dirExists outDir:
mkDir outDir
# Filter out nimble's internal params, only pass compiler flags
var extra_params = params
for i in 2 ..< paramCount():
extra_params &= " " & paramStr(i)
let param = paramStr(i)
# Skip nimble config files
if param.endsWith(".nimble") or param.endsWith(".nims") or param.endsWith(".out"):
continue
# Only pass actual compiler flags (those starting with -)
if not param.startsWith("-"):
continue
extra_params &= " " & param
exec "nim c" & " --out:" & outDir &
"/libwaku.so --threads:on --app:lib --opt:size --noMain --mm:refc -d:chronicles_sinks=textlines[dynamic] --header -d:chronosEventEngine=epoll --passL:-L" &
@ -233,7 +256,7 @@ task buildTest, "Test custom target":
let filepath = paramStr(paramCount())
discard buildModule(filepath)
import std/strutils
# strutils already imported at top of file
task execTest, "Run test":
# Expects to be parameterized with test case name in quotes
@ -254,11 +277,45 @@ let chroniclesParams =
"--warning:UnusedImport:on " & "-d:chronicles_log_level=TRACE"
task libwakuStatic, "Build the cbindings waku node library":
let lib_name = paramStr(paramCount())
# Find the library name - it's the first non-flag argument after the task name
var lib_name = ""
var foundTask = false
for i in 0..paramCount():
let param = paramStr(i)
if param == "libwakuStatic":
foundTask = true
continue
if foundTask and not param.startsWith("-") and not param.startsWith("--"):
lib_name = param
break
if lib_name == "":
# Use platform-appropriate extension for fallback
when defined(windows):
lib_name = "libwaku.lib"
else:
lib_name = "libwaku.a" # .a works for both macOS and Linux
buildLibrary lib_name, "library/", chroniclesParams, "static"
task libwakuDynamic, "Build the cbindings waku node library":
let lib_name = paramStr(paramCount())
# Find the library name - it's the first non-flag argument after the task name
var lib_name = ""
var foundTask = false
for i in 0..paramCount():
let param = paramStr(i)
if param == "libwakuDynamic":
foundTask = true
continue
if foundTask and not param.startsWith("-") and not param.startsWith("--"):
lib_name = param
break
if lib_name == "":
# Use platform-appropriate extension for fallback
when defined(macosx):
lib_name = "libwaku.dylib"
elif defined(windows):
lib_name = "libwaku.dll"
else:
lib_name = "libwaku.so"
buildLibrary lib_name, "library/", chroniclesParams, "dynamic"
### Mobile Android