nim-status/Makefile

433 lines
12 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 \
clean-migration-file \
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 \
migrations \
2020-10-08 16:08:52 +00:00
nat-libs-sub \
nats \
nim_status \
nim_status_go \
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:
cd vendor/nim-sqlcipher && $(MAKE) clean-build-dirs
cd vendor/nim-sqlcipher && $(MAKE) clean-sqlcipher
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
# in msys2 environment miniupnpc's Makefile.mingw's invocation of
# `wingenminiupnpcstrings.exe` will fail if containing directory is not in PATH
nats:
PATH="$(shell pwd)/vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc:$${PATH}" \
$(MAKE) nat-libs
PATH="$(shell pwd)/vendor/nim-waku/vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc:$${PATH}" \
$(MAKE) nat-libs-sub
deps: | deps-common nats
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) "$@"
2020-10-08 16:08:52 +00:00
+ 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
ifeq ($(SQLCIPHER_STATIC),false)
SQLCIPHER ?= vendor/nim-sqlcipher/lib/libsqlcipher.$(SHARED_LIB_EXT)
else
SQLCIPHER ?= vendor/nim-sqlcipher/lib/libsqlcipher.a
endif
2020-10-08 16:08:52 +00:00
$(SQLCIPHER): | deps
echo -e $(BUILD_MSG) "$@"
2020-10-08 16:08:52 +00:00
+ cd vendor/nim-sqlcipher && \
$(ENV_SCRIPT) $(MAKE) USE_SYSTEM_NIM=1 sqlcipher
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)
PCRE_LDFLAGS := -L$(PCRE_LIB_DIR) -lpcre
2020-10-08 16:08:52 +00:00
else
PCRE_LDFLAGS := $(PCRE_LIB_DIR)/libpcre.a
endif
endif
ifneq ($(PCRE_STATIC),false)
NIM_PARAMS += --define:usePcreHeader --dynlibOverride:pcre
else ifeq ($(detected_OS),Windows)
# to avoid Nim looking for pcre64.dll since we assume msys2 environment
NIM_PARAMS += --define:usePcreHeader
2020-10-08 16:08:52 +00:00
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
MIGRATIONS ?= nim_status/migrations/sql_scripts_app.nim
$(MIGRATIONS): | deps
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --verbosity:0 nim_status/migrations/sql_generate.nim
nim_status/migrations/sql_generate nim_status/migrations/accounts > nim_status/migrations/sql_scripts_accounts.nim
nim_status/migrations/sql_generate nim_status/migrations/app > nim_status/migrations/sql_scripts_app.nim
clean-migration-file:
rm -f nim_status/migrations/sql_scripts_accounts.nim
rm -f nim_status/migrations/sql_scripts_app.nim
migrations: clean-migration-file $(MIGRATIONS)
2020-10-08 16:08:52 +00:00
NIMSTATUS ?= build/nim_status.a
$(NIMSTATUS): $(SQLCIPHER) $(MIGRATIONS)
2020-10-08 16:08:52 +00:00
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:$@ \
nim_status/c/shim.nim
cp nimcache/nim_status/shim.h build/nim_status.h
mv nim_status.a build/
2020-10-08 16:08:52 +00:00
nim_status: $(NIMSTATUS)
NIMSTATUS_GO ?= build/nim_status_go.a
$(NIMSTATUS_GO):
echo -e $(BUILD_MSG) "$@"
+ mkdir -p build
$(ENV_SCRIPT) nim c $(NIM_PARAMS) \
--app:staticLib \
--header \
--nimcache:nimcache/nim_status_go \
--noMain \
--threads:on \
--tlsEmulation:off \
-o:$@ \
nim_status/c/go/shim.nim
cp nimcache/nim_status_go/shim.h build/nim_status_go.h
mv nim_status_go.a build/
nim_status_go: $(NIMSTATUS_GO)
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)
ifeq ($(SQLCIPHER_STATIC),false)
2020-12-17 03:44:07 +00:00
PATH_TEST ?= $(shell pwd)/$(shell dirname $(SQLCIPHER)):$(STATUSGO_LIB_DIR):$${PATH}
ifeq ($(PCRE_STATIC),false)
ifeq ($(SSL_STATIC),false)
LD_LIBRARY_PATH_TEST ?= $(shell pwd)/$(shell dirname $(SQLCIPHER)):$(PCRE_LIB_DIR):$(SSL_LIB_DIR):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
else
LD_LIBRARY_PATH_TEST ?= $(shell pwd)/$(shell dirname $(SQLCIPHER)):$(PCRE_LIB_DIR):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
endif
else
ifeq ($(SSL_STATIC),false)
LD_LIBRARY_PATH_TEST ?= $(shell pwd)/$(shell dirname $(SQLCIPHER)):$(SSL_LIB_DIR):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
else
LD_LIBRARY_PATH_TEST ?= $(shell pwd)/$(shell dirname $(SQLCIPHER)):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
endif
endif
else
PATH_TEST ?= $(STATUSGO_LIB_DIR):$${PATH}
ifeq ($(PCRE_STATIC),false)
ifeq ($(SSL_STATIC),false)
LD_LIBRARY_PATH_TEST ?= $(PCRE_LIB_DIR):$(SSL_LIB_DIR):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
else
LD_LIBRARY_PATH_TEST ?= $(PCRE_LIB_DIR):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
endif
else
ifeq ($(SSL_STATIC),false)
LD_LIBRARY_PATH_TEST ?= $(SSL_LIB_DIR):$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
else
LD_LIBRARY_PATH_TEST ?= :$(STATUSGO_LIB_DIR)$${LD_LIBRARY_PATH:+:$${LD_LIBRARY_PATH}}
endif
endif
endif
ifeq ($(SQLCIPHER_STATIC),false)
ifeq ($(detected_OS),Windows)
SQLCIPHER_LDFLAGS_TEST := -L$(shell cygpath -m $(shell pwd)/$(shell dirname $(SQLCIPHER))) -lsqlcipher
else
SQLCIPHER_LDFLAGS_TEST := -L$(shell pwd)/$(shell dirname $(SQLCIPHER)) -lsqlcipher
endif
else
ifeq ($(detected_OS),Windows)
SQLCIPHER_LDFLAGS_TEST := $(shell cygpath -m $(shell pwd)/$(SQLCIPHER))
else
SQLCIPHER_LDFLAGS_TEST := $(shell pwd)/$(SQLCIPHER)
endif
endif
ifeq ($(detected_OS),Windows)
STATUSGO_SQLCIPHER_LDFLAGS_TEST := -L$(STATUSGO_LIB_DIR) -lstatus $(SQLCIPHER_LDFLAGS_TEST)
else
STATUSGO_SQLCIPHER_LDFLAGS_TEST := $(SQLCIPHER_LDFLAGS_TEST) -L$(STATUSGO_LIB_DIR) -lstatus
endif
2020-10-08 16:08:52 +00:00
ifeq ($(detected_OS),Linux)
PLATFORM_FLAGS_TEST_C ?= -ldl
else ifeq ($(detected_OS),macOS)
PLATFORM_FLAGS_TEST_C ?= -Wl,-headerpad_max_install_names
2020-10-08 16:08:52 +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
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) \
-I$(shell pwd)/vendor/nimbus-build-system/vendor/Nim/lib \
2020-10-08 16:08:52 +00:00
test/c/$(TEST_NAME).c \
$(TEST_DEPS) \
2020-10-08 16:08:52 +00:00
$(PCRE_LDFLAGS) \
$(STATUSGO_SQLCIPHER_LDFLAGS_TEST) \
2020-10-08 16:08:52 +00:00
$(SSL_LDFLAGS) \
-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 \
$(STATUSGO_LIB_DIR) \
2020-10-08 16:08:52 +00:00
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
SHIMS_FOR_TEST_C_INCLUDES ?= -I$(shell pwd)/test/c/build
2020-10-08 16:08:52 +00:00
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_GO)
$(MAKE) TEST_DEPS=$(NIMSTATUS_GO) \
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
test-nim: $(STATUSGO) $(SQLCIPHER) $(MIGRATIONS)
2020-10-08 16:08:52 +00:00
ifeq ($(detected_OS),macOS)
NIMSTATUS_CFLAGS="$(NIMSTATUS_CFLAGS)" \
PCRE_LDFLAGS="$(PCRE_LDFLAGS)" \
PCRE_STATIC="$(PCRE_STATIC)" \
SQLCIPHER_LDFLAGS="$(SQLCIPHER_LDFLAGS_TEST)" \
2020-10-08 16:08:52 +00:00
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)" \
SQLCIPHER_LDFLAGS="$(SQLCIPHER_LDFLAGS_TEST)" \
2020-10-08 16:08:52 +00:00
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)" \
SQLCIPHER_LDFLAGS="$(SQLCIPHER_LDFLAGS_TEST)" \
2020-10-08 16:08:52 +00:00
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