builtin_plugins.html 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>xmake</title>
  6. <link rel="icon" href="/assets/img/favicon.ico">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  8. <meta name="description" content="Description">
  9. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  10. <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  11. <style>
  12. .markdown-body {
  13. box-sizing: border-box;
  14. min-width: 200px;
  15. max-width: 980px;
  16. margin: 0 auto;
  17. padding: 45px;
  18. }
  19. @media (max-width: 767px) {
  20. .markdown-body {
  21. padding: 15px;
  22. }
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <article class="markdown-body">
  28. <h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/plugin/builtin_plugins">https://xmake.io/#/plugin/builtin_plugins</a>
  29. <div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
  30. </br>
  31. <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
  32. <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
  33. <style>
  34. #carbonads {
  35. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  36. Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
  37. }
  38. #carbonads {
  39. display: flex;
  40. max-width: 330px;
  41. background-color: hsl(0, 0%, 98%);
  42. box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
  43. }
  44. #carbonads a {
  45. color: inherit;
  46. text-decoration: none;
  47. }
  48. #carbonads a:hover {
  49. color: inherit;
  50. }
  51. #carbonads span {
  52. position: relative;
  53. display: block;
  54. overflow: hidden;
  55. }
  56. #carbonads .carbon-wrap {
  57. display: flex;
  58. }
  59. .carbon-img {
  60. display: block;
  61. margin: 0;
  62. line-height: 1;
  63. }
  64. .carbon-img img {
  65. display: block;
  66. }
  67. .carbon-text {
  68. font-size: 13px;
  69. padding: 10px;
  70. line-height: 1.5;
  71. text-align: left;
  72. }
  73. .carbon-poweredby {
  74. display: block;
  75. padding: 8px 10px;
  76. background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  77. text-align: center;
  78. text-transform: uppercase;
  79. letter-spacing: .5px;
  80. font-weight: 600;
  81. font-size: 9px;
  82. line-height: 1;
  83. }
  84. </style>
  85. <h2 id="generateideprojectfiles">Generate IDE Project Files</h2>
  86. <h3 id="generatemakefile">Generate Makefile</h3>
  87. <pre><code class="lang-bash">$ xmake project -k makefile
  88. </code></pre>
  89. <h3 id="generatecmakeliststxt">Generate CMakelists.txt</h3>
  90. <pre><code class="lang-console">$ xmake project -k cmakelists
  91. </code></pre>
  92. <h3 id="generatebuildninja">Generate build.ninja</h3>
  93. <p>!> Only supported in versions above 2.3.1</p>
  94. <pre><code class="lang-console">$ xmake project -k ninja
  95. </code></pre>
  96. <h3 id="generatecompile_flags">Generate compile_flags</h3>
  97. <pre><code class="lang-console">$ xmake project -k compile_flags
  98. </code></pre>
  99. <h3 id="generatecompile_commands">Generate compile_commands</h3>
  100. <p>We can export the compilation commands info of all source files and it is JSON compilation database format.</p>
  101. <pre><code class="lang-console">$ xmake project -k compile_commands
  102. </code></pre>
  103. <p>The the content of the output file:</p>
  104. <pre><code>[
  105. { "directory": "/home/user/llvm/build",
  106. "command": "/usr/bin/clang++ -Irelative -DSOMEDEF=\"With spaces, quotes and \\-es.\" -c -o file.o file.cc",
  107. "file": "file.cc" },
  108. ...
  109. ]
  110. </code></pre><p>Please see <a href="#https://clang.llvm.org/docs/JSONCompilationDatabase.html">JSONCompilationDatabase</a> if need known more info about <code>compile_commands</code>.</p>
  111. <h3 id="generatexcodeprojectfile">Generate Xcode project file</h3>
  112. <p>At present, we have no time to implement the generation of xcode projects by ourselves, but it does not mean that it is not supported, because xmake supports the generation of cmakelists.txt files, and cmake supports the generation of xcode project files. Before the official implementation,<br>We can also support it in disguise through cmake, xmake will automatically call cmake internally to transfer the generated results, there is no difference in use for users, just make sure that cmake has been installed:</p>
  113. <pre><code class="lang-console">$ xmake project -k xcode
  114. </code></pre>
  115. <p>!> After we have time, we will re-implement each more complete xcode output plugin by ourselves, and welcome everyone to contribute.</p>
  116. <h3 id="generatevisualstudioproject">Generate VisualStudio Project</h3>
  117. <h4 id="compilewithxmakeintegration">Compile with xmake integration</h4>
  118. <p>v2.2.8 or later, provides a new version of the vs project generation plugin extension, which is very different from the previous plugin processing mode for generating vs. The previously generated vs project is the compilation of all files and then transferred to vs. To handle compilation.</p>
  119. <p>But this mode, there is no way to support the rules of xmake. Because xmake&#39;s rules use a lot of custom scripts like <code>on_build</code>, they can&#39;t be expanded, so projects like qt, wdk can&#39;t support exporting to vs. compile.</p>
  120. <p>Therefore, in order to solve this problem, the new version of the vs. build plugin performs the compile operation by directly calling the xmake command under vs, and also supports intellisense and definition jumps, as well as breakpoint debugging.</p>
  121. <p>The specific use is similar to the old version:</p>
  122. <pre><code class="lang-console">$ xmake project -k [vsxmake2010|vsxmake2013|vsxmake2015|..] -m "debug;release"
  123. </code></pre>
  124. <p>If no version is specified, xmake will automatically detect the current version of vs to generate:</p>
  125. <pre><code class="lang-bash">$ xmake project -k vsxmake -m "debug,release"
  126. </code></pre>
  127. <p><img src="/assets/img/manual/qt_vs.png" alt=""></p>
  128. <p>In addition, the vsxmake plugin will additionally generate a custom configuration property page for easy and flexible modification and appending some xmake compilation configuration in the vs., and even switch to other cross toolchains in the configuration to achieve the vs. vs. Cross-compilation of other platforms such as android, linux.</p>
  129. <p><img src="/assets/img/manual/property_page_vsxmake.png" alt=""></p>
  130. <p>The v2.5.1 version provides a <code>add_rules("plugin.vsxmake.autoupdate")</code> rule. If this rule is applied, the production vs project will be checked for changes in xmake.lua and the code file list after the compilation is completed. If there are changes , The vs project will be updated automatically.</p>
  131. <pre><code class="lang-lua">add_rules("plugin.vsxmake.autoupdate")
  132. target("test")
  133. set_kind("binary")
  134. add_files("src/*.c")
  135. </code></pre>
  136. <p>In addition, we can group each target through the <code>set_group</code> interface, so that the generated vs project can be grouped according to the specified structure. For more details, please see: <a href="https://github.com/xmake-io/xmake/issues/1026">issue 1026</a></p>
  137. <h4 id="usingvsbuiltincompilationmechanism">Using vs built-in compilation mechanism</h4>
  138. <p>!> It is recommended to use the new version of the vs. plugin provided after v2.2.8 mentioned above. The support is more complete. The generation method here does not support the rules of xmake, and the generation of projects such as qt.</p>
  139. <pre><code class="lang-bash">$ xmake project -k [vs2008|vs2013|vs2015|..]
  140. </code></pre>
  141. <p>v2.1.2 or later, it supports multi-mode and multi-architecture generation for vs201x project.</p>
  142. <p>For example:</p>
  143. <pre><code class="lang-bash">$ xmake project -k vs2017 -m "debug,release"
  144. </code></pre>
  145. <p>It will generate four project configurations: <code>debug|x86</code>, <code>debug|x64</code>, <code>release|x86</code>, <code>release|x64</code>.</p>
  146. <p>Or you can set modes to <code>xmake.lua</code>:</p>
  147. <pre><code class="lang-lua">set_modes("debug", "release")
  148. </code></pre>
  149. <p>Then, we run the following command:</p>
  150. <pre><code class="lang-bash">$ xmake project -k vs2017
  151. </code></pre>
  152. <p>The effect is same.</p>
  153. <p>In addition, we can group each target through the <code>set_group</code> interface, so that the generated vs project can be grouped according to the specified structure. For more details, please see: <a href="https://github.com/xmake-io/xmake/issues/1026">issue 1026</a></p>
  154. <h2 id="runthecustomluascript">Run the Custom Lua Script</h2>
  155. <h3 id="runthegivenscript">Run the given script</h3>
  156. <p>Write a simple lua script:</p>
  157. <pre><code class="lang-lua">function main()
  158. print("hello xmake!")
  159. end
  160. </code></pre>
  161. <p>Run this lua script.</p>
  162. <pre><code class="lang-bash">$ xmake lua /tmp/test.lua
  163. </code></pre>
  164. <p><p class="tip"><br> You can also use <code>import</code> api to write a more advance lua script.<br></p>
  165. </p>
  166. <h3 id="runthebuiltinscript">Run the builtin script</h3>
  167. <p>You can run <code>xmake lua -l</code> to list all builtin script name, for example:</p>
  168. <pre><code class="lang-bash">$ xmake lua -l
  169. scripts:
  170. cat
  171. cp
  172. echo
  173. versioninfo
  174. ...
  175. </code></pre>
  176. <p>And run them:</p>
  177. <pre><code class="lang-bash">$ xmake lua cat ~/file.txt
  178. $ xmake lua echo "hello xmake"
  179. $ xmake lua cp /tmp/file /tmp/file2
  180. $ xmake lua versioninfo
  181. </code></pre>
  182. <h3 id="runinteractivecommandsrepl">Run interactive commands (REPL)</h3>
  183. <p>Enter interactive mode:</p>
  184. <pre><code class="lang-bash">$ xmake lua
  185. > 1 + 2
  186. 3
  187. > a = 1
  188. > a
  189. 1
  190. > for _, v in pairs({1, 2, 3}) do
  191. >> print(v)
  192. >> end
  193. 1
  194. 2
  195. 3
  196. </code></pre>
  197. <p>And we can <code>import</code> modules:</p>
  198. <pre><code class="lang-bash">> task = import("core.project.task")
  199. > task.run("hello")
  200. hello xmake!
  201. </code></pre>
  202. <p>If you want to cancel multiline input, please input character <code>q</code>, for example:</p>
  203. <pre><code class="lang-bash">> for _, v in ipairs({1, 2}) do
  204. >> print(v)
  205. >> q <-- cancel multiline and clear previous input
  206. > 1 + 2
  207. 3
  208. </code></pre>
  209. <h2 id="showspecifiedinformationandlist">Show specified information and list</h2>
  210. <h3 id="showbasicinformationaboutxmakeitselfandthecurrentproject">Show basic information about xmake itself and the current project</h3>
  211. <pre><code class="lang-bash">$ xmake show
  212. The information of xmake:
  213. version: 2.3.3+202006011009
  214. host: macosx/x86_64
  215. programdir: /Users/ruki/.local/share/xmake
  216. programfile: /Users/ruki/.local/bin/xmake
  217. globaldir: /Users/ruki/.xmake
  218. tmpdir: /var/folders/32/w9cz0y_14hs19lkbs6v6_fm80000gn/T/.xmake501/200603
  219. workingdir: /Users/ruki/projects/personal/tbox
  220. packagedir: /Users/ruki/.xmake/packages
  221. packagedir(cache): /Users/ruki/.xmake/cache/packages/2006
  222. The information of project: tbox
  223. version: 1.6.5
  224. plat: macosx
  225. arch: x86_64
  226. mode: release
  227. buildir: build
  228. configdir: /Users/ruki/projects/personal/tbox/.xmake/macosx/x86_64
  229. projectdir: /Users/ruki/projects/personal/tbox
  230. projectfile: /Users/ruki/projects/personal/tbox/xmake.lua
  231. </code></pre>
  232. <h3 id="showtoolchainslist">Show toolchains list</h3>
  233. <pre><code class="lang-bash">$ xmake show -l toolchains
  234. xcode Xcode IDE
  235. vs VisualStudio IDE
  236. yasm The Yasm Modular Assembler
  237. clang A C language family frontend for LLVM
  238. go Go Programming Language Compiler
  239. dlang D Programming Language Compiler
  240. sdcc Small Device C Compiler
  241. cuda CUDA Toolkit
  242. ndk Android NDK
  243. rust Rust Programming Language Compiler
  244. llvm A collection of modular and reusable compiler and toolchain technologies
  245. cross Common cross compilation toolchain
  246. nasm NASM Assembler
  247. gcc GNU Compiler Collection
  248. mingw Minimalist GNU for Windows
  249. gnu-rm GNU Arm Embedded Toolchain
  250. envs Environment variables toolchain
  251. fasm Flat Assembler
  252. </code></pre>
  253. <h3 id="showtheinformationofthegiventarget">Show the information of the given target</h3>
  254. <p>We can use it to quickly trace the location of some specific configurations.</p>
  255. <pre><code class="lang-bash">$ xmake show -t tbox
  256. The information of target(tbox):
  257. at: /Users/ruki/projects/personal/tbox/src/tbox/xmake.lua
  258. kind: static
  259. targetfile: build/macosx/x86_64/release/libtbox.a
  260. rules:
  261. -> mode.release -> ./xmake.lua:26
  262. -> mode.debug -> ./xmake.lua:26
  263. -> mode.profile -> ./xmake.lua:26
  264. -> mode.coverage -> ./xmake.lua:26
  265. -> utils.install.cmake_importfiles -> ./src/tbox/xmake.lua:15
  266. -> utils.install.pkgconfig_importfiles -> ./src/tbox/xmake.lua:16
  267. options:
  268. -> info -> ./src/tbox/xmake.lua:50
  269. -> float -> ./src/tbox/xmake.lua:50
  270. -> wchar -> ./src/tbox/xmake.lua:50
  271. -> exception -> ./src/tbox/xmake.lua:50
  272. -> force-utf8 -> ./src/tbox/xmake.lua:50
  273. -> deprecated -> ./src/tbox/xmake.lua:50
  274. -> xml -> ./src/tbox/xmake.lua:53
  275. -> zip -> ./src/tbox/xmake.lua:53
  276. -> hash -> ./src/tbox/xmake.lua:53
  277. -> regex -> ./src/tbox/xmake.lua:53
  278. -> coroutine -> ./src/tbox/xmake.lua:53
  279. -> object -> ./src/tbox/xmake.lua:53
  280. -> charset -> ./src/tbox/xmake.lua:53
  281. -> database -> ./src/tbox/xmake.lua:53
  282. packages:
  283. -> mbedtls -> ./src/tbox/xmake.lua:43
  284. -> polarssl -> ./src/tbox/xmake.lua:43
  285. -> openssl -> ./src/tbox/xmake.lua:43
  286. -> pcre2 -> ./src/tbox/xmake.lua:43
  287. -> pcre -> ./src/tbox/xmake.lua:43
  288. -> zlib -> ./src/tbox/xmake.lua:43
  289. -> mysql -> ./src/tbox/xmake.lua:43
  290. -> sqlite3 -> ./src/tbox/xmake.lua:43
  291. links:
  292. -> pthread -> option(__keyword_thread_local) -> @programdir/includes/check_csnippets.lua:100
  293. syslinks:
  294. -> pthread -> ./xmake.lua:71
  295. -> dl -> ./xmake.lua:71
  296. -> m -> ./xmake.lua:71
  297. -> c -> ./xmake.lua:71
  298. defines:
  299. -> __tb_small__ -> ./xmake.lua:42
  300. -> __tb_prefix__="tbox" -> ./src/tbox/xmake.lua:19
  301. -> _GNU_SOURCE=1 -> option(__systemv_semget) -> @programdir/includes/check_cfuncs.lua:104
  302. cxflags:
  303. -> -Wno-error=deprecated-declarations -> ./xmake.lua:22
  304. -> -fno-strict-aliasing -> ./xmake.lua:22
  305. -> -Wno-error=expansion-to-defined -> ./xmake.lua:22
  306. -> -fno-stack-protector -> ./xmake.lua:51
  307. frameworks:
  308. -> CoreFoundation -> ./src/tbox/xmake.lua:38
  309. -> CoreServices -> ./src/tbox/xmake.lua:38
  310. mxflags:
  311. -> -Wno-error=deprecated-declarations -> ./xmake.lua:23
  312. -> -fno-strict-aliasing -> ./xmake.lua:23
  313. -> -Wno-error=expansion-to-defined -> ./xmake.lua:23
  314. includedirs:
  315. -> src -> ./src/tbox/xmake.lua:26
  316. -> build/macosx/x86_64/release -> ./src/tbox/xmake.lua:27
  317. headerfiles:
  318. -> src/(tbox/**.h)|**/impl/**.h -> ./src/tbox/xmake.lua:30
  319. -> src/(tbox/prefix/**/prefix.S) -> ./src/tbox/xmake.lua:31
  320. -> src/(tbox/math/impl/*.h) -> ./src/tbox/xmake.lua:32
  321. -> src/(tbox/utils/impl/*.h) -> ./src/tbox/xmake.lua:33
  322. -> build/macosx/x86_64/release/tbox.config.h -> ./src/tbox/xmake.lua:34
  323. files:
  324. -> src/tbox/*.c -> ./src/tbox/xmake.lua:56
  325. -> src/tbox/hash/bkdr.c -> ./src/tbox/xmake.lua:57
  326. -> src/tbox/hash/fnv32.c -> ./src/tbox/xmake.lua:57
  327. -> src/tbox/hash/adler32.c -> ./src/tbox/xmake.lua:57
  328. -> src/tbox/math/**.c -> ./src/tbox/xmake.lua:58
  329. -> src/tbox/libc/**.c|string/impl/**.c -> ./src/tbox/xmake.lua:59
  330. -> src/tbox/utils/*.c|option.c -> ./src/tbox/xmake.lua:60
  331. -> src/tbox/prefix/**.c -> ./src/tbox/xmake.lua:61
  332. -> src/tbox/memory/**.c -> ./src/tbox/xmake.lua:62
  333. -> src/tbox/string/**.c -> ./src/tbox/xmake.lua:63
  334. -> src/tbox/stream/**.c|**/charset.c|**/zip.c -> ./src/tbox/xmake.lua:64
  335. -> src/tbox/network/**.c|impl/ssl/*.c -> ./src/tbox/xmake.lua:65
  336. -> src/tbox/algorithm/**.c -> ./src/tbox/xmake.lua:66
  337. -> src/tbox/container/**.c|element/obj.c -> ./src/tbox/xmake.lua:67
  338. -> src/tbox/libm/impl/libm.c -> ./src/tbox/xmake.lua:68
  339. -> src/tbox/libm/idivi8.c -> ./src/tbox/xmake.lua:73
  340. -> src/tbox/libm/ilog2i.c -> ./src/tbox/xmake.lua:70
  341. -> src/tbox/libm/isqrti.c -> ./src/tbox/xmake.lua:71
  342. -> src/tbox/libm/isqrti64.c -> ./src/tbox/xmake.lua:72
  343. -> src/tbox/platform/*.c|context.c|exception.c -> ./src/tbox/xmake.lua:74
  344. -> src/tbox/platform/impl/*.c|charset.c|poller_fwatcher.c -> ./src/tbox/xmake.lua:74
  345. -> src/tbox/libm/*.c -> ./src/tbox/xmake.lua:77
  346. compiler (cc): /usr/bin/xcrun -sdk macosx clang
  347. -> -Qunused-arguments -target x86_64-apple-macos12.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk
  348. linker (ar): /usr/bin/xcrun -sdk macosx ar
  349. -> -cr
  350. compflags (cc):
  351. -> -Qunused-arguments -target x86_64-apple-macos12.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -Wall -Werror -Oz -std=c99 -Isrc -Ibuild/macosx/x86_64/release -D__tb_small__ -D__tb_prefix__=\"tbox\" -D_GNU_SOURCE=1 -framework CoreFoundation -framework CoreServices -Wno-error=deprecated-declarations -fno-strict-aliasing -Wno-error=expansion-to-defined -fno-stack-protector
  352. linkflags (ar):
  353. -> -cr
  354. </code></pre>
  355. <h3 id="showbuiltincompilationmodeslist">Show builtin compilation modes list</h3>
  356. <pre><code class="lang-bash">$ xmake show -l buildmodes
  357. </code></pre>
  358. <h3 id="showbuiltincompilationruleslist">Show builtin compilation rules list</h3>
  359. <pre><code class="lang-bash">$ xmake show -l rules
  360. </code></pre>
  361. <h3 id="showotherinformation">Show other information</h3>
  362. <p>It is still being perfected, see: <a href="https://github.com/xmake-io/xmake/issues/798">https://github.com/xmake-io/xmake/issues/798</a></p>
  363. <p>Or run</p>
  364. <pre><code class="lang-bash">$ xmake show --help
  365. </code></pre>
  366. <h2 id="watchingforfileupdates">Watching for file updates</h2>
  367. <p>New in v2.7.1 is the <code>xmake watch</code> plugin command, which can automatically monitor project files for updates and then trigger an automatic build or run some custom commands.</p>
  368. <p>This is often used for personal development to enable fast, real-time incremental builds without the need to manually execute the build command each time, improving development efficiency.</p>
  369. <h3 id="buildautomaticallyafteraprojectupdate">Build automatically after a project update</h3>
  370. <p>The default behaviour is to monitor the entire project root directory and any file changes will trigger an incremental build of the project.</p>
  371. <pre><code class="lang-bash">$ xmake watch
  372. watching /private/tmp/test/src/** .
  373. watching /private/tmp/test/* ...
  374. /private/tmp/test/src/main.cpp modified
  375. [ 25%]: cache compiling.release src/main.cpp
  376. [ 50%]: linking.release test
  377. [ 100%]: build ok!
  378. ```&#39;&#39;
  379. ### Monitoring a specific directory
  380. We can also monitor specific code directories to narrow down the scope of monitoring and improve performance.
  381. ```bash
  382. $ xmake watch -d src
  383. $ xmake watch -d "src;tests/*"
  384. </code></pre>
  385. <p>The above command will recursively watch all subdirectories. If you want to keep a tight watch on the files in the current directory and not do recursive monitoring, you can use the following command.</p>
  386. <pre><code class="lang-bash">$ xmake watch -p src
  387. $ xmake watch -p "src;tests/*"
  388. </code></pre>
  389. <h3 id="watchandrunthespecifiedcommand">Watch and run the specified command</h3>
  390. <p>If you want to run the build automatically even after the automatic build, we can use a custom command set.</p>
  391. <pre><code class="lang-bash">$ xmake watch -c "xmake; xmake run"
  392. </code></pre>
  393. <p>The above list of commands is passed as a string, which is not flexible enough for complex command arguments that need to be escaped rather tediously, so we can use the following for arbitrary commands.</p>
  394. <pre><code class="lang-bash">$ xmake watch -- echo hello xmake!
  395. $ xmake watch -- xmake run --help
  396. </code></pre>
  397. <h3 id="watchingandrunningthetargetprogram">Watching and running the target program</h3>
  398. <p>Although we can automate the running of the target program with custom commands, we also provide more convenient arguments to achieve this behaviour.</p>
  399. <pre><code class="lang-bash">$ xmake watch -r
  400. $ xmake watch --run
  401. [100%]: build ok!
  402. hello world!
  403. </code></pre>
  404. <h3 id="watchingandrunningluascripts">Watching and running lua scripts</h3>
  405. <p>We can also watch for file updates and then run the specified lua script for more flexible and complex command customisation.</p>
  406. <pre><code class="lang-bash">$ xmake watch -s /tmp/test.lua
  407. </code></pre>
  408. <p>We can also get a list of all updated file paths and events in the script again.</p>
  409. <pre><code class="lang-lua">function main(events)
  410. -- TODO handle events
  411. end
  412. </code></pre>
  413. <h2 id="checkprojectconfigurationsandcodes">Check project configurations and codes</h2>
  414. <h3 id="checkprojectconfiguration">Check project configuration</h3>
  415. <h4 id="checkallapivaluesinxmakeluabydefault">Check all api values in xmake.lua by default</h4>
  416. <pre><code class="lang-lua">set_lanuages("c91") -- typo
  417. </code></pre>
  418. <pre><code class="lang-console">$ xmake check
  419. ./xmake.lua:15: warning: unknown language value &#39;c91&#39;, it may be &#39;c90&#39;
  420. 0 notes, 1 warnings, 0 errors
  421. </code></pre>
  422. <p>we can also run a given group</p>
  423. <pre><code class="lang-console">$ xmake check api
  424. $ xmake check api.target
  425. </code></pre>
  426. <h4 id="verboseoutput">Verbose output</h4>
  427. <pre><code class="lang-console">$ xmake check -v
  428. ./xmake.lua:15: warning: unknown language value &#39;cxx91&#39;, it may be &#39;cxx98&#39;
  429. ./src/tbox/xmake.lua:43: note: unknown package value &#39;mbedtls&#39;
  430. ./src/tbox/xmake.lua:43: note: unknown package value &#39;polarssl&#39;
  431. ./src/tbox/xmake.lua:43: note: unknown package value &#39;openssl&#39;
  432. ./src/tbox/xmake.lua:43: note: unknown package value &#39;pcre2&#39;
  433. ./src/tbox/xmake.lua:43: note: unknown package value &#39;pcre&#39;
  434. ./src/tbox/xmake.lua:43: note: unknown package value &#39;zlib&#39;
  435. ./src/tbox/xmake.lua:43: note: unknown package value &#39;mysql&#39;
  436. ./src/tbox/xmake.lua:43: note: unknown package value &#39;sqlite3&#39;
  437. 8 notes, 1 warnings, 0 errors
  438. </code></pre>
  439. <h4 id="checkthegivenapi">Check the given api</h4>
  440. <pre><code class="lang-console">$ xmake check api.target.languages
  441. ./xmake.lua:15: warning: unknown language value &#39;cxx91&#39;, it may be &#39;cxx98&#39;
  442. 0 notes, 1 warnings, 0 errors
  443. </code></pre>
  444. <h4 id="checkcompilerflags">Check compiler flags</h4>
  445. <pre><code class="lang-console">$ xmake check
  446. ./xmake.lua:10: warning: clang: unknown c compiler flag &#39;-Ox&#39;
  447. 0 notes, 1 warnings, 0 errors
  448. </code></pre>
  449. <h4 id="checkincludedirs">Check includedirs</h4>
  450. <pre><code class="lang-console">$ xmake check
  451. ./xmake.lua:11: warning: includedir &#39;xxx&#39; not found
  452. 0 notes, 1 warnings, 0 errors
  453. </code></pre>
  454. <h3 id="checkprojectcodeclangtidy">Check project code (clang-tidy)</h3>
  455. <h4 id="listclangtidychecks">List clang-tidy checks</h4>
  456. <pre><code class="lang-console">$ xmake check clang.tidy --list
  457. Enabled checks:
  458. clang-analyzer-apiModeling.StdCLibraryFunctions
  459. clang-analyzer-apiModeling.TrustNonnull
  460. clang-analyzer-apiModeling.google.GTest
  461. clang-analyzer-apiModeling.llvm.CastValue
  462. clang-analyzer-apiModeling.llvm.ReturnValue
  463. ...
  464. </code></pre>
  465. <h4 id="checksourcecodeintargets">Check source code in targets</h4>
  466. <pre><code class="lang-console">$ xmake check clang.tidy
  467. 1 error generated.
  468. Error while processing /private/tmp/test2/src/main.cpp.
  469. /tmp/test2/src/main.cpp:1:10: error: &#39;iostr&#39; file not found [clang-diagnostic-error]
  470. #include <iostr>
  471. ^~~~~~~
  472. Found compiler error(s).
  473. error: execv(/usr/local/opt/llvm/bin/clang-tidy -p compile_commands.json /private/tmp/test2/src
  474. /main.cpp) failed(1)
  475. </code></pre>
  476. <h4 id="checkcodewiththegivenchecks">Check code with the given checks</h4>
  477. <pre><code class="lang-console">$ xmake check clang.tidy --checks="*"
  478. 6 warnings and 1 error generated.
  479. Error while processing /private/tmp/test2/src/main.cpp.
  480. /tmp/test2/src/main.cpp:1:10: error: &#39;iostr&#39; file not found [clang-diagnostic-error]
  481. #include <iostr>
  482. ^~~~~~~
  483. /tmp/test2/src/main.cpp:3:1: warning: do not use namespace using-directives; use using-declarat
  484. ions instead [google-build-using-namespace]
  485. using namespace std;
  486. ^
  487. /tmp/test2/src/main.cpp:3:17: warning: declaration must be declared within the &#39;__llvm_libc&#39; na
  488. mespace [llvmlibc-implementation-in-namespace]
  489. using namespace std;
  490. ^
  491. /tmp/test2/src/main.cpp:5:5: warning: declaration must be declared within the &#39;__llvm_libc&#39; nam
  492. espace [llvmlibc-implementation-in-namespace]
  493. int main(int argc, char **argv) {
  494. ^
  495. /tmp/test2/src/main.cpp:5:5: warning: use a trailing return type for this function [modernize-u
  496. se-trailing-return-type]
  497. int main(int argc, char **argv) {
  498. ~~~ ^
  499. auto -> int
  500. /tmp/test2/src/main.cpp:5:14: warning: parameter &#39;argc&#39; is unused [misc-unused-parameters]
  501. int main(int argc, char **argv) {
  502. ^~~~
  503. /*argc*/
  504. /tmp/test2/src/main.cpp:5:27: warning: parameter &#39;argv&#39; is unused [misc-unused-parameters]
  505. int main(int argc, char **argv) {
  506. ^~~~
  507. /*argv*/
  508. Found compiler error(s).
  509. error: execv(/usr/local/opt/llvm/bin/clang-tidy --checks=* -p compile_commands.json /private/tm
  510. p/test2/src/main.cpp) failed(1)
  511. </code></pre>
  512. <h4 id="checkcodewiththegiventargetname">Check code with the given target name</h4>
  513. <pre><code class="lang-console">$ xmake check clang.tidy [targetname]
  514. </code></pre>
  515. <h4 id="checkcodewiththegivensourcefiles">Check code with the given source files</h4>
  516. <pre><code class="lang-console">$ xmake check clang.tidy -f src/main.c
  517. $ xmake check clang.tidy -f &#39;src/*.c:src/**.cpp&#39;
  518. </code></pre>
  519. <h4 id="setthegivenclangtidyconfigfile">Set the given .clang-tidy config file</h4>
  520. <pre><code class="lang-console">$ xmake check clang.tidy --configfile=/tmp/.clang-tidy
  521. </code></pre>
  522. <h4 id="createanewclangtidyconfigfile">Create a new .clang-tidy config file</h4>
  523. <pre><code class="lang-console">$ xmake check clang.tidy --checks="*" --create
  524. $ cat .clang-tidy
  525. ---
  526. Checks: &#39;clang-diagnostic-*,clang-analyzer-*,*&#39;
  527. WarningsAsErrors: &#39;&#39;
  528. HeaderFilterRegex: &#39;&#39;
  529. AnalyzeTemporaryDtors: false
  530. FormatStyle: none
  531. User: ruki
  532. CheckOptions:
  533. - key: readability-suspicious-call-argument.PrefixSimilarAbove
  534. value: &#39;30&#39;
  535. - key: cppcoreguidelines-no-malloc.Reallocations
  536. value: &#39;::realloc&#39;
  537. </code></pre>
  538. <h4 id="automaticallyfixingerrorcodes">Automatically fixing error codes</h4>
  539. <p>We can use the following command parameters to automatically fix problematic code detected by clang tidy.</p>
  540. <pre><code class="lang-console">$ xmake check clang.tidy --fix
  541. $ xmake check clang.tidy --fix_errors
  542. $ xmake check clang.tidy --fix_notes
  543. </code></pre>
  544. <h2 id="generateinstallationpackagexpack">Generate installation package (XPack)</h2>
  545. <h3 id="introduction">Introduction</h3>
  546. <p>This plug-in can help users quickly generate installation packages and source code packages for different platforms. It will generate the following installation package formats:</p>
  547. <ul>
  548. <li>Windows NSIS binary installation package</li>
  549. <li>Windows Wix binary installation package</li>
  550. <li>runself (shell) self-compile installation package</li>
  551. <li>zip/tar.gz binary package</li>
  552. <li>zip/tar.gz source package</li>
  553. <li>RPM binary installation package</li>
  554. <li>SRPM source code installation package</li>
  555. <li>DEB binary installation package</li>
  556. </ul>
  557. <p>Here is a complete example, we can take a brief look at it first:</p>
  558. <pre><code class="lang-lua">set_version("1.0.0")
  559. add_rules("mode.debug", "mode.release")
  560. includes("@builtin/xpack")
  561. target("test")
  562. set_kind("binary")
  563. add_files("src/*.cpp")
  564. xpack("test")
  565. set_formats("nsis", "zip", "targz", "runself")
  566. set_title("hello")
  567. set_author("ruki")
  568. set_description("A test installer.")
  569. set_homepage("https://xmake.io")
  570. set_licensefile("LICENSE.md")
  571. add_targets("test")
  572. add_installfiles("src/(assets/*.png)", {prefixdir = "images"})
  573. add_sourcefiles("(src/**)")
  574. set_iconfile("src/assets/xmake.ico")
  575. after_installcmd(function (package, batchcmds)
  576. batchcmds:mkdir(package:installdir("resources"))
  577. batchcmds:cp("src/assets/*.txt", package:installdir("resources"), {rootdir = "src"})
  578. batchcmds:mkdir(package:installdir("stub"))
  579. end)
  580. after_uninstallcmd(function (package, batchcmds)
  581. batchcmds:rmdir(package:installdir("resources"))
  582. batchcmds:rmdir(package:installdir("stub"))
  583. end)
  584. </code></pre>
  585. <p>We introduce all configuration interfaces of xpack through <code>includes("@builtin/xpack")</code>, including the xpack configuration domain and all its domain interfaces.</p>
  586. <p>Then we execute:</p>
  587. <pre><code class="lang-bash">$xmakepack
  588. </code></pre>
  589. <p>All installation packages will be generated.</p>
  590. <h3 id="generatensisinstallationpackage">Generate NSIS installation package</h3>
  591. <p>As long as you configure the <code>set_formats("nsis")</code> format and then execute the <code>xmake pack</code> command, you can generate an installation package in NSIS format.</p>
  592. <p>In addition, xmake will also automatically install the tools required to generate NSIS packages to achieve true one-click packaging.</p>
  593. <pre><code class="lang-bash">$xmakepack
  594. note: install or modify (m) these packages (pass -y to skip confirm)?
  595. in xmake-repo:
  596. -> nsis 3.09
  597. please input: y (y/n/m)
  598. => install nsis 3.09 .. ok
  599. [25%]: compiling.release src\main.cpp
  600. [37%]: compiling.release src\main.cpp
  601. [50%]: linking.release foo.dll
  602. [62%]: linking.release test.exe
  603. packing build\xpack\test\test-windows-x64-v1.0.0.exe
  604. pack ok
  605. </code></pre>
  606. <p><code>test-windows-x64-v1.0.0.exe</code> is the installation package we generated. Double-click to run it to install our binary files to the specified directory.</p>
  607. <p><img src="/assets/img/manual/nsis_1.png" alt=""><br><img src="/assets/img/manual/nsis_2.png" alt=""><br><img src="/assets/img/manual/nsis_3.png" alt=""></p>
  608. <h4 id="addcomponentinstallation">Add component installation</h4>
  609. <p>We can also add component installation commands to NSIS. Only when the user selects the specified component, its installation command will be executed.</p>
  610. <pre><code class="lang-lua">xpack("test")
  611. add_components("LongPath")
  612. xpack_component("LongPath")
  613. set_default(false)
  614. set_title("Enable Long Path")
  615. set_description("Increases the maximum path length limit, up to 32,767 characters (before 256).")
  616. on_installcmd(function (component, batchcmds)
  617. batchcmds:rawcmd("nsis", [[
  618. ${If} $NoAdmin == "false"
  619. ; Enable long path
  620. WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1
  621. ${EndIf}]])
  622. end)
  623. </code></pre>
  624. <p>In this example, we added an NSIS-specific custom command to support long paths.</p>
  625. <p><img src="/assets/img/manual/nsis_4.png" alt=""></p>
  626. <h3 id="generateselfinstallationpackage">Generate self-installation package</h3>
  627. <p>We can also generate self-compiled installation packages based on shell scripts. We need to configure the runself packaging format, and then add the source files that need to participate in compilation and installation through <code>add_sourcefiles</code>.</p>
  628. <p>Next, we need to customize the on_installcmd installation script to configure if we compile the source code package, we can simply call a built-in compilation and installation script file, or directly configure compilation and installation commands such as <code>make install</code>.</p>
  629. <p>For example:</p>
  630. <pre><code class="lang-lua">xpack("test")
  631. set_formats("runself")
  632. add_sourcefiles("(src/**)")
  633. on_installcmd(function (package, batchcmds)
  634. batchcmds:runv("make", {"install"})
  635. end)
  636. </code></pre>
  637. <p>Then, we execute the <code>xmake pack</code> command to generate a self-installed xxx.gz.run package, which uses gzip compression by default.</p>
  638. <pre><code class="lang-bash">$xmakepack
  639. packing build/xpack/test/test-macosx-src-v1.0.0.gz.run
  640. pack ok
  641. </code></pre>
  642. <p>We can use sh to load and run it to install our program.</p>
  643. <pre><code class="lang-bash">$ sh ./build/xpack/test/test-macosx-src-v1.0.0.gz.run
  644. </code></pre>
  645. <p>We can also look at a more complete example:</p>
  646. <pre><code class="lang-lua">xpack("xmakesrc")
  647. set_formats("runself")
  648. set_basename("xmake-v$(version)")
  649. set_prefixdir("xmake-$(version)")
  650. before_package(function (package)
  651. import("devel.git")
  652. local rootdir = path.join(os.tmpfile(package:basename()) .. ".dir", "repo")
  653. if not os.isdir(rootdir) then
  654. os.tryrm(rootdir)
  655. os.cp(path.directory(os.projectdir()), rootdir)
  656. git.clean({repodir = rootdir, force = true, all = true})
  657. git.reset({repodir = rootdir, hard = true})
  658. if os.isfile(path.join(rootdir, ".gitmodules")) then
  659. git.submodule.clean({repodir = rootdir, force = true, all = true})
  660. git.submodule.reset({repodir = rootdir, hard = true})
  661. end
  662. end
  663. local extraconf = {rootdir = rootdir}
  664. package:add("sourcefiles", path.join(rootdir, "core/**|src/pdcurses/**|src/luajit/**|src/tbox/tbox/src/demo/**"), extraconf )
  665. package:add("sourcefiles", path.join(rootdir, "xmake/**"), extraconf)
  666. package:add("sourcefiles", path.join(rootdir, "*.md"), extraconf)
  667. package:add("sourcefiles", path.join(rootdir, "configure"), extraconf)
  668. package:add("sourcefiles", path.join(rootdir, "scripts/*.sh"), extraconf)
  669. package:add("sourcefiles", path.join(rootdir, "scripts/man/**"), extraconf)
  670. package:add("sourcefiles", path.join(rootdir, "scripts/debian/**"), extraconf)
  671. package:add("sourcefiles", path.join(rootdir, "scripts/msys/**"), extraconf)
  672. end)
  673. on_installcmd(function (package, batchcmds)
  674. batchcmds:runv("./scripts/get.sh", {"__local__"})
  675. end)
  676. </code></pre>
  677. <p>It is the installation package configuration script of xmake&#39;s own source code, which is more complete.</p>
  678. <p>For configuration, please refer to: <a href="https://github.com/xmake-io/xmake/blob/master/core/xpack.lua">xpack.lua</a></p>
  679. <p>Here, it performs compilation and installation by calling the <code>./scripts/get.sh</code> installation script built into the source package.</p>
  680. <h3 id="generatesourcecodearchivepackage">Generate source code archive package</h3>
  681. <p>In addition, we can also configure the <code>srczip</code> and <code>srctargz</code> formats to generate source code compression packages. It is not a complete installation package and has no installation commands. It is only used for source code package distribution.</p>
  682. <pre><code class="lang-lua">xpack("test")
  683. set_formats("srczip", "srctargz")
  684. add_sourcefiles("(src/**)")
  685. </code></pre>
  686. <pre><code class="lang-bash">$xmakepack
  687. packing build/xpack/test/test-macosx-src-v1.0.0.zip ..
  688. packing build/xpack/test/test-macosx-src-v1.0.0.tar.gz ..
  689. pack ok
  690. </code></pre>
  691. <h3 id="generatebinaryarchivepackage">Generate binary archive package</h3>
  692. <p>We can also configure <code>zip</code> and <code>targz</code> to generate binary compressed packages. It will automatically compile all bound target target programs and package all required binary programs and library files into zip/tar.gz format.</p>
  693. <p>This is usually used to create a green version of the installation package. There is no automatic installation script inside. Users need to set environment variables such as PATH themselves.</p>
  694. <pre><code class="lang-lua">xpack("test")
  695. set_formats("zip", "targz")
  696. add_installfiles("(src/**)")
  697. </code></pre>
  698. <pre><code class="lang-bash">$xmakepack
  699. packing build/xpack/test/test-macosx-v1.0.0.zip ..
  700. packing build/xpack/test/test-macosx-v1.0.0.tar.gz ..
  701. pack ok
  702. </code></pre>
  703. <p>!> It should be noted that to add binary files to the package, use <code>add_installfiles</code> instead of <code>add_sourcefiles</code>.</p>
  704. <p>We can also use <code>add_targets</code> to bind the target target programs and libraries that need to be installed. See the interface description for <code>add_targets</code> below for more details.</p>
  705. <h3 id="generatesrpmsourcecodeinstallationpackage">Generate SRPM source code installation package</h3>
  706. <p>It can generate source code installation packages in <code>.src.rpm</code> format.</p>
  707. <p>We can configure add_targets to associate the targets that need to be built. In the generated srpm package, it will automatically call <code>xmake build</code> and <code>xmake install</code> to build and install the package.</p>
  708. <pre><code class="lang-lua">xpack("test")
  709. set_homepage("https://xmake.io")
  710. set_license("Apache-2.0")
  711. set_description("A cross-platform build utility based on Lua.")
  712. set_formats("srpm")
  713. add_sourcefiles("(src/**)")
  714. add_sourcefiles("./xmake.lua")
  715. add_targets("demo")
  716. </code></pre>
  717. <p>It will generate a spec file similar to the following, and then automatically call rpmbuild to generate the <code>.src.rpm</code> package.</p>
  718. <pre><code>Name: test
  719. Version: 1.0.0
  720. Release: 1%{?dist}
  721. Summary: hello
  722. License: Apache-2.0
  723. URL: https://xmake.io
  724. Source0: test-linux-src-v1.0.0.tar.gz
  725. BuildRequires: xmake
  726. BuildRequires: gcc
  727. BuildRequires: gcc-c++
  728. %description
  729. A test installer.
  730. %prep
  731. %autosetup -n test-1.0.0 -p1
  732. %build
  733. xmake build -y test
  734. %install
  735. xmake install -o %{buildroot}/%{_exec_prefix} test
  736. cd %{buildroot}
  737. find . -type f | sed &#39;s!^\./!/!&#39; > %{_builddir}/_installedfiles.txt
  738. %check
  739. %files -f %{_builddir}/_installedfiles.txt
  740. %changelog
  741. * Fri Dec 22 2023 ruki - 1.0.0-1
  742. - Update to 1.0.0
  743. </code></pre><p>We can also customize build and installation scripts through <code>on_buildcmd</code> and <code>on_installcmd</code>.</p>
  744. <pre><code class="lang-lua">xpack("test")
  745. set_homepage("https://xmake.io")
  746. set_license("Apache-2.0")
  747. set_description("A cross-platform build utility based on Lua.")
  748. set_formats("srpm")
  749. add_sourcefiles("(src/**)")
  750. add_sourcefiles("./configure")
  751. on_buildcmd(function (package, batchcmds)
  752. batchcmds:runv("./configure")
  753. batchcmds:runv("make")
  754. end)
  755. on_installcmd(function (package, batchcmds)
  756. batchcmds:runv("make", {"install", "PREFIX=%{buildroot}"})
  757. end)
  758. </code></pre>
  759. <h3 id="generaterpmbinaryinstallationpackage">Generate RPM binary installation package</h3>
  760. <p>The RPM package will directly generate a compiled binary installation package. xmake will automatically call the <code>rpmbuild --rebuild</code> command to build the SRPM package and generate it.</p>
  761. <p>In XPack, we only need to configure <code>set_formats("rpm")</code> to support rpm package generation, and other configurations are exactly the same as srpm packages.</p>
  762. <pre><code class="lang-lua">xpack("test")
  763. set_formats("rpm")
  764. -- TODO
  765. </code></pre>
  766. <h3 id="packagingcommand">Packaging command</h3>
  767. <h4 id="specifypackagingformat">Specify packaging format</h4>
  768. <p>If we have configured multiple packaging formats using <code>set_formats</code> in the configuration file, then <code>xmake pack</code> will automatically generate packages for all these formats by default.</p>
  769. <p>Of course, we can also use <code>xmake pack --formats=nsis,targz</code> to selectively specify which formats of packages currently need to be packaged.</p>
  770. <h4 id="modifythepackagefilename">Modify the package file name</h4>
  771. <p>We can modify the package name through <code>set_basename()</code> in the configuration file, or we can modify it through the command line.</p>
  772. <pre><code class="lang-bash">$ xmake pack --basename="foo"
  773. packing build/xpack/test/foo.zip ..
  774. pack ok
  775. </code></pre>
  776. <h4 id="specifyoutputdirectory">Specify output directory</h4>
  777. <p>The default output directory is in the build directory, but we can also modify the output path.</p>
  778. <pre><code class="lang-bash">$ xmake pack -o /tmp/output
  779. </code></pre>
  780. <h4 id="disableautomaticbuild">Disable automatic build</h4>
  781. <p>If you are building a binary package such as NSIS, <code>xmake pack</code> will automatically compile all bound target files first, and then execute the packaging logic.</p>
  782. <p>But if we have already compiled it and don&#39;t want to compile it every time, but package it directly, we can disable automatic building through the following parameters.</p>
  783. <pre><code class="lang-bash">$ xmake pack --autobuild=n
  784. </code></pre>
  785. <h3 id="interfacedescription">Interface description</h3>
  786. <p>For more descriptions of the XPack packaging interface, see: <a href="https://xmake.io/#/manual/xpack">XPack Packaging Interface Document</a>.</p>
  787. <h2 id="macrosrecordingandplayback">Macros Recording and Playback</h2>
  788. <h3 id="introduction">Introduction</h3>
  789. <p>We can record and playback our xmake commands and save as macro quickly using this plugin.</p>
  790. <p>And we can run this macro to simplify our jobs repeatably.</p>
  791. <h3 id="recordcommands">Record Commands</h3>
  792. <pre><code class="lang-bash"># begin to record commands
  793. $ xmake macro --begin
  794. # run some xmake commands
  795. $ xmake f -p android --ndk=/xxx/ndk -a arm64-v8a
  796. $ xmake p
  797. $ xmake f -p mingw --sdk=/mingwsdk
  798. $ xmake p
  799. $ xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin
  800. $ xmake p
  801. $ xmake f -p iphoneos -a armv7
  802. $ xmake p
  803. $ xmake f -p iphoneos -a arm64
  804. $ xmake p
  805. $ xmake f -p iphoneos -a armv7s
  806. $ xmake p
  807. $ xmake f -p iphoneos -a i386
  808. $ xmake p
  809. $ xmake f -p iphoneos -a x86_64
  810. $ xmake p
  811. # stop to record and save as anonymous macro
  812. xmake macro --end
  813. </code></pre>
  814. <h3 id="playbackmacro">Playback Macro</h3>
  815. <pre><code class="lang-bash"># playback the previous anonymous macro
  816. $ xmake macro .
  817. </code></pre>
  818. <h3 id="namedmacro">Named Macro</h3>
  819. <pre><code class="lang-bash">$ xmake macro --begin
  820. $ ...
  821. $ xmake macro --end macroname
  822. $ xmake macro macroname
  823. </code></pre>
  824. <h3 id="importandexportmacro">Import and Export Macro</h3>
  825. <p>Import the given macro file or directory.</p>
  826. <pre><code class="lang-bash">$ xmake macro --import=/xxx/macro.lua macroname
  827. $ xmake macro --import=/xxx/macrodir
  828. </code></pre>
  829. <p>Export the given macro to file or directory.</p>
  830. <pre><code class="lang-bash">$ xmake macro --export=/xxx/macro.lua macroname
  831. $ xmake macro --export=/xxx/macrodir
  832. </code></pre>
  833. <h3 id="listandshowmacro">List and Show Macro</h3>
  834. <p>List all builtin macros.</p>
  835. <pre><code class="lang-bash">$ xmake macro --list
  836. </code></pre>
  837. <p>Show the given macro script content.</p>
  838. <pre><code class="lang-bash">$ xmake macro --show macroname
  839. </code></pre>
  840. <h3 id="custommacroscript">Custom Macro Script</h3>
  841. <p>Create and write a <code>macro.lua</code> script first.</p>
  842. <pre><code class="lang-lua">function main()
  843. os.exec("xmake f -p android --ndk=/xxx/ndk -a arm64-v8a")
  844. os.exec("xmake p")
  845. os.exec("xmake f -p mingw --sdk=/mingwsdk")
  846. os.exec("xmake p")
  847. os.exec("xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin")
  848. os.exec("xmake p")
  849. os.exec("xmake f -p iphoneos -a armv7")
  850. os.exec("xmake p")
  851. os.exec("xmake f -p iphoneos -a arm64")
  852. os.exec("xmake p")
  853. os.exec("xmake f -p iphoneos -a armv7s")
  854. os.exec("xmake p")
  855. os.exec("xmake f -p iphoneos -a i386")
  856. os.exec("xmake p")
  857. os.exec("xmake f -p iphoneos -a x86_64")
  858. os.exec("xmake p")
  859. end
  860. </code></pre>
  861. <p>Import this macro script to xmake.</p>
  862. <pre><code class="lang-bash">$ xmake macro --import=/xxx/macro.lua [macroname]
  863. </code></pre>
  864. <p>Playback this macro script.</p>
  865. <pre><code class="lang-bash">$ xmake macro [.|macroname]
  866. </code></pre>
  867. <h3 id="builtinmacros">Builtin Macros</h3>
  868. <p>XMake supports some builtins macros to simplify our jobs.</p>
  869. <p>For example, we use <code>package</code> macro to package all architectures of the iphoneos platform just for once.</p>
  870. <pre><code class="lang-bash">$ xmake macro package -p iphoneos
  871. </code></pre>
  872. <h3 id="advancemacroscript">Advance Macro Script</h3>
  873. <p>Let&#39;s see the <code>package</code> macro script:</p>
  874. <pre><code class="lang-lua">-- imports
  875. import("core.base.option")
  876. import("core.project.config")
  877. import("core.project.project")
  878. import("core.platform.platform")
  879. -- the options
  880. local options =
  881. {
  882. {&#39;p&#39;, "plat", "kv", os.host(), "Set the platform." }
  883. , {&#39;f&#39;, "config", "kv", nil, "Pass the config arguments to \"xmake config\" .." }
  884. , {&#39;o&#39;, "outputdir", "kv", nil, "Set the output directory of the package." }
  885. }
  886. -- package all
  887. --
  888. -- .e.g
  889. -- xmake m package
  890. -- xmake m package -f "-m debug"
  891. -- xmake m package -p linux
  892. -- xmake m package -p iphoneos -f "-m debug --xxx ..." -o /tmp/xxx
  893. -- xmake m package -f \"--mode=debug\"
  894. --
  895. function main(argv)
  896. -- parse arguments
  897. local args = option.parse(argv, options, "Package all architectures for the given the platform."
  898. , ""
  899. , "Usage: xmake macro package [options]")
  900. -- package all archs
  901. local plat = args.plat
  902. for _, arch in ipairs(platform.archs(plat)) do
  903. -- config it
  904. os.exec("xmake f -p %s -a %s %s -c %s", plat, arch, args.config or "", (option.get("verbose") and "-v" or ""))
  905. -- package it
  906. if args.outputdir then
  907. os.exec("xmake p -o %s %s", args.outputdir, (option.get("verbose") and "-v" or ""))
  908. else
  909. os.exec("xmake p %s", (option.get("verbose") and "-v" or ""))
  910. end
  911. end
  912. -- package universal for iphoneos, watchos ...
  913. if plat == "iphoneos" or plat == "watchos" then
  914. -- load configure
  915. config.load()
  916. -- load project
  917. project.load()
  918. -- enter the project directory
  919. os.cd(project.directory())
  920. -- the outputdir directory
  921. local outputdir = args.outputdir or config.get("buildir")
  922. -- package all targets
  923. for _, target in pairs(project.targets()) do
  924. -- get all modes
  925. local modedirs = os.match(format("%s/%s.pkg/lib/*", outputdir, target:name()), true)
  926. for _, modedir in ipairs(modedirs) do
  927. -- get mode
  928. local mode = path.basename(modedir)
  929. -- make lipo arguments
  930. local lipoargs = nil
  931. for _, arch in ipairs(platform.archs(plat)) do
  932. local archfile = format("%s/%s.pkg/lib/%s/%s/%s/%s", outputdir, target:name(), mode, plat, arch, path.filename(target:targetfile()))
  933. if os.isfile(archfile) then
  934. lipoargs = format("%s -arch %s %s", lipoargs or "", arch, archfile)
  935. end
  936. end
  937. if lipoargs then
  938. -- make full lipo arguments
  939. lipoargs = format("-create %s -output %s/%s.pkg/lib/%s/%s/universal/%s", lipoargs, outputdir, target:name(), mode, plat, path.filename(target:targetfile()))
  940. -- make universal directory
  941. os.mkdir(format("%s/%s.pkg/lib/%s/%s/universal", outputdir, target:name(), mode, plat))
  942. -- package all archs
  943. os.execv("xmake", {"l", "lipo", lipoargs})
  944. end
  945. end
  946. end
  947. end
  948. end
  949. </code></pre>
  950. <p><p class="tip"><br> If you want to known more options, please run: <code>xmake macro --help</code><br></p>
  951. </p>
  952. <h2 id="generatedoxygendocument">Generate Doxygen Document</h2>
  953. <p>Please ensure that the doxygen tool has been installed first.</p>
  954. <pre><code class="lang-bash">$ xmake doxygen
  955. </code></pre>
  956. </article>
  957. </body>
  958. </html>