building.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. # If you want to build a macOS app bundle for distribution
  119. % echo 'export BUILD_OWNCLOUD_OSX_BUNDLE=ON' >> ~/.nextcloud_build_variables
  120. Replace ``~/Builds`` with a different directory if you'd like the build to end up elsewhere.
  121. ..
  122. .. code-block:: bash
  123. % source ~/.nextcloud_build_variables
  124. % cd ~/Repositories/desktop/build
  125. % cmake ..
  126. 9. Compile and install:
  127. .. code-block:: bash
  128. % make install
  129. Windows Development Build
  130. -------------------------
  131. If you want to test some changes and deploy them locally, you can build natively
  132. on Windows using MinGW. If you want to generate an installer for deployment, please
  133. follow `Windows Installer Build (Cross-Compile)`_ instead.
  134. 1. Get the required dependencies:
  135. * Make sure that you have CMake_ and Git_.
  136. * Download the Qt_ MinGW package. You will use the MinGW version bundled with it.
  137. * Download an `OpenSSL Windows Build`_ (the non-"Light" version)
  138. 2. Get the QtKeychain_ sources as well as the latest versions of the Nextcloud client
  139. from Git as follows
  140. .. code-block:: bash
  141. git clone https://github.com/frankosterfeld/qtkeychain.git
  142. git clone git://github.com/nextcloud/client.git
  143. 3. Open the Qt MinGW shortcut console from the Start Menu
  144. 4. Make sure that OpenSSL's ``bin`` directory as well as your qtkeychain source
  145. directories are in your PATH. This will allow CMake to find the library and
  146. headers, as well as allow the Nextcloud client to find the DLLs at runtime::
  147. set PATH=C:\<OpenSSL Install Dir>\bin;%PATH%
  148. set PATH=C:\<qtkeychain Clone Dir>;%PATH%
  149. 5. Build qtkeychain **directly in the source directory** so that the DLL is built
  150. in the same directory as the headers to let CMake find them together through PATH::
  151. cd <qtkeychain Clone Dir>
  152. cmake -G "MinGW Makefiles" .
  153. mingw32-make
  154. cd ..
  155. 6. Create the build directory::
  156. mkdir client-build
  157. cd client-build
  158. 7. Build the client::
  159. cmake -G "MinGW Makefiles" ../client
  160. mingw32-make
  161. .. note:: You can try using ninja to build in parallel using
  162. ``cmake -G Ninja ../client`` and ``ninja`` instead.
  163. .. note:: Refer to the :ref:`generic-build-instructions` section for additional options.
  164. The Nextcloud binary will appear in the ``bin`` directory.
  165. .. _`Windows Installer Build (Cross-Compile)`:
  166. Windows Installer (i.e. Deployment) Build (Cross-Compile)
  167. ---------------------------------------------------------
  168. Due to the large number of dependencies, building the client installer for Windows
  169. is **currently only officially supported on openSUSE**, by using the MinGW cross compiler.
  170. You can set up any currently supported version of openSUSE in a virtual machine if you do not
  171. have it installed already.
  172. In order to make setup simple, you can use the provided Dockerfile to build your own image.
  173. 1. Assuming you are in the root of the Nextcloud Client's source tree, you can
  174. build an image from this Dockerfile like this::
  175. cd admin/win/docker
  176. docker build . -t nextcloud-client-win32:<version>
  177. Replace ``<version>`` by the version of the client you are building, e.g.
  178. |version| for the release of the client that this document describes.
  179. If you do not wish to use docker, you can run the commands in ``RUN`` manually
  180. in a shell, e.g. to create your own build environment in a virtual machine.
  181. .. note:: Docker images are specific to releases. This one refers to |version|.
  182. Newer releases may have different dependencies, and thus require a later
  183. version of the docker image! Always pick the docker image fitting your release
  184. of Nextcloud client!
  185. 2. From within the source tree Run the docker instance::
  186. docker run -v "$PWD:/home/user/client" nextcloud-client-win32:<version> \
  187. /home/user/client/admin/win/docker/build.sh client/ $(id -u)
  188. It will run the build, create an NSIS based installer, as well as run tests.
  189. You will find the resulting binary in an newly created ``build-win32`` subfolder.
  190. If you do not wish to use docker, and ran the ``RUN`` commands above in a virtual machine,
  191. you can run the indented commands in the lower section of ``build.sh`` manually in your
  192. source tree.
  193. 4. Finally, you should sign the installer to avoid warnings upon installation.
  194. This requires a `Microsoft Authenticode`_ Certificate ``osslsigncode`` to sign the installer::
  195. osslsigncode -pkcs12 $HOME/.codesign/packages.pfx -h sha256 \
  196. -pass yourpass \
  197. -n "ACME Client" \
  198. -i "http://acme.com" \
  199. -ts "http://timestamp.server/" \
  200. -in ${unsigned_file} \
  201. -out ${installer_file}
  202. For ``-in``, use the URL to the time stamping server provided by your CA along with the Authenticode certificate. Alternatively,
  203. you may use the official Microsoft ``signtool`` utility on Microsoft Windows.
  204. If you're familiar with docker, you can use the version of ``osslsigncode`` that is part of the docker image.
  205. .. _generic-build-instructions:
  206. Generic Build Instructions
  207. --------------------------
  208. Compared to previous versions, building the desktop sync client has become easier. Unlike
  209. earlier versions, CSync, which is the sync engine library of the client, is now
  210. part of the client source repository and not a separate module.
  211. To build the most up-to-date version of the client:
  212. 1. Clone the latest versions of the client from Git_ as follows:
  213. .. code-block:: bash
  214. $ git clone git://github.com/nextcloud/client.git
  215. $ cd client
  216. $ git submodule update --init
  217. 2. Create the build directory
  218. .. code-block:: bash
  219. $ mkdir client-build
  220. $ cd client-build
  221. 3. Configure the client build
  222. .. code-block:: bash
  223. $ cmake -DCMAKE_BUILD_TYPE="Debug" ..
  224. .. note:: You must use absolute paths for the ``include`` and ``library``
  225. directories.
  226. .. note:: On macOS, you need to specify ``-DCMAKE_INSTALL_PREFIX=target``,
  227. where ``target`` is a private location, i.e. in parallel to your build
  228. dir by specifying ``../install``.
  229. .. note:: qtkeychain must be compiled with the same prefix e.g ``CMAKE_INSTALL_PREFIX=/Users/path/to/client/install/ .``
  230. .. note:: Example:: ``cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5 -DCMAKE_INSTALL_PREFIX=/Users/path/to/client/install/``
  231. 4. Call ``make``.
  232. The Nextcloud binary will appear in the ``bin`` directory.
  233. 5. (Optional) Call ``make install`` to install the client to the
  234. ``/usr/local/bin`` directory.
  235. The following are known cmake parameters:
  236. * ``QTKEYCHAIN_LIBRARY=/path/to/qtkeychain.dylib -DQTKEYCHAIN_INCLUDE_DIR=/path/to/qtkeychain/``:
  237. Used for stored credentials. When compiling with Qt5, the library is called ``qt5keychain.dylib.``
  238. You need to compile QtKeychain with the same Qt version.
  239. * ``WITH_DOC=TRUE``: Creates doc and manpages through running ``make``; also adds install statements,
  240. providing the ability to install using ``make install``.
  241. * ``CMAKE_PREFIX_PATH=/path/to/Qt5.2.0/5.2.0/yourarch/lib/cmake/``: Builds using Qt5.
  242. * ``BUILD_WITH_QT4=ON``: Builds using Qt4 (even if Qt5 is found).
  243. * ``CMAKE_INSTALL_PREFIX=path``: Set an install prefix. This is mandatory on Mac OS
  244. Address Sanitizer
  245. =================
  246. You can enable the address sanitizer to detect memory corruptions and other mistakes.
  247. The are the following sanitizers are available:
  248. * Address Sanitizer
  249. * Leak anitizer
  250. * Memory sanitizer
  251. * Undefined sanitizer
  252. * Threads sanitizer
  253. You can enable one or more sanitizers through CMake. For example, to
  254. enable the address and the undefined sanitizer, execute CMake like
  255. ``cmake .. -D ECM_ENABLE_SANITIZERS="address;undefined"``.
  256. Keep in mind that not all combinations of sanitizers work together, and on some
  257. platforms, not all types of sanitizers are available. For example, on Windows there is
  258. currently only the address sanitizer available. If you are on Windows, you need to
  259. make sure that the linker can find the sanitizer dlls at runtime. If you installed
  260. Visual Studio in the standard location, you could find them in
  261. **C:/ProgramFiles (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/x64/lib/clang/10.0.0/lib/windows**.
  262. Make sure you add this location to your path. You may also need to
  263. `upgrade your Visual Studio version <https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160#install-the-addresssanitizer>`_.
  264. .. note:: If you use Visual Studio on Windows, you can enable the
  265. sanitizer if you click on **Manage Configurations**, scroll
  266. down to the section **CMake Command Arguments** and enter then
  267. ``-D ECM_ENABLE_SANITIZERS="address"`` in the text input field below.
  268. After that, click on **Save and generate CMake cache to load variables**
  269. right above the table.
  270. .. _CMake: http://www.cmake.org/download
  271. .. _CSync: http://www.csync.org
  272. .. _Client Download Page: https://nextcloud.com/install/#install-clients
  273. .. _Git: http://git-scm.com
  274. .. _OpenSSL Windows Build: http://slproweb.com/products/Win32OpenSSL.html
  275. .. _Qt: http://www.qt.io/download
  276. .. _Microsoft Authenticode: https://msdn.microsoft.com/en-us/library/ie/ms537361%28v=vs.85%29.aspx
  277. .. _QtKeychain: https://github.com/frankosterfeld/qtkeychain