Revert "build system refactoring"

This reverts commit 2449a12fb7.
This commit is contained in:
Iuri Matias 2020-06-04 17:18:11 -04:00
parent 9c668c79d1
commit 1a160cf664
7 changed files with 87 additions and 149 deletions

View File

@ -18,8 +18,6 @@ BUILD_SYSTEM_DIR := vendor/nimbus-build-system
appimage \
clean \
deps \
nim_status_client \
run \
update
ifeq ($(NIM_PARAMS),)
@ -37,57 +35,37 @@ GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
else # "variables.mk" was included. Business as usual until the end of this file.
all: nim_status_client
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
else
detected_OS := $(strip $(shell uname))
endif
DEFAULT_TARGET := None
ifeq ($(detected_OS), Darwin)
DEFAULT_TARGET := build-macos
else
DEFAULT_TARGET := build-linux
endif
all: $(DEFAULT_TARGET)
# 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...
detected_OS := Windows
else
detected_OS := $(strip $(shell uname))
endif
ifeq ($(detected_OS), Darwin)
NIM_PARAMS := $(NIM_PARAMS) -L:"-framework Foundation -framework Security -framework IOKit -framework CoreServices"
endif
DOTHERSIDE := vendor/DOtherSide/lib/libDOtherSideStatic.a
# Qt5 dirs (we can't indent with tabs here)
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
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):
@ -97,23 +75,28 @@ $(APPIMAGETOOL):
$(DOTHERSIDE): | deps
echo -e $(BUILD_MSG) "DOtherSide"
+ cd vendor/DOtherSide && \
rm -f CMakeCache.txt && \
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_DOCS=OFF -DENABLE_TESTS=OFF -DENABLE_DYNAMIC_LIBS=OFF -DENABLE_STATIC_LIBS=ON . $(HANDLE_OUTPUT) && \
$(MAKE) VERBOSE=$(V) $(HANDLE_OUTPUT)
mkdir -p build && \
cd build && \
cmake -DCMAKE_BUILD_TYPE=Release .. $(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): | deps
echo -e $(BUILD_MSG) "status-go"
+ cd vendor/status-go && \
$(MAKE) statusgo-library $(HANDLE_OUTPUT)
$(MAKE) statusgo-library
nim_status_client: | $(DOTHERSIDE) $(STATUSGO) deps
build-linux: $(DOTHERSIDE) $(STATUSGO) src/nim_status_client.nim | deps
echo -e $(BUILD_MSG) "$@" && \
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --passL:"$(STATUSGO)" --passL:"-lm" src/nim_status_client.nim
$(ENV_SCRIPT) nim c -d:nimDebugDlOpen -L:$(STATUSGO) -d:ssl -L:-lm $(NIM_PARAMS) -L:$(DOTHERSIDE) --outdir:./bin 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:
LD_LIBRARY_PATH="$(QT5_LIBDIR)" ./bin/nim_status_client
LD_LIBRARY_PATH=vendor/DOtherSide/build/lib ./bin/nim_status_client
APPIMAGE := NimStatusClient-x86_64.AppImage
@ -152,7 +135,6 @@ $(APPIMAGE): $(DEFAULT_TARGET) $(APPIMAGETOOL) nim-status.desktop
appimage: $(APPIMAGE)
clean: | clean-common
rm -rf $(APPIMAGE) bin/* tmp/dist $(STATUSGO)
+ $(MAKE) -C vendor/DOtherSide --no-print-directory clean
rm -rf $(APPIMAGE) bin/* vendor/* tmp/dist
endif # "variables.mk" was not included

View File

@ -8,15 +8,34 @@ Experiments calling status-go from nim, inspired in [nim-stratus](https://github
* QT
Linux users should install Qt through the system's package manager:
install QT https://www.qt.io/download-qt-installer
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:
sudo apt install qtbase5-dev qtdeclarative5-dev qml-module-qt-labs-platform
```
If that's not possible, manually install QT from https://www.qt.io/download-qt-installer
and add it to the PATH
* go - (used to build status-go)
```
# linux
<TODO>
# macos
brew install go
```
### 1. Install QT, and add it to the PATH
```
# Linux
@ -26,43 +45,24 @@ export PATH=$PATH:/path/to/Qt/5.14.2/gcc_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`
```
git clone https://github.com/status-im/nim-status-client
cd nim-status-client
make update
git clone https://github.com/status-im/nim-status-client/ --recurse-submodules
make
```
For more output use `make V=1 ...`.
if you previously cloned the repo without the `--recurse-submodule` options, then do
Use 4 CPU cores with `make -j4 ...`.
```
git submodule update --init --recursive
make
```
Users with manually installed Qt5 packages need to run `make QTDIR="/path/to/Qt" ...`
for more output use `make V=1`
**Troubleshooting**:
**Trouble Shooting**:
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
@ -74,12 +74,15 @@ 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`.
### 3. Run the app
### 3. Setup Library Path
```
export LD_LIBRARY_PATH=vendor/DOtherSide/build/lib/
```
### 4. Run the app
```
make run
# or
LD_LIBRARY_PATH=vendor/DOtherSide/lib ./bin/nim_status_client
./bin/nim_status_client
```
## Development
@ -89,7 +92,7 @@ If making changes in the nim code `src/` then doing `make` again is needed (it's
## Cold Reload
### "Cold" reload using VSCode
### 5. "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).

View File

@ -1,51 +0,0 @@
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):
# 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

View File

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

View File

@ -85,11 +85,9 @@ proc mainProc() =
# it will be passed as a regular C function to libstatus. This means that
# we cannot capture any local variables here (we must rely on globals)
var callback: SignalCallback = proc(p0: cstring) {.cdecl.} =
when not compileOption("tlsEmulation"):
setupForeignThreadGc()
setupForeignThreadGc()
signal_handler(signalsQObjPointer, p0, "receiveSignal")
when not compileOption("tlsEmulation"):
tearDownForeignThreadGc()
tearDownForeignThreadGc()
libstatus.setSignalEventCallback(callback)

View File

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

2
vendor/DOtherSide vendored

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