2020-10-08 16:08:52 +00:00
|
|
|
mode = ScriptMode.Verbose
|
|
|
|
|
2020-07-02 13:20:16 +00:00
|
|
|
version = "0.1.0"
|
|
|
|
author = "Status Research & Development GmbH"
|
|
|
|
description = "Nim implementation of the Status protocol"
|
|
|
|
license = "MIT"
|
2020-10-08 16:08:52 +00:00
|
|
|
skipDirs = @["test"]
|
|
|
|
|
|
|
|
requires "nim >= 1.2.0",
|
|
|
|
"chroma",
|
|
|
|
"chronicles",
|
|
|
|
"chronos",
|
|
|
|
"confutils",
|
|
|
|
"eth",
|
|
|
|
"nimPNG",
|
|
|
|
"nimage",
|
|
|
|
"nimcrypto",
|
|
|
|
"secp256k1",
|
|
|
|
"stew",
|
|
|
|
"waku"
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
import strutils
|
2020-07-13 14:26:31 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
proc buildAndRunTest(name: string,
|
|
|
|
srcDir = "test/nim/",
|
|
|
|
outDir = "test/nim/build/",
|
|
|
|
params = "",
|
|
|
|
cmdParams = "",
|
|
|
|
lang = "c") =
|
feat: introduce Nim impl of hashMessage in reorganized library
Introduce a Nim implementation of `hashMessage` situated in a reorganized
library with *Nim-oriented* and *C-oriented* entry points inspired by the
[shim strategy][shim-strat] suggested by @arnetheduck.
The goal of this approach (per @iurimatias, at least as I understood what was
discussed and tasked) is for Nim implementations of equivalent functionality to
eventually supersede existing [status-go][sgo] implementations.
These changes will benefit from feedback by @arnetheduck, @zah,
@stefantalpalaru, @siphiuel, other members of stimbus/desktop, et al. – my dev
experiences with Nim and C are quite limited to date. Some of the changes may
be problematic, unnecessary, suboptimal, etc. I may have reified the *"shim
strategy"* badly. Please shred this PR apart and lead me to the 💡
light. Thanks for your help!
N.B. `tests/nim/login.nim` and `tests/c/login.c` use loops that never
terminate (introduced prior to this PR). Future work will attempt to remedy
that shortcoming but it's out of scope for this PR.
The reorganized library can be grouped into two trees of `.nim` sources, but
note that `import` statements interlink some of them.
**Nim-oriented**
```
├── src
│ ├── nim_status
│ │ ├── go
│ │ │ └── shim.nim
│ │ ├── lib
│ │ │ ├── shim.nim
│ │ │ └── util.nim
│ │ ├── lib.nim
│ │ └── types.nim
│ └── nim_status.nim
```
**C-oriented**
```
├── src
│ ├── nim_status
│ │ ├── c
│ │ │ ├── go
│ │ │ │ └── shim.nim
│ │ │ ├── lib
│ │ │ │ └── shim.nim
│ │ │ ├── lib.nim
│ │ │ ├── nim_status.nim
│ │ │ └── sys.nim
```
The key difference between the Nim sources in one tree and the other is that
the Nim-oriented sources are intended to be consumed by other Nim
sources (e.g. [status-im/nim-status-client][nsc] via Nim's built-in `import`),
while the C-oriented sources are intended to be compiled to a C
library (e.g. `nim_status.a`) and then linked/called by other C code. To that
end, the former use e.g. `string` in call signatures while the latter use
`cstring`. Along the same lines, the C-oriented `proc`s may return pointers to
memory allocated with `c_malloc` such that it's up to the caller to free the
memory occupied by the return values.
Both `src/nim_status/go/shim.nim` and `src/nim_status/c/go/shim.nim` are pure
shims around status-go, the main difference being their call signatures.
With `src/nim_status/lib.nim` the intention is to implement functionality in a
manner independent of status-go's idioms.
In `src/nim_status/[c/]lib/shim.nim` the intention is to wrap around
`src/nim_status/lib.nim` in a way that preserves status-go's call signatures
and formatting. For example, the `hashMessage` proc introduced in this PR in
`src/nim_status/lib.nim` returns a hex string like `0xabcd...` while
`lib/shim.nim` returns JSON that's a match for status-go:
`{"result":"0xabcd..."}`.
Both `src/nim_status.nim` and `src/nim_status/c/nim_status.nim` represent a
hybrid of `go/shim.nim` and `lib/shim.nim`. Again, the goal is that over time
more and more `proc`s implemented in Nim replace the shims around status-go.
Callers that don't need to consume return values formatted according to
status-go conventions can use `lib.nim` directly, e.g. via `import
nim_status/lib` or by compiling `src/nim_status/c/lib.nim` and linking/calling
from C.
`c_malloc` has been copied (in `src/nim_status/c/sys.nim`) from the source of
Nim's `system/ansi_c` because `ansi_c` is an undocumented internal API.
A Nim template or pragma might be useful with respect to usgae of `c_malloc` in
`src/nim_status/c/*`, i.e. to cut down on repetition.
Use of `{.exportc.}` is limited to the `src/nim_status/c/nim_status.nim` hybrid
shim to avoid imposing exported symbols on C-oriented library consumers who may
wish to compose things in a different manner.
With respect to the Nim implementation of `hashMessage`, both Nim-oriented and
C-oriented tests have been implemented. Whether doubling up the tests is really
necessary/desirable for all `proc`s is probably worth discussing.
Adjust `.gitignore` and refactor `Makefile` accordingly; apply some lessons
learned while working on [status-im/nim-status-client][nsc].
Closes #34.
[shim-strat]: https://github.com/status-im/nim-status/issues/5#issuecomment-647497745
[sgo]: https://github.com/status-im/status-go
[nsc]: https://github.com/status-im/nim-status-client
2020-07-23 22:15:09 +00:00
|
|
|
rmDir "data"
|
|
|
|
rmDir "keystore"
|
|
|
|
rmDir "noBackup"
|
|
|
|
mkDir "data"
|
|
|
|
mkDir "keystore"
|
|
|
|
mkDir "noBackup"
|
2020-10-08 16:08:52 +00:00
|
|
|
rmDir outDir
|
|
|
|
mkDir outDir
|
2020-07-13 14:26:31 +00:00
|
|
|
# allow something like "nim test --verbosity:0 --hints:off beacon_chain.nims"
|
|
|
|
var extra_params = params
|
|
|
|
for i in 2..<paramCount():
|
|
|
|
extra_params &= " " & paramStr(i)
|
2020-10-08 16:08:52 +00:00
|
|
|
exec "nim " &
|
|
|
|
lang &
|
|
|
|
" --debugger:native" &
|
|
|
|
" --define:chronicles_line_numbers" &
|
|
|
|
" --define:debug" &
|
|
|
|
(if getEnv("PCRE_STATIC").strip != "false": " --define:usePcreHeader --dynlibOverride:pcre" else: "") &
|
|
|
|
" --define:ssl" &
|
|
|
|
(if getEnv("SSL_STATIC").strip != "false": " --dynlibOverride:ssl" else: "") &
|
|
|
|
" --nimcache:nimcache/test/" & name &
|
|
|
|
" --out:" & outDir & name &
|
|
|
|
(if getEnv("NIMSTATUS_CFLAGS").strip != "": " --passC:\"" & getEnv("NIMSTATUS_CFLAGS") & "\"" else: "") &
|
|
|
|
(if getEnv("PCRE_LDFLAGS").strip != "": " --passL:\"" & getEnv("PCRE_LDFLAGS") & "\"" else: "") &
|
|
|
|
(if getEnv("SSL_LDFLAGS").strip != "": " --passL:\"" & getEnv("SSL_LDFLAGS") & "\"" else: "") &
|
|
|
|
" --passL:\"-L" & getEnv("STATUSGO_LIB_DIR") & " -lstatus" & "\"" &
|
|
|
|
(if defined(macosx): " --passL:-headerpad_max_install_names" else: "") &
|
|
|
|
" --threads:on" &
|
|
|
|
" --tlsEmulation:off" &
|
|
|
|
" " &
|
|
|
|
extra_params &
|
|
|
|
" " &
|
|
|
|
srcDir & name & ".nim" &
|
|
|
|
" " &
|
|
|
|
cmdParams
|
2020-08-10 16:48:30 +00:00
|
|
|
if defined(macosx):
|
2020-10-08 16:08:52 +00:00
|
|
|
exec "install_name_tool -add_rpath " & getEnv("STATUSGO_LIB_DIR") & " " & outDir & name
|
|
|
|
exec "install_name_tool -change libstatus.dylib @rpath/libstatus.dylib " & outDir & name
|
|
|
|
exec outDir & name
|
2020-07-13 14:26:31 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
task tests, "Run all tests":
|
2020-11-26 01:40:55 +00:00
|
|
|
buildAndRunTest "shims"
|
|
|
|
buildAndRunTest "login"
|
|
|
|
buildAndRunTest "db_smoke"
|
|
|
|
buildAndRunTest "waku_smoke"
|
2020-10-22 22:26:06 +00:00
|
|
|
buildAndRunTest "settings"
|
2020-12-04 21:35:35 +00:00
|
|
|
buildAndRunTest "callrpc"
|