mirror of https://github.com/waku-org/nwaku.git
chore: Add new custom built and test target to make in order to enable easy build or test single nim modules (#2913)
* Add new custom built and test target to make in order to enable easy build or test single nim modules * Extend README.md describe how to use it
This commit is contained in:
parent
5c539fe13d
commit
ad25f43772
9
Makefile
9
Makefile
|
@ -179,7 +179,7 @@ testcommon: | build deps
|
|||
##########
|
||||
## Waku ##
|
||||
##########
|
||||
.PHONY: testwaku wakunode2 testwakunode2 example2 chat2 chat2bridge
|
||||
.PHONY: testwaku wakunode2 testwakunode2 example2 chat2 chat2bridge liteprotocoltester
|
||||
|
||||
# install anvil only for the testwaku target
|
||||
testwaku: | build deps anvil librln
|
||||
|
@ -218,6 +218,13 @@ liteprotocoltester: | build deps librln
|
|||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
$(ENV_SCRIPT) nim liteprotocoltester $(NIM_PARAMS) waku.nims
|
||||
|
||||
build/%: | build deps librln
|
||||
echo -e $(BUILD_MSG) "build/$*" && \
|
||||
$(ENV_SCRIPT) nim buildone $(NIM_PARAMS) waku.nims $*
|
||||
|
||||
test/%: | build deps librln
|
||||
echo -e $(BUILD_MSG) "test/$*" && \
|
||||
$(ENV_SCRIPT) nim testone $(NIM_PARAMS) waku.nims $*
|
||||
|
||||
################
|
||||
## Waku tools ##
|
||||
|
|
16
README.md
16
README.md
|
@ -68,6 +68,22 @@ If everything went well, you should see your prompt suffixed with `[Nimbus env]$
|
|||
make test
|
||||
```
|
||||
|
||||
### Building single test files
|
||||
|
||||
During development it is handful to build and run a single test file.
|
||||
To support this make has a specific target:
|
||||
|
||||
targets:
|
||||
- `build/<relative path to your test file.nim>`
|
||||
- `test/<relative path to your test file.nim>`
|
||||
|
||||
Binary will be created as `<path to your test file.nim>.bin` under the `build` directory .
|
||||
|
||||
```bash
|
||||
# Build and run your test file separately
|
||||
make test/tests/common/test_enr_builder.nim
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
Examples can be found in the examples folder.
|
||||
|
|
39
waku.nimble
39
waku.nimble
|
@ -26,6 +26,24 @@ requires "nim >= 2.0.8",
|
|||
"db_connector"
|
||||
|
||||
### Helper functions
|
||||
proc buildModule(filePath, params = "", lang = "c"): bool =
|
||||
if not dirExists "build":
|
||||
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)
|
||||
|
||||
if not fileExists(filePath):
|
||||
echo "File to build not found: " & filePath
|
||||
return false
|
||||
|
||||
exec "nim " & lang & " --out:build/" & filepath & ".bin --mm:refc " & extra_params &
|
||||
" " & filePath
|
||||
|
||||
# exec will raise exception if anything goes wrong
|
||||
return true
|
||||
|
||||
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
|
||||
if not dirExists "build":
|
||||
mkDir "build"
|
||||
|
@ -33,8 +51,8 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
|
|||
var extra_params = params
|
||||
for i in 2 ..< paramCount():
|
||||
extra_params &= " " & paramStr(i)
|
||||
exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " & srcDir & name &
|
||||
".nim"
|
||||
exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " &
|
||||
srcDir & name & ".nim"
|
||||
|
||||
proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") =
|
||||
if not dirExists "build":
|
||||
|
@ -45,12 +63,12 @@ proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") =
|
|||
extra_params &= " " & paramStr(i)
|
||||
if `type` == "static":
|
||||
exec "nim c" & " --out:build/" & name &
|
||||
".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header " & extra_params &
|
||||
" " & srcDir & name & ".nim"
|
||||
".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header " &
|
||||
extra_params & " " & srcDir & name & ".nim"
|
||||
else:
|
||||
exec "nim c" & " --out:build/" & name &
|
||||
".so --threads:on --app:lib --opt:size --noMain --mm:refc --header " & extra_params & " " &
|
||||
srcDir & name & ".nim"
|
||||
".so --threads:on --app:lib --opt:size --noMain --mm:refc --header " & extra_params &
|
||||
" " & srcDir & name & ".nim"
|
||||
|
||||
proc buildMobileAndroid(srcDir = ".", params = "") =
|
||||
let cpu = getEnv("CPU")
|
||||
|
@ -129,6 +147,15 @@ task liteprotocoltester, "Build liteprotocoltester":
|
|||
let name = "liteprotocoltester"
|
||||
buildBinary name, "apps/liteprotocoltester/"
|
||||
|
||||
task buildone, "Build custom target":
|
||||
let filepath = paramStr(paramCount())
|
||||
discard buildModule filepath
|
||||
|
||||
task testone, "Test custom target":
|
||||
let filepath = paramStr(paramCount())
|
||||
if buildModule(filepath):
|
||||
exec "build/" & filepath & ".bin"
|
||||
|
||||
### C Bindings
|
||||
task libwakuStatic, "Build the cbindings waku node library":
|
||||
let name = "libwaku"
|
||||
|
|
Loading…
Reference in New Issue