BUILD_MESON 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. Meson build system for Dinit
  2. =-=-=-=-=-=-=-=-=-=-=-=-=-=-
  3. <!> Special notes about building Dinit via Meson
  4. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  5. Please keep in mind:
  6. 1. Meson build system for Dinit is an experimental way to build Dinit.
  7. it might have some bugs. Please report bugs on https://github.com/davmac314/dinit/issues
  8. 2. Meson build system for Dinit is "extra" part. The main build system is GNU Make.
  9. This means that the feature is first tested on Make. There may also be delays
  10. in adding new Dinit's features to Meson builds.
  11. 3. If you found some bugs in Meson builds, Please also test it on GNU make builds.
  12. Buidling Dinit via Meson
  13. =-=-=-=-=-=-=-=-=-=-=-=-
  14. Buidling Dinit is available via two "Build system": meson & make.
  15. This file contains instructions for building Dinit using meson.
  16. Bulding dinit via meson requires "meson" (0.56.0 or later) and a C++11 compiler
  17. (GCC version 4.9 and later, or Clang ~5.0 and later, should be fine).
  18. Short version
  19. =-=-=-=-=-=-=
  20. Run "meson setup builddir && meson compile -C builddir". Your system type will
  21. hopefully be detected automatically and appropriate configuration chosen, and Dinit
  22. will be built. Continue reading instructions at "Running the test suite" or skip
  23. straight to "Installation".
  24. If this fails, or if you are cross-compiling, read the "long version" instructions.
  25. Long version
  26. =-=-=-=-=-=-
  27. Meson configures all you need to build Dinit. It detects your OS, detects your
  28. compiler & sets something based on your system information.
  29. By Default no action is required & meson configures everything needed to build Dinit.
  30. Note that the "eg++" or "clang++" package must be installed on OpenBSD
  31. as the default "g++" compiler is too old. Clang is a part of the base system
  32. in recent releases.
  33. In Meson you need to prepare the "build directory". simply just type:
  34. meson setup builddir/
  35. This command configures "build directory" in builddir/. You can set desired
  36. directory (but we suggest don't use dinit's directory such as build/ & src/ or ...
  37. as "build dir"). If everything goes smoothly this will prepare everything to
  38. build dinit, dinitctl and optionaly the shutdown/reboot/halt utilitys by default.
  39. Everything is ready! you can compile Dinit with
  40. meson compile -C builddir
  41. This command builds the dinit, dinitctl and optionaly the shutdown/reboot/halt
  42. utilities by default.
  43. Dinit's custom options
  44. =-=-=-=-=-=-=-=-=-=-=-
  45. Dinit should generally build with no additional options, all required
  46. options/flags will be added automatically. Custom options can be passed
  47. with command line:
  48. meson setup -Doption=value builddir/
  49. or users can modify original "meson_options.txt" and set values.
  50. Custom options:
  51. shutdown-prefix : Name prefix for "shutdown", "halt" and "reboot"
  52. commands (if they are built).
  53. This affects both the output, and what command dinit
  54. will execute as part of system shutdown. If you want
  55. to install Dinit alongside another init system with
  56. its own shutdown/halt/reboot commands, set
  57. this (for eg. to "dinit-").
  58. Available values : everything you want!
  59. Default value : (empty)
  60. build-shutdown : Whether to build the "shutdown" (and "halt" etc) utilities.
  61. These are only useful if dinit is the system init
  62. (i.e. the PID 1 process). You probably don't want
  63. this unless building for Linux.
  64. Available values : enabled, disabled, auto
  65. Default value : auto
  66. dinit-control-socket-path : Default full path to the control socket, for when
  67. Dinit runs as system service manager.
  68. Available values : anywhere you want!
  69. Default value : /run/dinitctl
  70. unit-tests : Building Unit tests. see "Running test suite", below.
  71. Available values: true, false
  72. Default value : false
  73. igr-tests : Building Integration tests. see "Running test suite", below.
  74. Available values : true, false
  75. Default value : false
  76. fuzzer : Building LLVM's Libfuzzer for Dinit. see "Running fuzzer", below.
  77. Available values : true, false
  78. Default value : false
  79. use-utmpx : Whether to build support for manipulating the
  80. utmp/utmpx database via the related POSIX functions.
  81. This may be required (along with appropriate service
  82. configuration) for utilities like "who" to work
  83. correctly (the service configuration items "inittab-id"
  84. and "inittab-line" have no effect if this is disabled).
  85. If not set to any value, support is enabled for certain
  86. systems automatically and disabled for all others.
  87. Available values : enabled, disabled, auto
  88. Default value : auto
  89. use-initgroups : Whether to use initgroups to initialize supplementary
  90. groups in services that use run-as with a name. Without
  91. this the services may potentially misbehave as process
  92. and its child processes won't recognize being in the
  93. supplementary groups, only their primary group. However,
  94. some systems may not implement the initgroups API, so
  95. it may be necessary to disable it on those.
  96. Available vlaues : enabled, disabled, auto
  97. Default value : auto
  98. dinit-sbindir : Default full path to the dinit executables.
  99. For some reasons Dinit dont follow Meson's default
  100. sbindir option. see "Why we use another option
  101. for sbindir?", below.
  102. Available values : anywhere you want!
  103. Default value : /sbin
  104. man-pages : Building Dinit's man-pages.
  105. Available values : true, false
  106. Default value : true
  107. support-cgroups : Enable Cgroups supprot.
  108. Available values : enabled, disabled, auto
  109. Default value : auto
  110. build-shutdown : Building shutdown/reboot/halt or not.
  111. Available values : enabled, disabled, auto
  112. Default value : auto
  113. Running test suite
  114. =-=-=-=-=-=-=-=-=-
  115. Enable "unit-tests" option to run the test suite:
  116. meson setup -Dunit-tests=true builddir/
  117. In Dinit's make build system -fsanitize enabled for unit tests but in meson
  118. it's not enabled. so if you need that use this option in meson setup step:
  119. meson setup -Db_sanitizes='address,undefined' builddir/
  120. Note: Unlike Dinit's make build system, This flag enables sanitizers for
  121. entire build.
  122. Enable "igr-tests" to run the integration tests:
  123. meson setup -Digr-tests=true builddir/
  124. (The integration tests are more fragile than the unit tests, but give a
  125. better indication that Dinit will actually work correctly on your system).
  126. Finally compile Dinit with "meson compile -C builddir" and run tests via:
  127. meson test -C builddir
  128. Then Meson report test status. All test logs available at
  129. "builddir/meson-logs/testlog.txt".
  130. Installation
  131. =-=-=-=-=-=-
  132. You can install dinit via this command:
  133. meson install -C builddir
  134. If you want to install to an alternate root (eg for packaging purposes),
  135. specify that root via DESTDIR:
  136. DESTDIR=/tmp/temporary-install-path meson install -C builddir
  137. The dinit executable will be put in "dinit-sbindir" option value (by default /sbin)
  138. (or rather, in $DESTDIR/sbin), which may not be on the path for normal users.
  139. Consider making a symbolic link to /usr/sbin/dinit.
  140. Running fuzzer
  141. =-=-=-=-=-=-=-
  142. In addition to the standard test suite, there is experimental support for
  143. fuzzing the control protocol handling using LLVM/clang's fuzzer (libFuzzer).
  144. Enable "fuzzer" option to build fuzzer:
  145. meson setup -Dfuzzer=true builddir
  146. Then changing current directory to Your builddir (eg builddir)/src/tests/cptests/,
  147. create a "corpus" directory and run the fuzzer:
  148. mkdir corpus
  149. ./fuzz corpus
  150. This will auto-generate test data as it finds input which triggers new
  151. execution paths. Check libFuzzer documentation for further details.
  152. Why we use another option for sbindir?
  153. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  154. For some reasons, Old Mesons force sbindir will prefixed by Meson's prefix
  155. (eg /usr + sbin) but Dinit project use /sbin by default as sbindir.
  156. Meson 0.62.0 release fixes this thing but we target Mesons's 0.56.0 as
  157. minimum version. So we use "dinit-sbindir" instead of default "sbindir".
  158. Some notes
  159. =-=-=-=-=-
  160. 1. Dinit use "custom" buildtype with "'optimization=s', 'debug=false'"
  161. (-Os, no debug) by default.
  162. 2. For building with debug symbols, use "meson setup -Ddebug=true builddir" or
  163. a buildtype with "debug=true"
  164. 3. For enabling LTO, use "meson setup -Db_lto=true builddir" command.
  165. Special note for GCC/Libstdc++
  166. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  167. (Note: the issue discussed here has apparently been resolved in recent GCC versions).
  168. GCC 5.x onwards includes a "dual ABI" in its standard library implementation, aka Libstdc++.
  169. Compiling against the newer (C++11 and later) ABI can be achieved by adding
  170. -D_GLIBCXX_USE_CXX11_ABI=1 to the compiler command line; this uses a non-standard language
  171. extension to differently mangle symbol names in order to link against the new ABI versions.
  172. (Some systems may be configured to build with the new ABI by default, and in that
  173. case you build against the old ABI using -D_GLIBCXX_USE_CXX11_ABI=0).
  174. This is problematic for several reasons. First, it prevents linking against the
  175. new ABI with other compilers that do not understand the language extension
  176. (LLVM i.e. clang++ does so in recent versions, so this is perhaps no longer
  177. much of a problem in practice). Secondly, some aspects of library behaviour are
  178. ABI-dependent but cannot be changed using the ABI macro; in particular, exceptions
  179. thrown as a result of failed I/O operations are, in GCC versions 5.x and 6.x, always
  180. "old ABI" exceptions which cannot be caught by code compiled against the new ABI, and
  181. in GCC version 7.x they are always "new ABI" exceptions which cannot be caught by
  182. code compiled against the old ABI. Since the one library object now supposedly
  183. houses both ABIs, this means that at least one of the two ABIs is always broken.
  184. A blog post describing the dual ABI mechanism can be found here:
  185. https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/
  186. The bug regarding the issue with catching other-ABI exceptions is here:
  187. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145
  188. Since Dinit is affected by this bug, the unfortunate possibility exists to break
  189. Dinit by upgrading GCC. If you have libstdc++ corresponding to GCC 5.x or 6.x,
  190. you *must* build with the old ABI, but Dinit will be broken if you upgrade to GCC 7.
  191. If you have libstdc++ from GCC 7, you *must* build with the new ABI. If the wrong
  192. ABI is used, Dinit may still run successfully but any attempt to load a non-existing
  193. service, for example, will cause Dinit to crash.