2020-07-02 18:40:49 +00:00
|
|
|
# Copyright (c) 2020 Status Research & Development GmbH. Licensed under
|
2020-07-02 13:20:16 +00:00
|
|
|
# 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
|
|
|
|
|
2020-07-02 13:20:16 +00:00
|
|
|
# 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 \
|
2021-03-28 23:03:18 +00:00
|
|
|
chat \
|
2020-07-02 13:20:16 +00:00
|
|
|
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 \
|
2021-03-15 15:55:19 +00:00
|
|
|
clean-migration-files \
|
2020-10-08 16:08:52 +00:00
|
|
|
clean-sqlcipher \
|
2020-07-02 13:20:16 +00:00
|
|
|
deps \
|
2020-12-22 20:24:58 +00:00
|
|
|
migrations \
|
2020-10-08 16:08:52 +00:00
|
|
|
nat-libs-sub \
|
2021-03-28 23:03:18 +00:00
|
|
|
rlnlib-sub \
|
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 \
|
2021-03-28 23:03:18 +00:00
|
|
|
update \
|
|
|
|
waku_chat2
|
2020-07-02 13:20:16 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2021-03-15 15:55:19 +00:00
|
|
|
all: sqlcipher
|
2020-07-02 13:20:16 +00:00
|
|
|
|
|
|
|
# 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...
|
2020-07-02 13:20:16 +00:00
|
|
|
detected_OS := Windows
|
2020-10-08 16:08:52 +00:00
|
|
|
else ifeq ($(strip $(shell uname)),Darwin)
|
|
|
|
detected_OS := macOS
|
2020-07-02 13:20:16 +00:00
|
|
|
else
|
2020-10-08 16:08:52 +00:00
|
|
|
# e.g. Linux
|
2020-07-02 13:20:16 +00:00
|
|
|
detected_OS := $(strip $(shell uname))
|
|
|
|
endif
|
|
|
|
|
2021-03-15 15:55:19 +00:00
|
|
|
clean: | clean-common clean-build-dirs clean-migration-files clean-sqlcipher
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
clean-build-dirs:
|
|
|
|
rm -rf \
|
2021-03-15 15:55:19 +00:00
|
|
|
test/build
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2021-03-15 15:55:19 +00:00
|
|
|
clean-migration-files:
|
|
|
|
rm -f \
|
|
|
|
nim_status/migrations/sql_scripts_accounts.nim \
|
|
|
|
nim_status/migrations/sql_scripts_app.nim
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
clean-sqlcipher:
|
2020-12-17 21:54:38 +00:00
|
|
|
cd vendor/nim-sqlcipher && $(MAKE) clean-build-dirs
|
|
|
|
cd vendor/nim-sqlcipher && $(MAKE) clean-sqlcipher
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
LIBMINIUPNPC := $(shell pwd)/vendor/nim-waku/vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc/libminiupnpc.a
|
|
|
|
LIBNATPMP := $(shell pwd)/vendor/nim-waku/vendor/nim-nat-traversal/vendor/libnatpmp-upstream/libnatpmp.a
|
|
|
|
|
2021-02-16 19:34:36 +00:00
|
|
|
# nat-libs target assumes libs are in vendor subdir of working directory;
|
|
|
|
# also, in msys2 environment miniupnpc's Makefile.mingw's invocation of
|
|
|
|
# `wingenminiupnpcstrings.exe` will fail if containing directory is not in PATH
|
2021-03-28 23:03:18 +00:00
|
|
|
$(LIBMINIUPNPC):
|
2020-10-08 16:08:52 +00:00
|
|
|
cd vendor/nim-waku && \
|
2021-02-16 19:34:36 +00:00
|
|
|
PATH="$$(pwd)/vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc:$${PATH}" \
|
2020-10-08 16:08:52 +00:00
|
|
|
$(ENV_SCRIPT) $(MAKE) USE_SYSTEM_NIM=1 nat-libs
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
$(LIBNATPMP): $(LIBMINIUPNPC)
|
|
|
|
|
|
|
|
nat-libs-sub: $(LIBMINIUPNPC) $(LIBNATPMP)
|
|
|
|
|
|
|
|
deps: | deps-common nat-libs-sub rlnlib-sub
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
update: | update-common
|
2020-08-10 16:48:30 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
ifndef SHARED_LIB_EXT
|
|
|
|
ifeq ($(detected_OS),macOS)
|
2021-03-28 23:03:18 +00:00
|
|
|
SHARED_LIB_EXT := dylib
|
2020-10-08 16:08:52 +00:00
|
|
|
else ifeq ($(detected_OS),Windows)
|
2021-03-28 23:03:18 +00:00
|
|
|
SHARED_LIB_EXT := dll
|
2020-10-08 16:08:52 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
SHARED_LIB_EXT := so
|
2020-10-08 16:08:52 +00:00
|
|
|
endif
|
2020-08-10 16:48:30 +00:00
|
|
|
endif
|
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
# For release builds of e.g. `examples/chat.nim`, it would be good to support
|
|
|
|
# older versions of macOS (older relative to the machine that's used to build
|
|
|
|
# the executable); for that to work, linking must be done against builds of
|
|
|
|
# OpenSSL, PCRE, RLN, etc. that are properly built to support the same older
|
|
|
|
# version of macOS we desire to target. That means compiling them ourselves or
|
|
|
|
# downloading pre-built Homebrew bottles for that older version of macOS
|
|
|
|
# (keeping in mind the oldest version of macOS that Homebrew supports,
|
|
|
|
# currently 10.14), tweaking Rust compiler flags, etc. That logic should
|
|
|
|
# probably be triggered with respect to `RELEASE=true` and then setting up
|
|
|
|
# and/or overriding variables and running targets in this Makefile (via
|
|
|
|
# `$(MAKE) [target]`) to do steps that are unnecessary apart from release
|
|
|
|
# builds for macOS.
|
|
|
|
# MACOSX_DEPLOYMENT_TARGET ?= 10.14
|
|
|
|
|
|
|
|
RELEASE ?= false
|
|
|
|
|
|
|
|
ifneq ($(RELEASE),false)
|
|
|
|
LOG_LEVEL ?= INFO
|
|
|
|
else
|
|
|
|
LOG_LEVEL ?= DEBUG
|
|
|
|
endif
|
|
|
|
ifeq ($(LOG_LEVEL),)
|
|
|
|
override LOG_LEVEL = DEBUG
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(RELEASE),false)
|
|
|
|
RLN_CARGO_BUILD_FLAGS := --release
|
|
|
|
RLN_TARGET_SUBDIR := release
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
WIN_STATIC := true
|
|
|
|
else
|
|
|
|
WIN_STATIC := false
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
RLN_TARGET_SUBDIR := debug
|
|
|
|
WIN_STATIC := false
|
|
|
|
endif
|
|
|
|
RLN_LIB_DIR := $(shell pwd)/vendor/nim-waku/vendor/rln/target/$(RLN_TARGET_SUBDIR)
|
|
|
|
RLN_STATIC ?= true
|
|
|
|
ifeq ($(RLN_STATIC),false)
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
RLN_LIB := $(RLN_LIB_DIR)/librln.$(SHARED_LIB_EXT).a
|
|
|
|
else
|
|
|
|
RLN_LIB := $(RLN_LIB_DIR)/librln.$(SHARED_LIB_EXT)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
RLN_LIB := $(RLN_LIB_DIR)/librln.a
|
2020-10-08 16:08:52 +00:00
|
|
|
endif
|
2021-03-28 23:03:18 +00:00
|
|
|
|
|
|
|
$(RLN_LIB):
|
|
|
|
cd vendor/nim-waku && \
|
|
|
|
cargo build \
|
|
|
|
$(RLN_CARGO_BUILD_FLAGS) \
|
|
|
|
--manifest-path vendor/rln/Cargo.toml
|
|
|
|
|
|
|
|
ifeq ($(detected_OS),macOS)
|
|
|
|
install_name_tool -id \
|
|
|
|
@rpath/librln.$(SHARED_LIB_EXT) \
|
|
|
|
$(RLN_LIB_DIR)/librln.$(SHARED_LIB_EXT)
|
2020-10-08 16:08:52 +00:00
|
|
|
endif
|
2021-03-28 23:03:18 +00:00
|
|
|
|
|
|
|
rlnlib-sub: $(RLN_LIB)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
migrations: clean-migration-files $(MIGRATIONS)
|
|
|
|
|
|
|
|
# These SSL variables and logic work like those in nim-sqlcipher's Makefile
|
|
|
|
ifeq ($(detected_OS),macOS)
|
|
|
|
SSL_INCLUDE_DIR ?= /usr/local/opt/openssl/include
|
|
|
|
ifeq ($(SSL_INCLUDE_DIR),)
|
|
|
|
override SSL_INCLUDE_DIR = /usr/local/opt/openssl/include
|
|
|
|
endif
|
|
|
|
SSL_LIB_DIR ?= /usr/local/opt/openssl/lib
|
|
|
|
ifeq ($(SSL_LIB_DIR),)
|
|
|
|
override SSL_LIB_DIR = /usr/local/opt/openssl/lib
|
|
|
|
endif
|
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
SSL_INCLUDE_DIR ?= /mingw64/include/openssl
|
|
|
|
ifeq ($(SSL_INCLUDE_DIR),)
|
|
|
|
override SSL_INCLUDE_DIR = /mingw64/include/openssl
|
|
|
|
endif
|
|
|
|
SSL_LIB_DIR ?= /mingw64/lib
|
|
|
|
ifeq ($(SSL_LIB_DIR),)
|
|
|
|
override SSL_LIB_DIR = /mingw64/lib
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
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
|
|
|
|
endif
|
|
|
|
SSL_STATIC ?= true
|
2020-10-08 16:08:52 +00:00
|
|
|
ifndef SSL_LDFLAGS
|
|
|
|
ifeq ($(SSL_STATIC),false)
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
SSL_LDFLAGS := -L$(shell cygpath -m $(SSL_LIB_DIR)) -lssl -lcrypto
|
|
|
|
else
|
|
|
|
SSL_LDFLAGS := -L$(SSL_LIB_DIR) -lssl -lcrypto
|
|
|
|
endif
|
2020-10-08 16:08:52 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
SSL_LDFLAGS := $(shell cygpath -m $(SSL_LIB_DIR)/libssl.a) $(shell cygpath -m $(SSL_LIB_DIR)/libcrypto.a)
|
|
|
|
else
|
|
|
|
SSL_LDFLAGS := $(SSL_LIB_DIR)/libssl.a $(SSL_LIB_DIR)/libcrypto.a
|
|
|
|
endif
|
2020-10-08 16:08:52 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
SSL_LDFLAGS += -lws2_32
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
NIM_PARAMS += --define:ssl
|
|
|
|
ifneq ($(SSL_STATIC),false)
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NIM_PARAMS += --dynlibOverride:ssl- --dynlibOverride:crypto- --define:noOpenSSLHacks --define:sslVersion:"("
|
|
|
|
else
|
|
|
|
NIM_PARAMS += --dynlibOverride:ssl --dynlibOverride:crypto
|
|
|
|
endif
|
2020-07-02 13:20:16 +00:00
|
|
|
endif
|
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
SQLCIPHER_STATIC ?= true
|
2020-12-17 21:54:38 +00:00
|
|
|
ifeq ($(SQLCIPHER_STATIC),false)
|
|
|
|
SQLCIPHER ?= vendor/nim-sqlcipher/lib/libsqlcipher.$(SHARED_LIB_EXT)
|
|
|
|
else
|
|
|
|
SQLCIPHER ?= vendor/nim-sqlcipher/lib/libsqlcipher.a
|
|
|
|
endif
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
$(SQLCIPHER): | deps
|
2020-12-17 21:54:38 +00:00
|
|
|
echo -e $(BUILD_MSG) "$@"
|
2020-10-08 16:08:52 +00:00
|
|
|
+ cd vendor/nim-sqlcipher && \
|
2021-03-28 23:03:18 +00:00
|
|
|
$(ENV_SCRIPT) $(MAKE) \
|
|
|
|
SQLCIPHER_STATIC=$(SQLCIPHER_STATIC) \
|
|
|
|
SSL_INCLUDE_DIR="$(SSL_INCLUDE_DIR)" \
|
|
|
|
SSL_LIB_DIR="$(SSL_LIB_DIR)" \
|
|
|
|
SSL_STATIC=$(SSL_STATIC) \
|
|
|
|
USE_SYSTEM_NIM=1 \
|
|
|
|
sqlcipher
|
2020-07-02 13:20:16 +00:00
|
|
|
|
2020-10-08 16:08:52 +00:00
|
|
|
sqlcipher: $(SQLCIPHER)
|
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),macOS)
|
|
|
|
PCRE_INCLUDE_DIR ?= /usr/local/opt/pcre/include
|
|
|
|
ifeq ($(PCRE_INCLUDE_DIR),)
|
|
|
|
override PCRE_INCLUDE_DIR = /usr/local/opt/pcre/include
|
|
|
|
endif
|
|
|
|
PCRE_LIB_DIR ?= /usr/local/opt/pcre/lib
|
|
|
|
ifeq ($(PCRE_LIB_DIR),)
|
|
|
|
override PCRE_LIB_DIR = /usr/local/opt/pcre/lib
|
|
|
|
endif
|
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
PCRE_INCLUDE_DIR ?= /mingw64/include
|
|
|
|
ifeq ($(PCRE_INCLUDE_DIR),)
|
|
|
|
override PCRE_INCLUDE_DIR = /mingw64/include
|
|
|
|
endif
|
|
|
|
PCRE_LIB_DIR ?= /mingw64/lib
|
|
|
|
ifeq ($(PCRE_LIB_DIR),)
|
|
|
|
override PCRE_LIB_DIR = /mingw64/lib
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
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
|
2020-10-08 16:08:52 +00:00
|
|
|
endif
|
2021-03-28 23:03:18 +00:00
|
|
|
PCRE_STATIC ?= true
|
2020-10-08 16:08:52 +00:00
|
|
|
ifndef PCRE_LDFLAGS
|
|
|
|
ifeq ($(PCRE_STATIC),false)
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
PCRE_LDFLAGS := -L$(shell cygpath -m $(PCRE_LIB_DIR)) -lpcre
|
|
|
|
else
|
|
|
|
PCRE_LDFLAGS := -L$(PCRE_LIB_DIR) -lpcre
|
|
|
|
endif
|
2020-10-08 16:08:52 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
PCRE_LDFLAGS := $(shell cygpath -m $(PCRE_LIB_DIR)/libpcre.a)
|
|
|
|
else
|
|
|
|
PCRE_LDFLAGS := $(PCRE_LIB_DIR)/libpcre.a
|
|
|
|
endif
|
2020-10-08 16:08:52 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifneq ($(PCRE_STATIC),false)
|
|
|
|
NIM_PARAMS += --define:usePcreHeader --dynlibOverride:pcre
|
2020-12-09 19:38:21 +00:00
|
|
|
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-07-02 13:20:16 +00:00
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),macOS)
|
|
|
|
NCURSES_LIB_DIR ?= /usr/local/opt/ncurses/lib
|
|
|
|
ifeq ($(NCURSES_LIB_DIR),)
|
|
|
|
override NCURSES_LIB_DIR = /usr/local/opt/ncurses/lib
|
|
|
|
endif
|
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
NCURSES_LIB_DIR ?= /mingw64/lib
|
|
|
|
ifeq ($(NCURSES_LIB_DIR),)
|
|
|
|
override NCURSES_LIB_DIR = /mingw64/lib
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
NCURSES_LIB_DIR ?= /usr/lib/x86_64-linux-gnu
|
|
|
|
ifeq ($(NCURSES_LIB_DIR),)
|
|
|
|
override NCURSES_LIB_DIR = /usr/lib/x86_64-linux-gnu
|
2020-10-08 16:08:52 +00:00
|
|
|
endif
|
|
|
|
endif
|
2021-03-28 23:03:18 +00:00
|
|
|
NCURSES_STATIC ?= true
|
|
|
|
ifndef NCURSES_LDFLAGS
|
|
|
|
ifeq ($(NCURSES_STATIC),false)
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NCURSES_LDFLAGS := -L$(shell cygpath -m $(NCURSES_LIB_DIR)) -lncursesw
|
|
|
|
else ifeq ($(detected_OS),macOS)
|
|
|
|
NCURSES_LDFLAGS := -L$(NCURSES_LIB_DIR) -lncursesw -rpath $(NCURSES_LIB_DIR)
|
2020-12-09 19:38:21 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
NCURSES_LDFLAGS := -L$(NCURSES_LIB_DIR) -lncursesw
|
2020-12-09 19:38:21 +00:00
|
|
|
endif
|
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NCURSES_LDFLAGS := $(shell cygpath -m $(NCURSES_LIB_DIR)/libncursesw.a)
|
|
|
|
else ifeq ($(detected_OS),macOS)
|
|
|
|
NCURSES_LDFLAGS := $(NCURSES_LIB_DIR)/libncursesw.a
|
2020-12-09 19:38:21 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
NCURSES_LDFLAGS := $(NCURSES_LIB_DIR)/libncursesw.a $(NCURSES_LIB_DIR)/libtinfo.a
|
2020-11-19 13:50:01 +00:00
|
|
|
endif
|
|
|
|
endif
|
2021-03-28 23:03:18 +00:00
|
|
|
endif
|
|
|
|
ifneq ($(PCRE_STATIC),false)
|
|
|
|
NIM_PARAMS += --dynlibOverride:ncursesw
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef RLN_LDFLAGS
|
|
|
|
ifeq ($(RLN_STATIC),false)
|
|
|
|
ifeq ($(detected_OS),macOS)
|
|
|
|
RLN_LDFLAGS := -L$(RLN_LIB_DIR) -lrln -rpath $(RLN_LIB_DIR)
|
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
ifneq ($(WIN_STATIC),false)
|
|
|
|
RLN_LDFLAGS := -L$(shell cygpath -m $(RLN_LIB_DIR)) -lrln -luserenv
|
|
|
|
else
|
|
|
|
RLN_LDFLAGS := -L$(shell cygpath -m $(RLN_LIB_DIR)) -lrln
|
|
|
|
endif
|
2020-12-09 19:38:21 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
RLN_LDFLAGS := -L$(RLN_LIB_DIR) -lrln
|
2020-12-09 19:38:21 +00:00
|
|
|
endif
|
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
RLN_LDFLAGS := $(shell cygpath -m $(RLN_LIB)) -luserenv
|
|
|
|
else ifeq ($(detected_OS),macOS)
|
|
|
|
RLN_LDFLAGS := $(RLN_LIB)
|
2020-12-09 19:38:21 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
RLN_LDFLAGS := $(RLN_LIB) -lm
|
2020-12-09 19:38:21 +00:00
|
|
|
endif
|
|
|
|
endif
|
2020-11-19 13:50:01 +00:00
|
|
|
endif
|
2021-03-28 23:03:18 +00:00
|
|
|
# ifneq ($(RLN_STATIC),false)
|
|
|
|
# usually `--dynlibOverride` is used in case of static linking and so would be
|
|
|
|
# used conditionally (see commented `ifneq` above), but because
|
|
|
|
# `vendor/nim-waku/waku/v2/protocol/waku_rln_relay/rln.nim` specifies the
|
|
|
|
# library with a relative path prefix (which isn't valid relative to root of
|
|
|
|
# this repo) it needs to be used in the case of shared or static linking
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NIM_PARAMS += --dynlibOverride:vendor\\rln\\target\\debug\\rln
|
|
|
|
else
|
|
|
|
NIM_PARAMS += --dynlibOverride:vendor/rln/target/debug/librln
|
|
|
|
endif
|
|
|
|
# endif
|
|
|
|
NIM_PARAMS += --define:rln
|
2020-11-19 13:50:01 +00:00
|
|
|
|
2020-12-18 06:45:19 +00:00
|
|
|
ifeq ($(SQLCIPHER_STATIC),false)
|
|
|
|
ifeq ($(detected_OS),Windows)
|
2021-03-28 23:03:18 +00:00
|
|
|
SQLCIPHER_LDFLAGS := -L$(shell cygpath -m $(shell pwd)/$(shell dirname $(SQLCIPHER))) -lsqlcipher
|
2020-12-18 06:45:19 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
SQLCIPHER_LDFLAGS := -L$(shell pwd)/$(shell dirname $(SQLCIPHER)) -lsqlcipher
|
2020-12-18 06:45:19 +00:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
ifeq ($(detected_OS),Windows)
|
2021-03-28 23:03:18 +00:00
|
|
|
SQLCIPHER_LDFLAGS := $(shell cygpath -m $(shell pwd)/$(SQLCIPHER))
|
2020-12-18 06:45:19 +00:00
|
|
|
else
|
2021-03-28 23:03:18 +00:00
|
|
|
SQLCIPHER_LDFLAGS := $(shell pwd)/$(SQLCIPHER)
|
2020-12-18 06:45:19 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
ifndef NIMSTATUS_CFLAGS
|
|
|
|
ifneq ($(PCRE_STATIC),false)
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NIMSTATUS_CFLAGS := -DPCRE_STATIC -I$(shell cygpath -m $(PCRE_INCLUDE_DIR))
|
|
|
|
else
|
|
|
|
NIMSTATUS_CFLAGS := -I$(PCRE_INCLUDE_DIR)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifneq ($(NIMSTATUS_CFLAGS),)
|
|
|
|
NIM_PARAMS += --passC:"$(NIMSTATUS_CFLAGS)"
|
|
|
|
endif
|
2021-03-19 15:17:27 +00:00
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
# for NCURSES, PCRE, SSL assume linkable from default location, e.g. /usr/lib/x86_64-linux-gnu
|
|
|
|
LD_LIBRARY_PATH_NIMBLE := $${LD_LIBRARY_PATH}
|
|
|
|
ifeq ($(RLN_STATIC),false)
|
|
|
|
LD_LIBRARY_PATH_NIMBLE := $(RLN_LIB_DIR):$(LD_LIBRARY_PATH_NIMBLE)
|
|
|
|
endif
|
|
|
|
ifeq ($(SQLCIPHER_STATIC),false)
|
|
|
|
LD_LIBRARY_PATH_NIMBLE := $(shell pwd)/$(shell dirname $(SQLCIPHER)):$(LD_LIBRARY_PATH_NIMBLE)
|
|
|
|
endif
|
2021-03-19 15:17:27 +00:00
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
# for NCURSES, PCRE, SSL assume already in PATH of MSYS2 shell, e.g. in /mingw64/bin
|
|
|
|
PATH_NIMBLE := $${PATH}
|
|
|
|
ifeq ($(RLN_STATIC),false)
|
|
|
|
PATH_NIMBLE := $(RLN_LIB_DIR):$(PATH_NIMBLE)
|
|
|
|
endif
|
|
|
|
ifeq ($(SQLCIPHER_STATIC),false)
|
|
|
|
PATH_NIMBLE := $(shell pwd)/$(shell dirname $(SQLCIPHER)):$(PATH_NIMBLE)
|
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
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
RUN_AFTER_BUILD ?= true
|
|
|
|
|
|
|
|
# MACOSX_DEPLOYMENT_TARGET="$(MACOSX_DEPLOYMENT_TARGET)" \
|
|
|
|
|
|
|
|
NIMBLE_ENV = \
|
|
|
|
LOG_LEVEL=$(LOG_LEVEL) \
|
|
|
|
NCURSES_LDFLAGS="$(NCURSES_LDFLAGS)" \
|
|
|
|
NCURSES_STATIC=$(NCURSES_STATIC) \
|
2020-10-08 16:08:52 +00:00
|
|
|
NIMSTATUS_CFLAGS="$(NIMSTATUS_CFLAGS)" \
|
|
|
|
PCRE_LDFLAGS="$(PCRE_LDFLAGS)" \
|
2021-03-28 23:03:18 +00:00
|
|
|
PCRE_STATIC=$(PCRE_STATIC) \
|
|
|
|
RELEASE=$(RELEASE) \
|
|
|
|
RLN_LDFLAGS="$(RLN_LDFLAGS)" \
|
|
|
|
RLN_STATIC=$(RLN_STATIC) \
|
|
|
|
RUN_AFTER_BUILD=$(RUN_AFTER_BUILD) \
|
|
|
|
SQLCIPHER_LDFLAGS="$(SQLCIPHER_LDFLAGS)" \
|
2020-10-08 16:08:52 +00:00
|
|
|
SSL_LDFLAGS="$(SSL_LDFLAGS)" \
|
2021-03-28 23:03:18 +00:00
|
|
|
SSL_STATIC=$(SSL_STATIC) \
|
|
|
|
WIN_STATIC=$(WIN_STATIC)
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NIMBLE_ENV += PATH="$(PATH_NIMBLE)"
|
|
|
|
else ifneq ($(detected_OS),macOS)
|
|
|
|
NIMBLE_ENV += LD_LIBRARY_PATH="$(LD_LIBRARY_PATH_NIMBLE)"
|
2020-08-10 16:48:30 +00:00
|
|
|
endif
|
2020-07-02 18:40:49 +00:00
|
|
|
|
2021-03-28 23:03:18 +00:00
|
|
|
chat: $(SQLCIPHER) $(MIGRATIONS)
|
|
|
|
$(NIMBLE_ENV) $(ENV_SCRIPT) nimble chat
|
|
|
|
|
|
|
|
waku_chat2: $(SQLCIPHER) $(MIGRATIONS)
|
|
|
|
$(NIMBLE_ENV) $(ENV_SCRIPT) nimble waku_chat2
|
|
|
|
|
|
|
|
test: $(SQLCIPHER) $(MIGRATIONS)
|
|
|
|
$(NIMBLE_ENV) $(ENV_SCRIPT) nimble tests
|
|
|
|
|
2020-07-02 13:20:16 +00:00
|
|
|
endif # "variables.mk" was not included
|