2018-11-19 02:52:11 +00:00
|
|
|
mode = ScriptMode.Verbose
|
|
|
|
|
2018-11-19 04:03:23 +00:00
|
|
|
packageName = "libp2p"
|
2023-06-06 11:05:49 +00:00
|
|
|
version = "1.1.0"
|
2018-11-19 02:52:11 +00:00
|
|
|
author = "Status Research & Development GmbH"
|
|
|
|
description = "LibP2P implementation"
|
|
|
|
license = "MIT"
|
2020-09-15 09:16:43 +00:00
|
|
|
skipDirs = @["tests", "examples", "Nim", "tools", "scripts", "docs"]
|
2018-11-19 02:52:11 +00:00
|
|
|
|
2023-06-07 11:12:49 +00:00
|
|
|
requires "nim >= 1.6.0",
|
2020-04-14 05:26:12 +00:00
|
|
|
"nimcrypto >= 0.4.1",
|
2022-09-29 08:29:51 +00:00
|
|
|
"dnsclient >= 0.3.0 & < 0.4.0",
|
2020-03-06 19:19:43 +00:00
|
|
|
"bearssl >= 0.1.4",
|
2021-12-16 18:00:10 +00:00
|
|
|
"chronicles >= 0.10.2",
|
2021-11-24 20:01:12 +00:00
|
|
|
"chronos >= 3.0.6",
|
2020-04-14 13:27:07 +00:00
|
|
|
"metrics",
|
|
|
|
"secp256k1",
|
2021-08-03 13:48:03 +00:00
|
|
|
"stew#head",
|
2022-11-07 21:55:22 +00:00
|
|
|
"websock",
|
2023-10-11 14:18:53 +00:00
|
|
|
"https://github.com/status-im/nim-webrtc.git",
|
2023-09-06 15:52:43 +00:00
|
|
|
"unittest2 >= 0.0.5 & <= 0.1.0"
|
2018-11-19 02:52:11 +00:00
|
|
|
|
2023-06-28 15:51:51 +00:00
|
|
|
let nimc = getEnv("NIMC", "nim") # Which nim compiler to use
|
|
|
|
let lang = getEnv("NIMLANG", "c") # Which backend (c/cpp/js)
|
|
|
|
let flags = getEnv("NIMFLAGS", "") # Extra flags for the compiler
|
|
|
|
let verbose = getEnv("V", "") notin ["", "0"]
|
|
|
|
|
|
|
|
let cfg =
|
|
|
|
" --styleCheck:usages --styleCheck:error" &
|
|
|
|
(if verbose: "" else: " --verbosity:0 --hints:off") &
|
|
|
|
" --skipParentCfg --skipUserCfg -f" &
|
|
|
|
" --threads:on --opt:speed"
|
|
|
|
|
|
|
|
import hashes, strutils
|
|
|
|
|
2020-07-21 20:10:21 +00:00
|
|
|
proc runTest(filename: string, verify: bool = true, sign: bool = true,
|
|
|
|
moreoptions: string = "") =
|
2023-06-28 15:51:51 +00:00
|
|
|
var excstr = nimc & " " & lang & " -d:debug " & cfg & " " & flags
|
2020-06-20 10:56:55 +00:00
|
|
|
excstr.add(" -d:libp2p_pubsub_sign=" & $sign)
|
|
|
|
excstr.add(" -d:libp2p_pubsub_verify=" & $verify)
|
2020-07-21 20:10:21 +00:00
|
|
|
excstr.add(" " & moreoptions & " ")
|
2022-11-16 13:33:42 +00:00
|
|
|
if getEnv("CICOV").len > 0:
|
|
|
|
excstr &= " --nimcache:nimcache/" & filename & "-" & $excstr.hash
|
2022-07-01 18:20:42 +00:00
|
|
|
exec excstr & " -r " & " tests/" & filename
|
2020-04-14 13:21:16 +00:00
|
|
|
rmFile "tests/" & filename.toExe
|
2019-03-14 02:55:47 +00:00
|
|
|
|
2022-10-30 07:49:02 +00:00
|
|
|
proc buildSample(filename: string, run = false, extraFlags = "") =
|
2023-06-28 15:51:51 +00:00
|
|
|
var excstr = nimc & " " & lang & " " & cfg & " " & flags & " -p:. " & extraFlags
|
2020-06-20 10:56:55 +00:00
|
|
|
excstr.add(" examples/" & filename)
|
|
|
|
exec excstr
|
2021-11-08 12:00:44 +00:00
|
|
|
if run:
|
|
|
|
exec "./examples/" & filename.toExe
|
|
|
|
rmFile "examples/" & filename.toExe
|
|
|
|
|
2022-09-28 08:40:53 +00:00
|
|
|
proc tutorialToMd(filename: string) =
|
2023-06-28 15:51:51 +00:00
|
|
|
let markdown = gorge "cat " & filename & " | " & nimc & " " & lang & " -r --verbosity:0 --hints:off tools/markdown_builder.nim "
|
2022-09-28 08:40:53 +00:00
|
|
|
writeFile(filename.replace(".nim", ".md"), markdown)
|
2020-04-19 05:04:53 +00:00
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
task testnative, "Runs libp2p native tests":
|
2020-04-23 01:27:29 +00:00
|
|
|
runTest("testnative")
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
task testdaemon, "Runs daemon tests":
|
2020-04-23 01:27:29 +00:00
|
|
|
runTest("testdaemon")
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
task testinterop, "Runs interop tests":
|
2020-04-23 01:27:29 +00:00
|
|
|
runTest("testinterop")
|
2020-04-19 05:04:53 +00:00
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
task testpubsub, "Runs pubsub tests":
|
2020-09-21 09:16:29 +00:00
|
|
|
runTest("pubsub/testgossipinternal", sign = false, verify = false, moreoptions = "-d:pubsub_internal_testing")
|
2020-05-06 09:26:08 +00:00
|
|
|
runTest("pubsub/testpubsub")
|
|
|
|
runTest("pubsub/testpubsub", sign = false, verify = false)
|
2020-09-28 07:11:18 +00:00
|
|
|
runTest("pubsub/testpubsub", sign = false, verify = false, moreoptions = "-d:libp2p_pubsub_anonymize=true")
|
2020-05-06 09:26:08 +00:00
|
|
|
|
2020-09-28 07:11:18 +00:00
|
|
|
task testpubsub_slim, "Runs pubsub tests":
|
|
|
|
runTest("pubsub/testgossipinternal", sign = false, verify = false, moreoptions = "-d:pubsub_internal_testing")
|
|
|
|
runTest("pubsub/testpubsub")
|
|
|
|
|
2020-07-21 20:10:21 +00:00
|
|
|
task testfilter, "Run PKI filter test":
|
|
|
|
runTest("testpkifilter",
|
|
|
|
moreoptions = "-d:libp2p_pki_schemes=\"secp256k1\"")
|
|
|
|
runTest("testpkifilter",
|
|
|
|
moreoptions = "-d:libp2p_pki_schemes=\"secp256k1;ed25519\"")
|
|
|
|
runTest("testpkifilter",
|
|
|
|
moreoptions = "-d:libp2p_pki_schemes=\"secp256k1;ed25519;ecnist\"")
|
|
|
|
runTest("testpkifilter",
|
|
|
|
moreoptions = "-d:libp2p_pki_schemes=")
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
task test, "Runs the test suite":
|
|
|
|
exec "nimble testnative"
|
|
|
|
exec "nimble testpubsub"
|
|
|
|
exec "nimble testdaemon"
|
|
|
|
exec "nimble testinterop"
|
2020-07-21 20:10:21 +00:00
|
|
|
exec "nimble testfilter"
|
2021-11-08 12:00:44 +00:00
|
|
|
exec "nimble examples_build"
|
2020-05-06 09:26:08 +00:00
|
|
|
|
2022-01-10 11:29:52 +00:00
|
|
|
task test_slim, "Runs the (slimmed down) test suite":
|
2020-09-28 07:11:18 +00:00
|
|
|
exec "nimble testnative"
|
|
|
|
exec "nimble testpubsub_slim"
|
|
|
|
exec "nimble testfilter"
|
2021-11-19 10:52:29 +00:00
|
|
|
exec "nimble examples_build"
|
2020-09-28 07:11:18 +00:00
|
|
|
|
2022-09-28 08:40:53 +00:00
|
|
|
task website, "Build the website":
|
|
|
|
tutorialToMd("examples/tutorial_1_connect.nim")
|
|
|
|
tutorialToMd("examples/tutorial_2_customproto.nim")
|
2022-09-29 08:28:58 +00:00
|
|
|
tutorialToMd("examples/tutorial_3_protobuf.nim")
|
2022-10-21 15:00:36 +00:00
|
|
|
tutorialToMd("examples/tutorial_4_gossipsub.nim")
|
2022-10-29 10:12:12 +00:00
|
|
|
tutorialToMd("examples/tutorial_5_discovery.nim")
|
2022-10-30 07:49:02 +00:00
|
|
|
tutorialToMd("examples/tutorial_6_game.nim")
|
2022-09-28 08:40:53 +00:00
|
|
|
tutorialToMd("examples/circuitrelay.nim")
|
|
|
|
exec "mkdocs build"
|
|
|
|
|
2020-04-19 05:04:53 +00:00
|
|
|
task examples_build, "Build the samples":
|
2020-04-23 01:27:29 +00:00
|
|
|
buildSample("directchat")
|
2021-11-08 12:00:44 +00:00
|
|
|
buildSample("helloworld", true)
|
2022-08-01 12:31:22 +00:00
|
|
|
buildSample("circuitrelay", true)
|
2022-09-28 08:40:53 +00:00
|
|
|
buildSample("tutorial_1_connect", true)
|
|
|
|
buildSample("tutorial_2_customproto", true)
|
2023-06-07 11:12:49 +00:00
|
|
|
buildSample("tutorial_3_protobuf", true)
|
|
|
|
buildSample("tutorial_4_gossipsub", true)
|
|
|
|
buildSample("tutorial_5_discovery", true)
|
|
|
|
exec "nimble install -y nimpng@#HEAD" # this is to fix broken build on 1.7.3, remove it when nimpng version 0.3.2 or later is released
|
|
|
|
exec "nimble install -y nico"
|
|
|
|
buildSample("tutorial_6_game", false, "--styleCheck:off")
|
2021-12-16 18:00:10 +00:00
|
|
|
|
|
|
|
# pin system
|
|
|
|
# while nimble lockfile
|
|
|
|
# isn't available
|
|
|
|
|
|
|
|
const PinFile = ".pinned"
|
|
|
|
task pin, "Create a lockfile":
|
|
|
|
# pinner.nim was originally here
|
|
|
|
# but you can't read output from
|
|
|
|
# a command in a nimscript
|
2023-06-28 15:51:51 +00:00
|
|
|
exec nimc & " c -r tools/pinner.nim"
|
2021-12-16 18:00:10 +00:00
|
|
|
|
|
|
|
import sequtils
|
|
|
|
import os
|
|
|
|
task install_pinned, "Reads the lockfile":
|
|
|
|
let toInstall = readFile(PinFile).splitWhitespace().mapIt((it.split(";", 1)[0], it.split(";", 1)[1]))
|
|
|
|
# [('packageName', 'packageFullUri')]
|
|
|
|
|
|
|
|
rmDir("nimbledeps")
|
|
|
|
mkDir("nimbledeps")
|
|
|
|
exec "nimble install -y " & toInstall.mapIt(it[1]).join(" ")
|
|
|
|
|
|
|
|
# Remove the automatically installed deps
|
|
|
|
# (inefficient you say?)
|
2022-12-14 11:10:00 +00:00
|
|
|
let nimblePkgs =
|
|
|
|
if system.dirExists("nimbledeps/pkgs"): "nimbledeps/pkgs"
|
|
|
|
else: "nimbledeps/pkgs2"
|
|
|
|
for dependency in listDirs(nimblePkgs):
|
2023-01-23 14:53:15 +00:00
|
|
|
let
|
|
|
|
fileName = dependency.extractFilename
|
|
|
|
fileContent = readFile(dependency & "/nimblemeta.json")
|
|
|
|
packageName = fileName.split('-')[0]
|
|
|
|
|
|
|
|
if toInstall.anyIt(
|
|
|
|
it[0] == packageName and
|
|
|
|
(
|
|
|
|
it[1].split('#')[^1] in fileContent or # nimble for nim 2.X
|
|
|
|
fileName.endsWith(it[1].split('#')[^1]) # nimble for nim 1.X
|
|
|
|
)
|
|
|
|
) == false or
|
|
|
|
fileName.split('-')[^1].len < 20: # safegard for nimble for nim 1.X
|
|
|
|
rmDir(dependency)
|
2021-12-16 18:00:10 +00:00
|
|
|
|
|
|
|
task unpin, "Restore global package use":
|
|
|
|
rmDir("nimbledeps")
|