nim-status/Makefile

347 lines
9.1 KiB
Makefile
Raw Normal View History

# Copyright (c) 2020 Status Research & Development GmbH. Licensed under
# either of:
# - Apache License, version 2.0
# - MIT license
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
SHELL := bash # the shell used internally by Make
# used inside the included makefiles
BUILD_SYSTEM_DIR := vendor/nimbus-build-system
2020-10-08 16:08:52 +00:00
# Deactivate nimbus-build-system LINK_PCRE logic in favor of PCRE variables
# defined later in this Makefile.
export LINK_PCRE := 0
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
-include $(BUILD_SYSTEM_DIR)/makefiles/variables.mk
.PHONY: \
all \
clean \
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
clean-build-dirs \
clean-data-dirs \
2020-10-08 16:08:52 +00:00
clean-sqlcipher \
clean-status-go \
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
create-data-dirs \
deps \
2020-10-08 16:08:52 +00:00
nat-libs-sub \
nim_status \
2020-10-08 16:08:52 +00:00
shims-for-test-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
status-go \
2020-10-08 16:08:52 +00:00
sqlcipher \
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
test \
2020-10-08 16:08:52 +00:00
test-c \
test-c-template \
test-nim \
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
update
ifeq ($(NIM_PARAMS),)
# "variables.mk" was not included, so we update the submodules.
GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
.DEFAULT:
+@ echo -e "Git submodules not found. Running '$(GIT_SUBMODULE_UPDATE)'.\n"; \
$(GIT_SUBMODULE_UPDATE); \
echo
# Now that the included *.mk files appeared, and are newer than this file, Make will restart itself:
# https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles
#
# After restarting, it will execute its original goal, so we don't have to start a child Make here
# with "$(MAKE) $(MAKECMDGOALS)". Isn't hidden control flow great?
else # "variables.mk" was included. Business as usual until the end of this file.
all: nim_status
# must be included after the default target
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk
2020-10-08 16:08:52 +00:00
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
2020-10-08 16:08:52 +00:00
else ifeq ($(strip $(shell uname)),Darwin)
detected_OS := macOS
else
2020-10-08 16:08:52 +00:00
# e.g. Linux
detected_OS := $(strip $(shell uname))
endif
2020-10-08 16:08:52 +00:00
clean: | clean-common clean-build-dirs clean-data-dirs clean-sqlcipher clean-status-go
2020-10-08 16:08:52 +00:00
clean-build-dirs:
rm -rf \
build \
test/c/build \
test/nim/build
2020-10-08 16:08:52 +00:00
clean-data-dirs:
rm -rf \
data \
keystore \
noBackup
2020-10-08 16:08:52 +00:00
clean-sqlcipher:
rm -rf \
$(shell dirname $(shell dirname $(SQLCIPHER)))/nimcache \
$(shell dirname $(shell dirname $(SQLCIPHER)))/sqlcipher \
$(shell dirname $(shell dirname $(SQLCIPHER)))/sqlite
2020-10-08 16:08:52 +00:00
clean-status-go:
rm -rf $(shell dirname $(STATUSGO))/*
2020-10-08 16:08:52 +00:00
create-data-dirs:
mkdir -p \
data \
keystore \
noBackup
2020-10-08 16:08:52 +00:00
# nim-nat-traversal assumes nat-libs are available in its parent's vendor
nat-libs-sub:
cd vendor/nim-waku && \
$(ENV_SCRIPT) $(MAKE) USE_SYSTEM_NIM=1 nat-libs
2020-10-08 16:08:52 +00:00
deps: | deps-common nat-libs nat-libs-sub
2020-10-08 16:08:52 +00:00
update: | update-common
2020-10-08 16:08:52 +00:00
ifndef SHARED_LIB_EXT
ifeq ($(detected_OS),macOS)
SHARED_LIB_EXT := dylib
else ifeq ($(detected_OS),Windows)
SHARED_LIB_EXT := dll
else
SHARED_LIB_EXT := so
endif
endif
2020-10-08 16:08:52 +00:00
# should be an absolute path when supplied by user
ifndef STATUSGO
STATUSGO := vendor/status-go/build/bin/libstatus.$(SHARED_LIB_EXT)
STATUSGO_LIB_DIR := $(shell pwd)/$(shell dirname $(STATUSGO))
else
STATUSGO_LIB_DIR := $(shell dirname $(STATUSGO))
endif
2020-10-08 16:08:52 +00:00
$(STATUSGO): | deps
echo -e $(BUILD_MSG) "status-go"
+ cd vendor/status-go && \
$(MAKE) statusgo-shared-library $(HANDLE_OUTPUT)
2020-10-08 16:08:52 +00:00
status-go: $(STATUSGO)
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
2020-10-08 16:08:52 +00:00
# These SSL variables and logic work like those in nim-sqlcipher's Makefile
SSL_STATIC ?= true
SSL_INCLUDE_DIR ?= /usr/include
ifeq ($(SSL_INCLUDE_DIR),)
override SSL_INCLUDE_DIR = /usr/include
endif
SSL_LIB_DIR ?= /usr/lib/x86_64-linux-gnu
ifeq ($(SSL_LIB_DIR),)
override SSL_LIB_DIR = /usr/lib/x86_64-linux-gnu
endif
ifndef SSL_LDFLAGS
ifeq ($(SSL_STATIC),false)
SSL_LDFLAGS := -L$(SSL_LIB_DIR) -lssl -lcrypto
else
SSL_LDFLAGS := $(SSL_LIB_DIR)/libssl.a $(SSL_LIB_DIR)/libcrypto.a
endif
ifeq ($(detected_OS),Windows)
SSL_LDFLAGS += -lws2_32
endif
endif
NIM_PARAMS += --define:ssl
ifneq ($(SSL_STATIC),false)
NIM_PARAMS += --dynlibOverride:ssl
endif
2020-10-08 16:08:52 +00:00
SQLCIPHER ?= vendor/nim-sqlcipher/sqlcipher/sqlite.nim
2020-10-08 16:08:52 +00:00
$(SQLCIPHER): | deps
echo -e $(BUILD_MSG) "Nim wrapper for SQLCipher"
+ cd vendor/nim-sqlcipher && \
$(ENV_SCRIPT) $(MAKE) USE_SYSTEM_NIM=1 sqlite.nim
2020-10-08 16:08:52 +00:00
sqlcipher: $(SQLCIPHER)
PCRE_STATIC ?= true
PCRE_INCLUDE_DIR ?= /usr/include
ifeq ($(PCRE_INCLUDE_DIR),)
override PCRE_INCLUDE_DIR = /usr/include
endif
PCRE_LIB_DIR ?= /usr/lib/x86_64-linux-gnu
ifeq ($(PCRE_LIB_DIR),)
override PCRE_LIB_DIR = /usr/lib/x86_64-linux-gnu
endif
ifndef PCRE_LDFLAGS
ifeq ($(PCRE_STATIC),false)
ifeq ($(detected_OS),Windows)
PCRE_LDFLAGS := -L$(PCRE_LIB_DIR) -lpcre64
else
PCRE_LDFLAGS := -L$(PCRE_LIB_DIR) -lpcre
endif
else
PCRE_LDFLAGS := $(PCRE_LIB_DIR)/libpcre.a
endif
endif
ifneq ($(PCRE_STATIC),false)
NIM_PARAMS += --define:usePcreHeader --dynlibOverride:pcre
endif
2020-10-08 16:08:52 +00:00
ifndef NIMSTATUS_CFLAGS
ifneq ($(PCRE_STATIC),false)
ifeq ($(detected_OS),Windows)
NIMSTATUS_CFLAGS := -DPCRE_STATIC -I$(PCRE_INCLUDE_DIR)
else
NIMSTATUS_CFLAGS := -I$(PCRE_INCLUDE_DIR)
endif
endif
endif
ifneq ($(NIMSTATUS_CFLAGS),)
NIM_PARAMS += --passC:"$(NIMSTATUS_CFLAGS)"
endif
NIMSTATUS ?= build/nim_status.a
2020-10-08 16:08:52 +00:00
$(NIMSTATUS): $(SQLCIPHER)
echo -e $(BUILD_MSG) "$@"
+ mkdir -p build
$(ENV_SCRIPT) nim c $(NIM_PARAMS) \
--app:staticLib \
--header \
2020-10-08 16:08:52 +00:00
--nimcache:nimcache/nim_status \
--noMain \
2020-10-08 16:08:52 +00:00
--threads:on \
--tlsEmulation:off \
-o:$@ \
2020-10-08 16:08:52 +00:00
nim_status/c/nim_status.nim
cp nimcache/nim_status/nim_status.h build/nim_status.h
mv nim_status.a build/
2020-10-08 16:08:52 +00:00
nim_status: $(NIMSTATUS)
2020-10-08 16:08:52 +00:00
SHIMS_FOR_TEST_C ?= test/c/build/shims.a
$(SHIMS_FOR_TEST_C): $(SQLCIPHER)
echo -e $(BUILD_MSG) "$@"
+ mkdir -p test/c/build
$(ENV_SCRIPT) nim c $(NIM_PARAMS) \
--app:staticLib \
--header \
2020-10-08 16:08:52 +00:00
--nimcache:nimcache/shims \
--noMain \
2020-10-08 16:08:52 +00:00
--threads:on \
--tlsEmulation:off \
-o:$@ \
2020-10-08 16:08:52 +00:00
test/c/shims.nim
cp nimcache/shims/shims.h test/c/build/shims.h
mv shims.a test/c/build/
shims-for-test-c: $(SHIMS_FOR_TEST_C)
# Currently assumes the _STATIC variables are all false or all not false
# LD_LIBRARY_PATH is supplied when running tests on Linux
# PATH is supplied when running tests on Windows
ifeq ($(PCRE_STATIC),false)
ifeq ($(SQLITE_STATIC),false)
ifeq ($(SSL_STATIC),false)
LD_LIBRARY_PATH_TEST ?= $(PCRE_LIB_DIR):$(shell pwd)/$(shell dirname $(SQLCIPHER)):$(SSL_LIB_DIR):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
PATH_TEST ?= $(shell cygpath $(shell dirname $(PCRE_LIB_DIR))):$(shell cygpath $(PCRE_LIB_DIR)):$(shell pwd)/$(shell dirname $(SQLCIPHER)):$(shell cygpath $(shell dirname $(SSL_LIB_DIR))):$(shell cygpath $(SSL_LIB_DIR)):$(STATUSGO_LIB_DIR):$${PATH}
endif
endif
else
LD_LIBRARY_PATH_TEST ?= $(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
PATH_TEST ?= $(STATUSGO_LIB_DIR):$${PATH}
endif
2020-10-08 16:08:52 +00:00
ifeq ($(detected_OS),Linux)
PLATFORM_FLAGS_TEST_C ?= -ldl
endif
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
2020-10-08 16:08:52 +00:00
test-c-template: $(STATUSGO) clean-data-dirs create-data-dirs
echo "Compiling 'test/c/$(TEST_NAME)'"
+ mkdir -p test/c/build
$(ENV_SCRIPT) $(CC) \
$(TEST_INCLUDES) \
2020-10-08 16:08:52 +00:00
-I"$(shell pwd)/vendor/nimbus-build-system/vendor/Nim/lib" \
test/c/$(TEST_NAME).c \
$(TEST_DEPS) \
2020-10-08 16:08:52 +00:00
$(PCRE_LDFLAGS) \
$(SSL_LDFLAGS) \
-L$(STATUSGO_LIB_DIR) \
-lstatus \
-lm \
-pthread \
2020-10-08 16:08:52 +00:00
$(PLATFORM_FLAGS_TEST_C) \
-o test/c/build/$(TEST_NAME) $(HANDLE_OUTPUT)
[[ $$? = 0 ]] && \
2020-10-08 16:08:52 +00:00
(([[ $(detected_OS) = macOS ]] && \
install_name_tool -add_rpath \
2020-10-08 16:08:52 +00:00
"$(STATUSGO_LIB_DIR)" \
test/c/build/$(TEST_NAME) $(HANDLE_OUTPUT) && \
install_name_tool -change \
libstatus.dylib \
@rpath/libstatus.dylib \
2020-10-08 16:08:52 +00:00
test/c/build/$(TEST_NAME) $(HANDLE_OUTPUT)) || true)
echo "Executing 'test/c/build/$(TEST_NAME)'"
ifeq ($(detected_OS),macOS)
./test/c/build/$(TEST_NAME)
else ifeq ($(detected_OS),Windows)
PATH="$(PATH_TEST)" \
2020-10-08 16:08:52 +00:00
./test/c/build/$(TEST_NAME)
2020-07-03 12:28:12 +00:00
else
LD_LIBRARY_PATH="$(LD_LIBRARY_PATH_TEST)" \
2020-10-08 16:08:52 +00:00
./test/c/build/$(TEST_NAME)
2020-07-03 12:28:12 +00:00
endif
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
2020-10-08 16:08:52 +00:00
SHIMS_FOR_TEST_C_INCLUDES ?= -I\"$(shell pwd)/test/c/build\"
LOGIN_TEST_INCLUDES ?= -I\"$(shell pwd)/build\"
2020-10-08 16:08:52 +00:00
test-c:
rm -rf test/c/build
$(MAKE) $(SHIMS_FOR_TEST_C)
$(MAKE) TEST_DEPS=$(SHIMS_FOR_TEST_C) \
TEST_INCLUDES=$(SHIMS_FOR_TEST_C_INCLUDES) \
TEST_NAME=shims \
test-c-template
2020-10-08 16:08:52 +00:00
rm -rf test/c/build
$(MAKE) $(NIMSTATUS)
$(MAKE) TEST_DEPS=$(NIMSTATUS) \
2020-10-08 16:08:52 +00:00
TEST_INCLUDES=$(LOGIN_TEST_INCLUDES) \
TEST_NAME=login \
test-c-template
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
2020-10-08 16:08:52 +00:00
test-nim: $(STATUSGO) $(SQLCIPHER)
ifeq ($(detected_OS),macOS)
NIMSTATUS_CFLAGS="$(NIMSTATUS_CFLAGS)" \
PCRE_LDFLAGS="$(PCRE_LDFLAGS)" \
PCRE_STATIC="$(PCRE_STATIC)" \
SSL_LDFLAGS="$(SSL_LDFLAGS)" \
SSL_STATIC="$(SSL_STATIC)" \
STATUSGO_LIB_DIR="$(STATUSGO_LIB_DIR)" \
$(ENV_SCRIPT) nimble tests
else ifeq ($(detected_OS),Windows)
2020-10-08 16:08:52 +00:00
NIMSTATUS_CFLAGS="$(NIMSTATUS_CFLAGS)" \
PATH="$(PATH_TEST)" \
2020-10-08 16:08:52 +00:00
PCRE_LDFLAGS="$(PCRE_LDFLAGS)" \
PCRE_STATIC="$(PCRE_STATIC)" \
SSL_LDFLAGS="$(SSL_LDFLAGS)" \
SSL_STATIC="$(SSL_STATIC)" \
STATUSGO_LIB_DIR="$(STATUSGO_LIB_DIR)" \
$(ENV_SCRIPT) nimble tests
else
LD_LIBRARY_PATH="$(LD_LIBRARY_PATH_TEST)" \
2020-10-08 16:08:52 +00:00
NIMSTATUS_CFLAGS="$(NIMSTATUS_CFLAGS)" \
PCRE_LDFLAGS="$(PCRE_LDFLAGS)" \
PCRE_STATIC="$(PCRE_STATIC)" \
SSL_LDFLAGS="$(SSL_LDFLAGS)" \
SSL_STATIC="$(SSL_STATIC)" \
STATUSGO_LIB_DIR="$(STATUSGO_LIB_DIR)" \
$(ENV_SCRIPT) nimble tests
endif
2020-10-08 16:08:52 +00:00
test: test-nim test-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
endif # "variables.mk" was not included