build system refactoring

- unify the "build-..." targets
- enable a debug build by default, to simplify development
- bump vendor/DOtherSide
- avoid DOtherSide checks for docs/tests-specific tools like Doxygen
- switch to an in-place build for DOtherSide
- silence the DOtherSide build when V=0, make it more verbose with V=1
- don't delete checked out submodules in the "clean" target
- update build instructions in the README
- centralise Nim compiler options in a top-level "config.nims" (except
  `-d:debug` which needs to be on the command line)
This commit is contained in:
Ștefan Talpalaru 2020-05-25 04:18:37 +02:00 committed by Iuri Matias
parent 5371f22e70
commit 4fe6d9b767
7 changed files with 147 additions and 87 deletions

View File

@ -18,6 +18,8 @@ BUILD_SYSTEM_DIR := vendor/nimbus-build-system
appimage \ appimage \
clean \ clean \
deps \ deps \
nim_status_client \
run \
update update
ifeq ($(NIM_PARAMS),) ifeq ($(NIM_PARAMS),)
@ -35,6 +37,10 @@ GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
else # "variables.mk" was included. Business as usual until the end of this file. else # "variables.mk" was included. Business as usual until the end of this file.
all: nim_status_client
# must be included after the default target
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows detected_OS := Windows
@ -42,30 +48,46 @@ else
detected_OS := $(strip $(shell uname)) detected_OS := $(strip $(shell uname))
endif endif
DEFAULT_TARGET := None
ifeq ($(detected_OS), Darwin) ifeq ($(detected_OS), Darwin)
DEFAULT_TARGET := build-macos NIM_PARAMS := $(NIM_PARAMS) -L:"-framework Foundation -framework Security -framework IOKit -framework CoreServices"
else
DEFAULT_TARGET := build-linux
endif endif
all: $(DEFAULT_TARGET) DOTHERSIDE := vendor/DOtherSide/lib/libDOtherSideStatic.a
# must be included after the default target # Qt5 dirs (we can't indent with tabs here)
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk QT5_PCFILEDIR := $(shell pkg-config --variable=pcfiledir Qt5Core 2>/dev/null)
QT5_LIBDIR := $(shell pkg-config --variable=libdir Qt5Core 2>/dev/null)
ifeq ($(QT5_PCFILEDIR),)
ifeq ($(QTDIR),)
$(error Can't find your Qt5 installation. Please run "$(MAKE) QTDIR=/path/to/your/Qt5/installation/prefix ...")
else
ifeq ($(detected_OS), Darwin)
QT5_PCFILEDIR := $(QTDIR)/clang_64/lib/pkgconfig
QT5_LIBDIR := $(QTDIR)/clang_64/lib
# some manually installed Qt5 instances have wrong paths in their *.pc files, so we pass the right one to the linker here
NIM_PARAMS += --passL:"-F$(QT5_LIBDIR)"
else
QT5_PCFILEDIR := $(QTDIR)/gcc_64/lib/pkgconfig
QT5_LIBDIR := $(QTDIR)/gcc_64/lib
NIM_PARAMS += --passL:"-L$(QT5_LIBDIR)"
endif
endif
endif
export QT5_LIBDIR
# order matters here, due to "-Wl,-as-needed"
NIM_PARAMS += --passL:"$(DOTHERSIDE) $(shell PKG_CONFIG_PATH="$(QT5_PCFILEDIR)" pkg-config --libs Qt5Core Qt5Qml Qt5Gui Qt5Quick Qt5QuickControls2 Qt5Widgets)"
# TODO: control debug/release builds with a Make var
# We need `-d:debug` to get Nim's default stack traces.
NIM_PARAMS += --outdir:./bin -d:debug
# Enable debugging symbols in DOtherSide, in case we need GDB backtraces from it.
CFLAGS += -g
CXXFLAGS += -g
deps: | deps-common deps: | deps-common
update: | update-common update: | update-common
DOTHERSIDE := None
ifeq ($(detected_OS), Darwin)
DOTHERSIDE := vendor/DOtherSide/build/lib/libDOtherSide.dylib
else
DOTHERSIDE := vendor/DOtherSide/build/lib/libDOtherSide.so
endif
APPIMAGETOOL := appimagetool-x86_64.AppImage APPIMAGETOOL := appimagetool-x86_64.AppImage
$(APPIMAGETOOL): $(APPIMAGETOOL):
@ -75,28 +97,23 @@ $(APPIMAGETOOL):
$(DOTHERSIDE): | deps $(DOTHERSIDE): | deps
echo -e $(BUILD_MSG) "DOtherSide" echo -e $(BUILD_MSG) "DOtherSide"
+ cd vendor/DOtherSide && \ + cd vendor/DOtherSide && \
mkdir -p build && \ rm -f CMakeCache.txt && \
cd build && \ cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_DOCS=OFF -DENABLE_TESTS=OFF -DENABLE_DYNAMIC_LIBS=OFF -DENABLE_STATIC_LIBS=ON . $(HANDLE_OUTPUT) && \
cmake -DCMAKE_BUILD_TYPE=Release .. $(HANDLE_OUTPUT) && \ $(MAKE) VERBOSE=$(V) $(HANDLE_OUTPUT)
$(MAKE) DOtherSide # IF WE WANT TO USE LIBDOTHERSIDE AS STATIC LIBRARY, USE `$(MAKE) DOtherSideStatic` INSTEAD
STATUSGO := vendor/status-go/build/bin/libstatus.a STATUSGO := vendor/status-go/build/bin/libstatus.a
$(STATUSGO): | deps $(STATUSGO): | deps
echo -e $(BUILD_MSG) "status-go" echo -e $(BUILD_MSG) "status-go"
+ cd vendor/status-go && \ + cd vendor/status-go && \
$(MAKE) statusgo-library $(MAKE) statusgo-library $(HANDLE_OUTPUT)
build-linux: $(DOTHERSIDE) $(STATUSGO) src/nim_status_client.nim | deps nim_status_client: | $(DOTHERSIDE) $(STATUSGO) deps
echo -e $(BUILD_MSG) "$@" && \ echo -e $(BUILD_MSG) "$@" && \
$(ENV_SCRIPT) nim c -d:nimDebugDlOpen -L:$(STATUSGO) -d:ssl -L:-lm $(NIM_PARAMS) -L:$(DOTHERSIDE) --outdir:./bin src/nim_status_client.nim $(ENV_SCRIPT) nim c $(NIM_PARAMS) --passL:"$(STATUSGO)" --passL:"-lm" src/nim_status_client.nim
build-macos: $(DOTHERSIDE) $(STATUSGO) src/nim_status_client.nim | deps
echo -e $(BUILD_MSG) "$@" && \
$(ENV_SCRIPT) nim c -d:nimDebugDlOpen -L:$(STATUSGO) -d:ssl -L:-lm -L:"-framework Foundation -framework Security -framework IOKit -framework CoreServices" $(NIM_PARAMS) -L:$(DOTHERSIDE) --outdir:./bin src/nim_status_client.nim
run: run:
LD_LIBRARY_PATH=vendor/DOtherSide/build/lib ./bin/nim_status_client LD_LIBRARY_PATH="$(QT5_LIBDIR)" ./bin/nim_status_client
APPIMAGE := NimStatusClient-x86_64.AppImage APPIMAGE := NimStatusClient-x86_64.AppImage
@ -135,6 +152,7 @@ $(APPIMAGE): $(DEFAULT_TARGET) $(APPIMAGETOOL) nim-status.desktop
appimage: $(APPIMAGE) appimage: $(APPIMAGE)
clean: | clean-common clean: | clean-common
rm -rf $(APPIMAGE) bin/* vendor/* tmp/dist rm -rf $(APPIMAGE) bin/* tmp/dist $(STATUSGO)
+ $(MAKE) -C vendor/DOtherSide --no-print-directory clean
endif # "variables.mk" was not included endif # "variables.mk" was not included

View File

@ -8,34 +8,15 @@ Experiments calling status-go from nim, inspired in [nim-stratus](https://github
* QT * QT
install QT https://www.qt.io/download-qt-installer Linux users should install Qt through the system's package manager:
and add it to the PATH
```
# Linux
export PATH=$PATH:/path/to/Qt/5.14.2/gcc_64/bin
# macos
export PATH=$PATH:/path/to/Qt/5.14.2/clang_64/bin
```
Linux users can also install Qt through the system's package manager:
``` ```
# Debian/Ubuntu: # Debian/Ubuntu:
sudo apt install qtbase5-dev qtdeclarative5-dev qml-module-qt-labs-platform sudo apt install qtbase5-dev qtdeclarative5-dev qml-module-qt-labs-platform
``` ```
* go - (used to build status-go) If that's not possible, manually install QT from https://www.qt.io/download-qt-installer
and add it to the PATH
```
# linux
<TODO>
# macos
brew install go
```
### 1. Install QT, and add it to the PATH
``` ```
# Linux # Linux
@ -45,24 +26,43 @@ export PATH=$PATH:/path/to/Qt/5.14.2/gcc_64/bin
export PATH=$PATH:/path/to/Qt/5.14.2/clang_64/bin export PATH=$PATH:/path/to/Qt/5.14.2/clang_64/bin
``` ```
* Go - (used to build status-go)
```
# Linux
<TODO>
# macOS
brew install go
```
### 1. Install QT, and add it to the PATH
```
# Linux users should use their distro's package manager, but in case they do a manual install:
export PATH=$PATH:/path/to/Qt/5.14.2/gcc_64/bin
# macOS:
export PATH=$PATH:/path/to/Qt/5.14.2/clang_64/bin
```
### 2. Clone the repo and build `nim-status-client` ### 2. Clone the repo and build `nim-status-client`
``` ```
git clone https://github.com/status-im/nim-status-client/ --recurse-submodules git clone https://github.com/status-im/nim-status-client
cd nim-status-client
make update
make make
``` ```
if you previously cloned the repo without the `--recurse-submodule` options, then do For more output use `make V=1 ...`.
``` Use 4 CPU cores with `make -j4 ...`.
git submodule update --init --recursive
make
```
for more output use `make V=1` Users with manually installed Qt5 packages need to run `make QTDIR="/path/to/Qt" ...`
**Trouble Shooting**: **Troubleshooting**:
If the `make` command fails due to already installed homebrew packages, such as: If the `make` command fails due to already installed Homebrew packages, such as:
``` ```
Error: protobuf 3.11.4 is already installed Error: protobuf 3.11.4 is already installed
@ -74,15 +74,12 @@ make: *** [vendor/status-go/build/bin/libstatus.a] Error 2
This can be fixed by uninstalling the package e.g. `brew uninstall protobuf` followed by rerunning `make`. This can be fixed by uninstalling the package e.g. `brew uninstall protobuf` followed by rerunning `make`.
### 3. Setup Library Path ### 3. Run the app
```
export LD_LIBRARY_PATH=vendor/DOtherSide/build/lib/
```
### 4. Run the app
``` ```
./bin/nim_status_client make run
# or
LD_LIBRARY_PATH=vendor/DOtherSide/lib ./bin/nim_status_client
``` ```
## Development ## Development
@ -92,7 +89,7 @@ If making changes in the nim code `src/` then doing `make` again is needed (it's
## Cold Reload ## Cold Reload
### 5. "Cold" reload using VSCode ### "Cold" reload using VSCode
We can setup a "cold" reload, whereby the app will be rebuilt and restarted when changes in the source are saved. This will not save state, as the app will be restarted, but it will save us some time from manually restarting the app. We can handily force an app rebuild/relaunch with the shortcut `Cmd+Shift+b` (execute the default build task, which we'll setup below). We can setup a "cold" reload, whereby the app will be rebuilt and restarted when changes in the source are saved. This will not save state, as the app will be restarted, but it will save us some time from manually restarting the app. We can handily force an app rebuild/relaunch with the shortcut `Cmd+Shift+b` (execute the default build task, which we'll setup below).

51
config.nims Normal file
View File

@ -0,0 +1,51 @@
when defined(macosx):
import algorithm, strutils
if defined(release):
switch("nimcache", "nimcache/release/$projectName")
else:
switch("nimcache", "nimcache/debug/$projectName")
proc linkLib(name: string): string =
var resLib = name
when defined(macosx):
# In macOS Catalina, unversioned libraries may be broken stubs, so we need to
# find a versioned one: https://github.com/status-im/nim-status-client/pull/209
var matches: seq[string]
for path in listFiles("/usr/lib"):
# /usr/lib/libcrypto.0.9.8.dylib
let file = path[9..^1]
# libcrypto.0.9.8.dylib
if file.startsWith("lib" & name) and file != "lib" & name & ".dylib":
matches.add(path)
matches.sort(order = SortOrder.Descending)
if matches.len > 0:
resLib = matches[0]
# Passing "/usr/lib/libcrypto.44.dylib" directly to the linker works for
# dynamic linking.
return resLib
return "-l" & resLib
--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):
--tlsEmulation:off
# DYLD_LIBRARY_PATH doesn't seem to work with Qt5
switch("passL", "-rpath" & " " & getEnv("QT5_LIBDIR"))
switch("passL", "-lstdc++")
# dynamically link these libs, since we're opting out of dlopen()
switch("passL", linkLib("crypto"))
switch("passL", linkLib("ssl"))
# https://code.videolan.org/videolan/VLCKit/-/issues/232
switch("passL", "-Wl,-no_compact_unwind")
else:
switch("passL", linkLib("crypto") & " " & linkLib("ssl")) # dynamically link these libs, since we're opting out of dlopen()
switch("passL", "-Wl,-as-needed") # don't link libraries we're not actually using
--define:chronicles_line_numbers # useful when debugging

3
nim.cfg Normal file
View File

@ -0,0 +1,3 @@
# we need to link C++ libraries
gcc.linkerexe="g++"

View File

@ -1,9 +0,0 @@
--threads:on
--tlsEmulation:off
@if release:
nimcache = "nimcache/release/$projectName"
@else:
nimcache = "nimcache/debug/$projectName"
@end

2
vendor/DOtherSide vendored

@ -1 +1 @@
Subproject commit 3ecf2595f1616b36b5de95227f8a7b5581d419c3 Subproject commit 407787b72bb0e861c98a26a7e7dc768911830f30