Skip to content

Commit

Permalink
Merge pull request #41 from status-im/feat/nim-hashmessage
Browse files Browse the repository at this point in the history
feat: introduce Nim impl of hashMessage in reorganized library
  • Loading branch information
michaelsbradleyjr authored Aug 31, 2020
2 parents b3e3a89 + 6f39981 commit 9fb5c56
Show file tree
Hide file tree
Showing 25 changed files with 740 additions and 471 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
.idea
.vscode
bin/
/bottles/
build/
vendor/.nimble
tmp
nimcache
.DS_Store
TODO
nim_status
test/test
/nim_status
data/
keystore/
noBackup/
noBackup/
tests/c/build
tests/nim/build
115 changes: 77 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ BUILD_SYSTEM_DIR := vendor/nimbus-build-system
bottles-dummy \
bottles-macos \
clean \
clean-build-dirs \
clean-data-dirs \
create-data-dirs \
deps \
nim_status \
update \
tests
status-go \
test \
test-shims-c \
test-login-c \
tests \
tests-c \
tests-nim \
update

ifeq ($(NIM_PARAMS),)
# "variables.mk" was not included, so we update the submodules.
Expand Down Expand Up @@ -50,7 +59,7 @@ else
detected_OS := $(strip $(shell uname))
endif

ifeq ($(detected_OS), Darwin)
ifeq ($(detected_OS),Darwin)
BOTTLES_TARGET := bottles-macos
MACOSX_DEPLOYMENT_TARGET := 10.13
export MACOSX_DEPLOYMENT_TARGET
Expand Down Expand Up @@ -89,64 +98,94 @@ $(BOTTLE_PCRE):
bottles-macos: | $(BOTTLE_OPENSSL) $(BOTTLE_PCRE)
rm -rf bottles/Downloads

deps: | deps-common bottles

ifeq ($(detected_OS), Darwin)
update: | update-common

ifeq ($(detected_OS),Darwin)
NIM_PARAMS := $(NIM_PARAMS) -L:"-framework Foundation -framework Security -framework IOKit -framework CoreServices"
endif

# TODO: control debug/release builds with a Make var
# We need `-d:debug` to get Nim's default stack traces.
NIM_PARAMS += -d:debug

deps: | deps-common

update: | update-common

STATUSGO := vendor/status-go/build/bin/libstatus.a

status-go: $(STATUSGO)
$(STATUSGO): | deps
echo -e $(BUILD_MSG) "status-go"
+ cd vendor/status-go && \
$(MAKE) statusgo-library $(HANDLE_OUTPUT)

clean: | clean-common clean-build-dir
rm -rf $(STATUSGO)
rm -rf keystore
rm -rf data
rm -rf noBackup

clean-build-dir:
rm -rf build/*

NIMSTATUS := build/nim_status.a

$(NIMSTATUS): | build deps
nim_status: | $(NIMSTATUS)
$(NIMSTATUS): | deps
echo -e $(BUILD_MSG) "$@" && \
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --app:staticLib --header --noMain --nimcache:nimcache/nim_status -o:$@ src/nim_status.nim
cp nimcache/nim_status/nim_status.h build/.
mv nim_status.a build/.
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --app:staticLib --header --noMain --nimcache:nimcache/nim_status -o:$@ src/nim_status/c/nim_status.nim
cp nimcache/nim_status/nim_status.h build/nim_status.h
mv nim_status.a build/

nim_status: | clean-build-dir $(NIMSTATUS)
SHIMS := tests/c/build/shims.a

tests: | $(NIMSTATUS) $(STATUSGO)
rm -Rf keystore
rm -Rf data
rm -Rf noBackup
mkdir -p data
mkdir -p noBackup
mkdir -p keystore
echo "Compiling 'test/test'"
ifeq ($(detected_OS), Darwin)
$(ENV_SCRIPT) $(CC) -I"$(CURDIR)/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" test/test.c $(NIMSTATUS) $(STATUSGO) -framework CoreFoundation -framework CoreServices -framework IOKit -framework Security -lm -pthread -o test/test
shims: | $(SHIMS)
$(SHIMS): | deps
echo -e $(BUILD_MSG) "$@" && \
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --app:staticLib --header --noMain --nimcache:nimcache/nim_status -o:$@ tests/c/shims.nim
cp nimcache/nim_status/shims.h tests/c/build/shims.h
mv shims.a tests/c/build/

test-shims-c: | $(STATUSGO) clean-data-dirs create-data-dirs $(SHIMS)
mkdir -p tests/c/build
echo "Compiling 'tests/c/shims'"
ifeq ($(detected_OS),Darwin)
$(ENV_SCRIPT) $(CC) -I"$(CURDIR)/tests/c/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" tests/c/shims.c $(SHIMS) $(STATUSGO) -framework CoreFoundation -framework CoreServices -framework IOKit -framework Security -lm -pthread -o tests/c/build/shims
else
$(ENV_SCRIPT) $(CC) -I"$(CURDIR)/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" test/test.c $(NIMSTATUS) $(STATUSGO) -lm -pthread -o test/test
$(ENV_SCRIPT) $(CC) -I"$(CURDIR)/tests/c/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" tests/c/shims.c $(SHIMS) $(STATUSGO) -lm -pthread -o tests/c/build/shims
endif
echo "Executing 'test/test'"
$(ENV_SCRIPT) ./test/test
$(ENV_SCRIPT) nimble test
echo "Executing 'tests/c/build/shims'"
$(ENV_SCRIPT) ./tests/c/build/shims

test-login-c: | $(STATUSGO) clean-data-dirs create-data-dirs $(NIMSTATUS)
mkdir -p tests/c/build
echo "Compiling 'tests/c/login'"
ifeq ($(detected_OS),Darwin)
$(ENV_SCRIPT) $(CC) -I"$(CURDIR)/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" tests/c/login.c $(NIMSTATUS) $(STATUSGO) -framework CoreFoundation -framework CoreServices -framework IOKit -framework Security -lm -pthread -o tests/c/build/login
else
$(ENV_SCRIPT) $(CC) -I"$(CURDIR)/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" tests/c/login.c $(NIMSTATUS) $(STATUSGO) -lm -pthread -o tests/c/build/login
endif
echo "Executing 'tests/c/build/login'"
$(ENV_SCRIPT) ./tests/c/build/login

tests-c:
$(MAKE) test-shims-c
$(MAKE) test-login-c

nim-tests: | $(NIMSTATUS) $(STATUSGO)
rm -Rf build/*
tests-nim: | $(STATUSGO)
$(ENV_SCRIPT) nimble test

tests: tests-nim tests-c

test: tests

clean: | clean-common clean-build-dirs clean-data-dirs
rm -rf $(STATUSGO)
rm -rf bottles

clean-build-dirs:
rm -rf build/*
rm -rf tests/c/build/*
rm -rf tests/nim/build/*

clean-data-dirs:
rm -rf data
rm -rf keystore
rm -rf noBackup

create-data-dirs:
mkdir -p data
mkdir -p keystore
mkdir -p noBackup

endif # "variables.mk" was not included
9 changes: 5 additions & 4 deletions config.nims
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
when defined(macosx):
import algorithm, strutils

if defined(release):
switch("nimcache", "nimcache/release/$projectName")
else:
Expand All @@ -9,10 +6,10 @@ else:
--threads:on
--opt:speed # -O3
--debugger:native # passes "-g" to the C compiler
--dynliboverrideall # don't use dlopen()
--define:ssl # needed by the stdlib to enable SSL procedures

if defined(macosx):
--dynliboverrideall # don't use dlopen()
--tlsEmulation:off
switch("passL", "-lstdc++")
# statically linke these libs
Expand All @@ -23,7 +20,11 @@ if defined(macosx):
switch("passL", "-Wl,-no_compact_unwind")
# set the minimum supported macOS version to 10.13
switch("passC", "-mmacosx-version-min=10.13")
elif defined(windows):
--tlsEmulation:off
switch("passL", "-Wl,-as-needed")
else:
--dynliboverrideall # don't use dlopen()
# dynamically link these libs, since we're opting out of dlopen()
switch("passL", "-lcrypto")
switch("passL", "-lssl")
Expand Down
24 changes: 14 additions & 10 deletions nim_status.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Package

### Package
version = "0.1.0"
author = "Status Research & Development GmbH"
description = "Nim implementation of the Status protocol"
Expand All @@ -8,21 +7,26 @@ srcDir = "src"
bin = @[""]
skipDirs = @["test"]

# Deps

### Deps
requires "nim >= 1.0.0"


### Helper functions
proc buildAndRunBinary(name: string, srcDir = "./", params = "", cmdParams = "", lang = "c") =
if not dirExists "build":
mkDir "build"
rmDir "data"
rmDir "keystore"
rmDir "noBackup"
mkDir "data"
mkDir "keystore"
mkDir "noBackup"
if not dirExists "tests/nim/build":
mkDir "tests/nim/build"
# allow something like "nim test --verbosity:0 --hints:off beacon_chain.nims"
var extra_params = params
for i in 2..<paramCount():
extra_params &= " " & paramStr(i)
exec "nim " & lang & " --out:./build/" & name & " -r " & extra_params & " " & srcDir & name & ".nim" & " " & cmdParams
exec "nim " & lang & " --out:./tests/nim/build/" & name & " -r " & extra_params & " " & srcDir & name & ".nim" & " " & cmdParams

### tasks
### Tasks
task test, "Run all tests":
buildAndRunBinary "test1", "tests/"
buildAndRunBinary "shims", "tests/nim/"
buildAndRunBinary "login", "tests/nim/"
Loading

0 comments on commit 9fb5c56

Please sign in to comment.