Skip to content

Commit

Permalink
Revert "build system refactoring"
Browse files Browse the repository at this point in the history
This reverts commit 2449a12.
  • Loading branch information
iurimatias committed Jun 4, 2020
1 parent 9c668c7 commit 1a160cf
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 134 deletions.
78 changes: 30 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ BUILD_SYSTEM_DIR := vendor/nimbus-build-system
appimage \
clean \
deps \
nim_status_client \
run \
update

ifeq ($(NIM_PARAMS),)
Expand All @@ -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

# 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
detected_OS := Windows
else
detected_OS := $(strip $(shell uname))
detected_OS := $(strip $(shell uname))
endif


DEFAULT_TARGET := None
ifeq ($(detected_OS), Darwin)
NIM_PARAMS := $(NIM_PARAMS) -L:"-framework Foundation -framework Security -framework IOKit -framework CoreServices"
DEFAULT_TARGET := build-macos
else
DEFAULT_TARGET := build-linux
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)"
all: $(DEFAULT_TARGET)

# 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
# must be included after the default target
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk

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):
Expand All @@ -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

build-linux: $(DOTHERSIDE) $(STATUSGO) src/nim_status_client.nim | deps
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

nim_status_client: | $(DOTHERSIDE) $(STATUSGO) deps
build-macos: $(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 -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

Expand Down Expand Up @@ -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
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ Experiments calling status-go from nim, inspired in [nim-stratus](https://github

* QT

Linux users should 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
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
Expand All @@ -26,43 +18,51 @@ 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 users can also install Qt through the system's package manager:

```
# Linux
# Debian/Ubuntu:
sudo apt install qtbase5-dev qtdeclarative5-dev qml-module-qt-labs-platform
```

* go - (used to build status-go)

```
# linux
<TODO>
# macOS
# 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:
# Linux
export PATH=$PATH:/path/to/Qt/5.14.2/gcc_64/bin
# macOS:
# 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
Expand All @@ -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
Expand All @@ -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).

Expand Down
51 changes: 0 additions & 51 deletions config.nims

This file was deleted.

3 changes: 0 additions & 3 deletions nim.cfg

This file was deleted.

6 changes: 2 additions & 4 deletions src/nim_status_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions src/nim_status_client.nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--threads:on
--tlsEmulation:off

@if release:
nimcache = "nimcache/release/$projectName"
@else:
nimcache = "nimcache/debug/$projectName"
@end

2 changes: 1 addition & 1 deletion vendor/DOtherSide

0 comments on commit 1a160cf

Please sign in to comment.