building.md
1 # Building Status Desktop 2 3 ## Building 4 5 ### 0. Prerequesites 6 7 On windows you can simply run the [`scripts/windows_build_setup.ps1`](../scripts/windows_build_setup.ps1) script in a PowerShell with Administrator privileges. 8 9 * QT 10 11 **IMPORTANT:** Due to [a bug](https://github.com/status-im/status-desktop/commit/7b07a31fa6d06c730cf563475d319f0217a211ca) in version `5.15.0`, this project is locked to version `5.14.2`. Make sure to select version `5.14.2` when installing Qt via the installer. 12 13 Linux users should install Qt through the system's package manager: 14 15 ``` 16 # Debian/Ubuntu: 17 sudo apt install qtbase5-dev qtdeclarative5-dev qml-module-qt-labs-platform qtquickcontrols2-5-dev 18 19 # Fedora 20 sudo dnf install qt-devel qt5-devel 21 22 ``` 23 24 If that's not possible, manually install QT from https://www.qt.io/download-qt-installer 25 and add it to the PATH 26 27 ``` 28 # Linux 29 export PATH=$PATH:/path/to/Qt/5.14.2/gcc_64/bin 30 31 # macos 32 export PATH=$PATH:/path/to/Qt/5.14.2/clang_64/bin 33 ``` 34 35 * Go - (used to build status-go) 36 37 ``` 38 # Linux 39 <TODO> 40 41 # macOS 42 brew install go 43 ``` 44 45 ### 1. Install QT, and add it to the PATH 46 47 ``` 48 # Linux users should use their distro's package manager, but in case they do a manual install: 49 export QTDIR="/path/to/Qt/5.14.2/gcc_64" 50 export PATH="${QTDIR}/bin:${PATH}" 51 52 # macOS: 53 export QTDIR="/path/to/Qt/5.14.2/clang_64" 54 export PATH="${QTDIR}/bin:${PATH}" 55 ``` 56 57 ### 2. Clone the repo and build `nim-status-client` 58 ``` 59 git clone https://github.com/status-im/nim-status-client 60 cd nim-status-client 61 make update 62 make 63 ``` 64 65 For more output use `make V=1 ...`. 66 67 Use 4 CPU cores with `make -j4 ...`. 68 69 Users with manually installed Qt5 packages need to run `make QTDIR="/path/to/Qt" ...` 70 71 **Troubleshooting**: 72 73 If the `make` command fails due to already installed Homebrew packages, such as: 74 75 ``` 76 Error: protobuf 3.11.4 is already installed 77 To upgrade to 3.11.4_1, run `brew upgrade protobuf`. 78 make[1]: *** [install-os-dependencies] Error 1 79 make: *** [vendor/status-go/build/bin/libstatus.a] Error 2 80 ``` 81 82 This can be fixed by uninstalling the package e.g. `brew uninstall protobuf` followed by rerunning `make`. 83 84 85 ### 3. Run the app 86 87 ``` 88 make run 89 # or 90 LD_LIBRARY_PATH=vendor/DOtherSide/lib ./bin/nim_status_client 91 ``` 92 93 ## Development 94 95 If only making changes in QML `ui/` re-rerunning the app is enough 96 If making changes in the nim code `src/` then doing `make` again is needed (it's very fast after the first run) 97 98 ## Cold Reload 99 100 ### "Cold" reload using VSCode 101 102 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). 103 104 To enable a meagre app reload during development, first creates a task in `.vscode/tasks.json`. This task sets up the default build task for the workspace, and depends on the task that compiles our nim: 105 106 ```json 107 ({ 108 "label": "Build Nim Status Client", 109 "type": "shell", 110 "command": "nim", 111 "args": [ 112 "c", 113 "-L:lib/libstatus.dylib", 114 "-L:-lm", 115 "-L:\"-framework Foundation -framework Security -framework IOKit -framework CoreServices\"", 116 "--outdir:./bin", 117 "src/nim_status_client.nim" 118 ], 119 "options": { 120 "cwd": "${workspaceRoot}" 121 } 122 }, 123 { 124 "label": "Run nim_status_client", 125 "type": "shell", 126 "command": "bash", 127 "args": ["./run.sh"], 128 "options": { 129 "cwd": "${workspaceRoot}/.vscode" 130 }, 131 "dependsOn": ["Build Nim Status Client"], 132 "group": { 133 "kind": "build", 134 "isDefault": true 135 } 136 }) 137 ``` 138 139 Next, add a `.vscode/run.sh` file, changing the `DOtherSide` lib path to be specific to your environment: 140 141 ```bash 142 export LD_LIBRARY_PATH="/Users/emizzle/repos/github.com/filcuc/DOtherSide/build/lib" 143 ../bin/nim_status_client 144 ``` 145 146 # Auto build on save (for the "cold" reload effect) 147 148 Finally, to get trigger this default build task when our files our saved, we need to enable a task to be run while `.nim` files are saved, and when `.qml` files are saved. 149 150 ### Build on save 151 152 To build on save of our source files, first install the "Trigger Task on Save" VS Code extension to detect changes to our changable files, which will trigger a build/run. Once installed, update `settings.json` like so: 153 154 ```json 155 "files.autoSave": "afterDelay", 156 "triggerTaskOnSave.tasks": { 157 "Run nim_status_client": ["ui/**/*", "src/*.nim"] 158 }, 159 "triggerTaskOnSave.restart": true, 160 "triggerTaskOnSave.showStatusBarToggle": true 161 162 ```