building.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. .. _building-label:
  2. ===============================
  3. Appendix A: Building the Client
  4. ===============================
  5. The goal of this section is to set up a build environment for developing
  6. and testing the Nextcloud Desktop client. If you just want to use the
  7. Nextcloud Desktop client without developing and testing it, you should
  8. download the latest stable build instead.
  9. .. note:: These instructions represent a particular streamlined and easy-to-understand
  10. methodology, but they are by no means the only way of setting up a build
  11. environment.
  12. The steps listed here have been tested multiple times and should allow you
  13. to build the client and/or the documentation with not warnings or errors.
  14. These instructions should be current with the version, |version|, of the
  15. Nextcloud Client with which it ships. If you are using the most recent version
  16. of these instructions, and you run into errors or warnings with the latest
  17. code from the repository, please open a GitHub Issue to let us know so we can
  18. document a workaround or fix any underlying problems.
  19. Using GitHub
  20. ------------
  21. By default, cloning the GitHub repository will give you the "master" branch,
  22. which is the most recent. If for some reason you want to build an older
  23. version of the Nextcloud Desktop client, you can choose a branch corresponding
  24. with that version. However, for older versions of the client, please be mindful
  25. that any issues present may have been fixed in more recent versions.
  26. .. note:: Doing anything other than just downloading the existing code will
  27. require you to have a GitHub account.
  28. If your goal in cloning and building the Nextcloud Desktop client is to
  29. contribute to its development, and you are not already a "collaborator"
  30. on the Nextcloud Desktop GitHub repository, you will need to create a "fork"
  31. by clicking the "fork" button in the upper right on any GitHub page in the
  32. repository. It is important to do this in advance because the URL for cloning
  33. the repository is different for a fork than for the main official version.
  34. When cloning a GitHub repository, you have two options for authenticating your
  35. GitHub account, SSH or HTTPS. SSH requires additional setup but is more secure
  36. and simplifies things later on. For an explanation of the differences between
  37. HTTPS and SSH, as well as instructions to set up SSH, see this `GitHub
  38. help article`_ on the subject.
  39. .. _`GitHub help article`: https://help.github.com/en/articles/which-remote-url-should-i-use
  40. The most basic version of the Git command for cloning a repository is as follows:
  41. .. code-block:: bash
  42. $ git clone <repository_url>
  43. Which will clone the repository into the directory where you run the command.
  44. The four versions of the ``git clone`` command are as follows:
  45. 1. HTTPS from the official repository:
  46. .. code-block:: bash
  47. $ git clone https://github.com/nextcloud/desktop.git
  48. 2. SSH from the official repository:
  49. .. code-block:: bash
  50. $ git clone git@github.com:nextcloud/desktop.git
  51. 3. HTTPS from a fork (see above):
  52. .. code-block:: bash
  53. % git clone https://github.com/<github_username>/desktop.git
  54. 4. SSH from a fork (see above):
  55. .. code-block:: bash
  56. % git clone git@github.com:<github_username>/desktop.git
  57. macOS Development Build
  58. -----------------------
  59. .. note:: While it is possible to do many of the following steps using GUI
  60. frontends, wherever possible the Terminal commands are listed instead, in order
  61. to streamline the process.
  62. 1. Install Xcode from the Mac App Store:
  63. https://apps.apple.com/app/xcode/id497799835
  64. Then, in Terminal:
  65. 2. Install Xcode command line tools:
  66. .. code-block:: bash
  67. % xcode-select –install
  68. 3. Install Homebrew from `brew.sh`_ (which will just give you the following):
  69. .. _`brew.sh`: https://brew.sh
  70. .. code-block:: bash
  71. % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  72. .. note:: Under certain cirumstances, you may get on error along the
  73. lines of ``Permission denied @ apply2files`` when installing certain
  74. Homebrew packages. This is `a known issue`_ and can be fixed by changing
  75. the permissions on the affected files with the following command:
  76. .. code-block:: bash
  77. % sudo chown -R $(whoami):admin /usr/local/* \
  78. && sudo chmod -R g+rwx /usr/local/*
  79. This workaround may lead to other shell warnings.
  80. .. _`a known issue`: https://stackoverflow.com/a/63241724
  81. 4. Install Homebrew packages:
  82. .. code-block:: bash
  83. % brew install git qt qtkeychain cmake openssl glib cmocka
  84. 5. Certain Homebrew packages are not automatically linked in places where
  85. the build scripts can find them, so you can create a shell-profile script
  86. that will find and load them dynamically when you run a build:
  87. .. code-block:: bash
  88. % echo 'export OPENSSL_ROOT_DIR=$(brew --prefix openssl)' >> ~/.nextcloud_build_variables
  89. % echo 'export QT_PATH=$(brew --prefix qt5)/bin' >> ~/.nextcloud_build_variables
  90. % echo 'export Qt5LinguistTools_DIR=$(brew --prefix qt5)/lib/cmake/Qt5LinguistTools/' >> ~/.nextcloud_build_variables
  91. .. note:: The name ``~/.nextcloud_build_variables`` is just a suggestion for
  92. convenience. You can use a different file or create an entire shell
  93. script, but this way of doing things is the simplest to explain.
  94. 6. Clone the Nextcloud repository to a convenient location, such as ``~/Repositories``:
  95. .. code-block:: bash
  96. % mkdir ~/Repositories
  97. (if it doesn't already exist), then:
  98. .. code-block:: bash
  99. % cd ~/Repositories
  100. .. note:: The cloned repository can go basically anywhere your user account
  101. has write access, though it should not go in a directory synced with another
  102. cloud service (especially not iCloud Drive). ``~/Repositories`` is recommended
  103. for tidiness and consistency.
  104. .. code-block:: bash
  105. % git clone <repository_url>
  106. (See the above section on using GitHub for an explanation of what URL to use.)
  107. 7. Create build directory:
  108. .. code-block:: bash
  109. % cd ~/Repositories/desktop
  110. % mkdir build
  111. 8. Generate the build files:
  112. .. note::
  113. By default Nextcloud Desktop will build in a protected directory on macOS,
  114. so you need to specify a build location. You can do this every time you build,
  115. or you can add it to your save build variables, like so:
  116. .. code-block:: bash
  117. % echo 'export CMAKE_INSTALL_PREFIX=~/Builds' >> ~/.nextcloud_build_variables
  118. Replace ``~/Builds`` with a different directory if you'd like the build to end up elsewhere.
  119. ..
  120. .. code-block:: bash
  121. % source ~/.nextcloud_build_variables
  122. % cd ~/Repositories/desktop/build
  123. % cmake ..
  124. 9. Compile and install:
  125. .. code-block:: bash
  126. % make install
  127. Windows Development Build
  128. -------------------------
  129. If you want to test some changes and deploy them locally, you can build natively
  130. on Windows using MinGW. If you want to generate an installer for deployment, please
  131. follow `Windows Installer Build (Cross-Compile)`_ instead.
  132. 1. Get the required dependencies:
  133. * Make sure that you have CMake_ and Git_.
  134. * Download the Qt_ MinGW package. You will use the MinGW version bundled with it.
  135. * Download an `OpenSSL Windows Build`_ (the non-"Light" version)
  136. 2. Get the QtKeychain_ sources as well as the latest versions of the Nextcloud client
  137. from Git as follows
  138. .. code-block:: bash
  139. git clone https://github.com/frankosterfeld/qtkeychain.git
  140. git clone git://github.com/nextcloud/client.git
  141. 3. Open the Qt MinGW shortcut console from the Start Menu
  142. 4. Make sure that OpenSSL's ``bin`` directory as well as your qtkeychain source
  143. directories are in your PATH. This will allow CMake to find the library and
  144. headers, as well as allow the Nextcloud client to find the DLLs at runtime::
  145. set PATH=C:\<OpenSSL Install Dir>\bin;%PATH%
  146. set PATH=C:\<qtkeychain Clone Dir>;%PATH%
  147. 5. Build qtkeychain **directly in the source directory** so that the DLL is built
  148. in the same directory as the headers to let CMake find them together through PATH::
  149. cd <qtkeychain Clone Dir>
  150. cmake -G "MinGW Makefiles" .
  151. mingw32-make
  152. cd ..
  153. 6. Create the build directory::
  154. mkdir client-build
  155. cd client-build
  156. 7. Build the client::
  157. cmake -G "MinGW Makefiles" ../client
  158. mingw32-make
  159. .. note:: You can try using ninja to build in parallel using
  160. ``cmake -G Ninja ../client`` and ``ninja`` instead.
  161. .. note:: Refer to the :ref:`generic-build-instructions` section for additional options.
  162. The Nextcloud binary will appear in the ``bin`` directory.
  163. .. _`Windows Installer Build (Cross-Compile)`:
  164. Windows Installer (i.e. Deployment) Build (Cross-Compile)
  165. ---------------------------------------------------------
  166. Due to the large number of dependencies, building the client installer for Windows
  167. is **currently only officially supported on openSUSE**, by using the MinGW cross compiler.
  168. You can set up any currently supported version of openSUSE in a virtual machine if you do not
  169. have it installed already.
  170. In order to make setup simple, you can use the provided Dockerfile to build your own image.
  171. 1. Assuming you are in the root of the Nextcloud Client's source tree, you can
  172. build an image from this Dockerfile like this::
  173. cd admin/win/docker
  174. docker build . -t nextcloud-client-win32:<version>
  175. Replace ``<version>`` by the version of the client you are building, e.g.
  176. |version| for the release of the client that this document describes.
  177. If you do not wish to use docker, you can run the commands in ``RUN`` manually
  178. in a shell, e.g. to create your own build environment in a virtual machine.
  179. .. note:: Docker images are specific to releases. This one refers to |version|.
  180. Newer releases may have different dependencies, and thus require a later
  181. version of the docker image! Always pick the docker image fitting your release
  182. of Nextcloud client!
  183. 2. From within the source tree Run the docker instance::
  184. docker run -v "$PWD:/home/user/client" nextcloud-client-win32:<version> \
  185. /home/user/client/admin/win/docker/build.sh client/ $(id -u)
  186. It will run the build, create an NSIS based installer, as well as run tests.
  187. You will find the resulting binary in an newly created ``build-win32`` subfolder.
  188. If you do not wish to use docker, and ran the ``RUN`` commands above in a virtual machine,
  189. you can run the indented commands in the lower section of ``build.sh`` manually in your
  190. source tree.
  191. 4. Finally, you should sign the installer to avoid warnings upon installation.
  192. This requires a `Microsoft Authenticode`_ Certificate ``osslsigncode`` to sign the installer::
  193. osslsigncode -pkcs12 $HOME/.codesign/packages.pfx -h sha256 \
  194. -pass yourpass \
  195. -n "ACME Client" \
  196. -i "http://acme.com" \
  197. -ts "http://timestamp.server/" \
  198. -in ${unsigned_file} \
  199. -out ${installer_file}
  200. For ``-in``, use the URL to the time stamping server provided by your CA along with the Authenticode certificate. Alternatively,
  201. you may use the official Microsoft ``signtool`` utility on Microsoft Windows.
  202. If you're familiar with docker, you can use the version of ``osslsigncode`` that is part of the docker image.
  203. .. _generic-build-instructions:
  204. Generic Build Instructions
  205. --------------------------
  206. Compared to previous versions, building the desktop sync client has become easier. Unlike
  207. earlier versions, CSync, which is the sync engine library of the client, is now
  208. part of the client source repository and not a separate module.
  209. To build the most up-to-date version of the client:
  210. 1. Clone the latest versions of the client from Git_ as follows:
  211. .. code-block:: bash
  212. $ git clone git://github.com/nextcloud/client.git
  213. $ cd client
  214. $ git submodule update --init
  215. 2. Create the build directory
  216. .. code-block:: bash
  217. $ mkdir client-build
  218. $ cd client-build
  219. 3. Configure the client build
  220. .. code-block:: bash
  221. $ cmake -DCMAKE_BUILD_TYPE="Debug" ..
  222. .. note:: You must use absolute paths for the ``include`` and ``library``
  223. directories.
  224. .. note:: On macOS, you need to specify ``-DCMAKE_INSTALL_PREFIX=target``,
  225. where ``target`` is a private location, i.e. in parallel to your build
  226. dir by specifying ``../install``.
  227. .. note:: qtkeychain must be compiled with the same prefix e.g ``CMAKE_INSTALL_PREFIX=/Users/path/to/client/install/ .``
  228. .. note:: Example:: ``cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5 -DCMAKE_INSTALL_PREFIX=/Users/path/to/client/install/``
  229. 4. Call ``make``.
  230. The Nextcloud binary will appear in the ``bin`` directory.
  231. 5. (Optional) Call ``make install`` to install the client to the
  232. ``/usr/local/bin`` directory.
  233. The following are known cmake parameters:
  234. * ``QTKEYCHAIN_LIBRARY=/path/to/qtkeychain.dylib -DQTKEYCHAIN_INCLUDE_DIR=/path/to/qtkeychain/``:
  235. Used for stored credentials. When compiling with Qt5, the library is called ``qt5keychain.dylib.``
  236. You need to compile QtKeychain with the same Qt version.
  237. * ``WITH_DOC=TRUE``: Creates doc and manpages through running ``make``; also adds install statements,
  238. providing the ability to install using ``make install``.
  239. * ``CMAKE_PREFIX_PATH=/path/to/Qt5.2.0/5.2.0/yourarch/lib/cmake/``: Builds using Qt5.
  240. * ``BUILD_WITH_QT4=ON``: Builds using Qt4 (even if Qt5 is found).
  241. * ``CMAKE_INSTALL_PREFIX=path``: Set an install prefix. This is mandatory on Mac OS
  242. Address Sanitizer
  243. =================
  244. You can enable the address sanitizer to detect memory corruptions and other mistakes.
  245. The are the following sanitizers are available:
  246. * Address Sanitizer
  247. * Leak anitizer
  248. * Memory sanitizer
  249. * Undefined sanitizer
  250. * Threads sanitizer
  251. You can enable one or more sanitizers through CMake. For example, to
  252. enable the address and the undefined sanitizer, execute CMake like
  253. ``cmake .. -D ECM_ENABLE_SANITIZERS="address;undefined"``.
  254. Keep in mind that not all combinations of sanitizers work together, and on some
  255. platforms, not all types of sanitizers are available. For example, on Windows there is
  256. currently only the address sanitizer available. If you are on Windows, you need to
  257. make sure that the linker can find the sanitizer dlls at runtime. If you installed
  258. Visual Studio in the standard location, you could find them in
  259. **C:/ProgramFiles (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/x64/lib/clang/10.0.0/lib/windows**.
  260. Make sure you add this location to your path. You may also need to
  261. `upgrade your Visual Studio version <https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160#install-the-addresssanitizer>`_.
  262. .. note:: If you use Visual Studio on Windows, you can enable the
  263. sanitizer if you click on **Manage Configurations**, scroll
  264. down to the section **CMake Command Arguments** and enter then
  265. ``-D ECM_ENABLE_SANITIZERS="address"`` in the text input field below.
  266. After that, click on **Save and generate CMake cache to load variables**
  267. right above the table.
  268. .. _CMake: http://www.cmake.org/download
  269. .. _CSync: http://www.csync.org
  270. .. _Client Download Page: https://nextcloud.com/install/#install-clients
  271. .. _Git: http://git-scm.com
  272. .. _OpenSSL Windows Build: http://slproweb.com/products/Win32OpenSSL.html
  273. .. _Qt: http://www.qt.io/download
  274. .. _Microsoft Authenticode: https://msdn.microsoft.com/en-us/library/ie/ms537361%28v=vs.85%29.aspx
  275. .. _QtKeychain: https://github.com/frankosterfeld/qtkeychain