custom_rule.html 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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/#/manual/custom_rule">https://xmake.io/#/manual/custom_rule</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. <p>After the 2.2.1 release, xmake not only natively supports the construction of multi-language files, but also allows users to implement complex unknown file builds by custom building rules.</p>
  86. <p>Custom build rules can have a set of file extensions associated to them using <code>set_extensions</code>.<br>Once these extensions are associated to the rule a later call to <code>add_files</code> will automatically use this custom rule.<br>Here is an example rule that will use Pandoc to convert markdown files added to a build target in to HTML files:</p>
  87. <pre><code class="lang-lua">-- Define a build rule for a markdown file
  88. rule("markdown")
  89. set_extensions(".md", ".markdown")
  90. on_build_file(function (target, sourcefile, opt)
  91. import("core.project.depend")
  92. import("utils.progress") -- it only for v2.5.9, we need use print to show progress below v2.5.8
  93. -- make sure build directory exists
  94. os.mkdir(target:targetdir())
  95. -- replace .md with .html
  96. local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".html")
  97. -- only rebuild the file if its changed since last run
  98. depend.on_changed(function ()
  99. -- call pandoc to make a standalone html file from a markdown file
  100. os.vrunv(&#39;pandoc&#39;, {"-s", "-f", "markdown", "-t", "html", "-o", targetfile, sourcefile})
  101. progress.show(opt.progress, "${color.build.object}markdown %s", sourcefile)
  102. end, {files = sourcefile})
  103. end)
  104. target("test")
  105. set_kind("object")
  106. -- make the test target support the construction rules of the markdown file
  107. add_rules("markdown")
  108. -- adding a markdown file to build
  109. add_files("src/*.md")
  110. add_files("src/*.markdown")
  111. </code></pre>
  112. <p>Note that in xmake a rule is responsible for checking when targets are out of date and informing the user of ongoing progress.</p>
  113. <p>There is also an alternative to <code>on_build_file</code> in the form of <code>on_build_files</code> which allows you to process the entire set of files in one function call.</p>
  114. <p>A second form called <code>on_buildcmd_file</code> and <code>on_buildcmd_files</code> is instead declarative; rather than running arbitrary Lua to build a target it runs Lua to learn how those targets are built.<br>The advantage to <code>buildcmd</code> is that those rules can be exported to makefiles which do not require xmake at all in order to run.</p>
  115. <p>We can use buildcmd to simplify it further, like this:</p>
  116. <pre><code class="lang-lua">-- Define a build rule for a markdown file
  117. rule("markdown")
  118. set_extensions(".md", ".markdown")
  119. on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  120. -- make sure build directory exists
  121. batchcmds:mkdir(target:targetdir())
  122. -- replace .md with .html
  123. local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".html")
  124. -- call pandoc to make a standalone html file from a markdown file
  125. batchcmds:vrunv(&#39;pandoc&#39;, {"-s", "-f", "markdown", "-t", "html", "-o", targetfile, sourcefile})
  126. batchcmds:show_progress(opt.progress, "${color.build.object}markdown %s", sourcefile)
  127. -- only rebuild the file if its changed since last run
  128. batchcmds:add_depfiles(sourcefile)
  129. end)
  130. target("test")
  131. set_kind("object")
  132. -- make the test target support the construction rules of the markdown file
  133. add_rules("markdown")
  134. -- adding a markdown file to build
  135. add_files("src/*.md")
  136. add_files("src/*.markdown")
  137. </code></pre>
  138. <p>Files can be assigned to a specific rule regardless of their file extension. You do this by setting the <code>rule</code> custom property when adding the file like in the following example:</p>
  139. <pre><code class="lang-lua">target("test")
  140. add_files("src/test/*.md.in", {rule = "markdown"})
  141. </code></pre>
  142. <p>A target can be superimposed to apply multiple rules to more customize its own build behavior, and even support different build environments.</p>
  143. <p>!> Rules specified by <code>add_files("*.md", {rule = "markdown"})</code>, with a higher priority than the rule set by <code>add_rules("markdown")</code>.</p>
  144. <h3 id="builtinrules">Built-in rules</h3>
  145. <p>sinceAfter the 2.2.1 release, xmake provides some built-in rules to simplify the daily xmake.lua description and support for some common build environments.</p>
  146. <p>We can view the complete list of built-in rules by running the following command:</p>
  147. <pre><code class="lang-bash">$ xmake show -l rules
  148. </code></pre>
  149. <h4 id="modedebug">mode.debug</h4>
  150. <p>Add the configuration rules for the debug compilation mode for the current project xmake.lua, for example:</p>
  151. <pre><code class="lang-lua">add_rules("mode.debug")
  152. </code></pre>
  153. <p>Equivalent to:</p>
  154. <pre><code class="lang-lua">if is_mode("debug") then
  155. set_symbols("debug")
  156. set_optimize("none")
  157. end
  158. </code></pre>
  159. <p>We can switch to this compilation mode by <code>xmake f -m debug</code>.</p>
  160. <h4 id="moderelease">mode.release</h4>
  161. <p>Add the configuration rules for the release compilation mode for the current project xmake.lua, for example:</p>
  162. <pre><code class="lang-lua">add_rules("mode.release")
  163. </code></pre>
  164. <p>Equivalent to:</p>
  165. <pre><code class="lang-lua">if is_mode("release") then
  166. set_symbols("hidden")
  167. set_optimize("fastest")
  168. set_strip("all")
  169. end
  170. </code></pre>
  171. <p>We can switch to this compilation mode by <code>xmake f -m release</code>.</p>
  172. <h4 id="modereleasedbg">mode.releasedbg</h4>
  173. <p>Add the configuration rules for the releasedbg compilation mode for the current project xmake.lua, for example:</p>
  174. <pre><code class="lang-lua">add_rules("mode.releasedbg")
  175. </code></pre>
  176. <p>!> Compared with the release mode, this mode will also enable additional debugging symbols, which is usually very useful.</p>
  177. <p>Equivalent to:</p>
  178. <pre><code class="lang-lua">if is_mode("releasedbg") then
  179. set_symbols("debug")
  180. set_optimize("fastest")
  181. set_strip("all")
  182. end
  183. </code></pre>
  184. <p>We can switch to this compilation mode by <code>xmake f -m releasedbg</code>.</p>
  185. <h4 id="modeminsizerel">mode.minsizerel</h4>
  186. <p>Add the configuration rules for the minsizerel compilation mode for the current project xmake.lua, for example:</p>
  187. <pre><code class="lang-lua">add_rules("mode.minsizerel")
  188. </code></pre>
  189. <p>!> Compared with the release mode, this mode is more inclined to the minimum code compilation optimization, rather than speed priority.</p>
  190. <p>相当于:</p>
  191. <pre><code class="lang-lua">if is_mode("minsizerel") then
  192. set_symbols("hidden")
  193. set_optimize("smallest")
  194. set_strip("all")
  195. end
  196. </code></pre>
  197. <p>We can switch to this compilation mode by <code>xmake f -m minsizerel</code>.</p>
  198. <h4 id="modecheck">mode.check</h4>
  199. <p>Add the check compilation mode configuration rules for the current project xmake.lua, generally used for memory detection, for example:</p>
  200. <pre><code class="lang-lua">add_rules("mode.check")
  201. </code></pre>
  202. <p>Equivalent to:</p>
  203. <pre><code class="lang-lua">if is_mode("check") then
  204. set_symbols("debug")
  205. set_optimize("none")
  206. add_cxflags("-fsanitize=address", "-ftrapv")
  207. add_mxflags("-fsanitize=address", "-ftrapv")
  208. add_ldflags("-fsanitize=address")
  209. end
  210. </code></pre>
  211. <p>We can switch to this compilation mode by <code>xmake f -m check</code>.</p>
  212. <h4 id="modeprofile">mode.profile</h4>
  213. <p>Add configuration rules for the profile compilation mode for the current project xmake.lua, which is generally used for performance analysis, for example:</p>
  214. <pre><code class="lang-lua">add_rules("mode.profile")
  215. </code></pre>
  216. <p>Equivalent to:</p>
  217. <pre><code class="lang-lua">if is_mode("profile") then
  218. set_symbols("debug")
  219. add_cxflags("-pg")
  220. add_ldflags("-pg")
  221. end
  222. </code></pre>
  223. <p>We can switch to this compilation mode by <code>xmake f -m profile</code>.</p>
  224. <h4 id="modecoverage">mode.coverage</h4>
  225. <p>Add the configuration rules for the coverage compilation mode for the current project xmake.lua, which is generally used for coverage analysis, for example:</p>
  226. <pre><code class="lang-lua">add_rules("mode.coverage")
  227. </code></pre>
  228. <p>Equivalent to:</p>
  229. <pre><code class="lang-lua">if is_mode("coverage") then
  230. add_cxflags("--coverage")
  231. add_mxflags("--coverage")
  232. add_ldflags("--coverage")
  233. end
  234. </code></pre>
  235. <p>We can switch to this compilation mode by <code>xmake f -m coverage</code>.</p>
  236. <h4 id="modevalgrind">mode.valgrind</h4>
  237. <p>This mode provides valgrind memory analysis and detection support.</p>
  238. <pre><code class="lang-lua">add_rules("mode.valgrind")
  239. </code></pre>
  240. <p>We can switch to this compilation mode by: <code>xmake f -m valgrind</code>.</p>
  241. <h4 id="modeasan">mode.asan</h4>
  242. <p>This mode provides AddressSanitizer memory analysis and detection support.</p>
  243. <pre><code class="lang-lua">add_rules("mode.asan")
  244. </code></pre>
  245. <p>We can switch to this compilation mode by: <code>xmake f -m asan</code>.</p>
  246. <h4 id="modetsan">mode.tsan</h4>
  247. <p>This mode provides ThreadSanitizer memory analysis and detection support.</p>
  248. <pre><code class="lang-lua">add_rules("mode.tsan")
  249. </code></pre>
  250. <p>We can switch to this compilation mode by: <code>xmake f -m tsan</code>.</p>
  251. <h4 id="modelsan">mode.lsan</h4>
  252. <p>This mode provides LeakSanitizer memory analysis and detection support.</p>
  253. <pre><code class="lang-lua">add_rules("mode.lsan")
  254. </code></pre>
  255. <p>We can switch to this compilation mode by: <code>xmake f -m lsan</code>.</p>
  256. <h4 id="modeubsan">mode.ubsan</h4>
  257. <p>This mode provides UndefinedBehaviorSanitizer memory analysis and detection support.</p>
  258. <pre><code class="lang-lua">add_rules("mode.ubsan")
  259. </code></pre>
  260. <p>We can switch to this compilation mode by: <code>xmake f -m ubsan</code>.</p>
  261. <h4 id="qtstatic">qt.static</h4>
  262. <p>A static library program used to compile and generate Qt environments:</p>
  263. <pre><code class="lang-lua">target("test")
  264. add_rules("qt.static")
  265. add_files("src/*.cpp")
  266. add_frameworks("QtNetwork", "QtGui")
  267. </code></pre>
  268. <h4 id="qtshared">qt.shared</h4>
  269. <p>Dynamic library program for compiling and generating Qt environment:</p>
  270. <pre><code class="lang-lua">target("test")
  271. add_rules("qt.shared")
  272. add_files("src/*.cpp")
  273. add_frameworks("QtNetwork", "QtGui")
  274. </code></pre>
  275. <h4 id="qtconsole">qt.console</h4>
  276. <p>A console program for compiling and generating a Qt environment:</p>
  277. <pre><code class="lang-lua">target("test")
  278. add_rules("qt.console")
  279. add_files("src/*.cpp")
  280. </code></pre>
  281. <h4 id="qtquickapp">qt.quickapp</h4>
  282. <p>Quick(qml) ui application for compiling and generating Qt environment.</p>
  283. <pre><code class="lang-lua">target("test")
  284. add_rules("qt.quickapp")
  285. add_files("src/*.cpp")
  286. add_files("src/qml.qrc")
  287. </code></pre>
  288. <h4 id="qtquickapp_static">qt.quickapp_static</h4>
  289. <p>Quick(qml) ui application (statically linked version) for compiling and generating Qt environment.</p>
  290. <p>!> Need to switch to static library version Qt SDK</p>
  291. <pre><code class="lang-lua">target("test")
  292. add_rules("qt.quickapp_static")
  293. add_files("src/*.cpp")
  294. add_files("src/qml.qrc")
  295. </code></pre>
  296. <h4 id="qtwidgetapp">qt.widgetapp</h4>
  297. <p>Used to compile Qt Widgets (ui/moc) applications</p>
  298. <pre><code class="lang-lua">target("test")
  299. add_rules("qt.widgetapp")
  300. add_files("src/*.cpp")
  301. add_files("src/mainwindow.ui")
  302. add_files("src/mainwindow.h") -- add meta header files with Q_OBJECT
  303. </code></pre>
  304. <h4 id="qtwidgetapp_static">qt.widgetapp_static</h4>
  305. <p>Used to compile Qt Widgets (ui/moc) applications (static library version)</p>
  306. <p>!> Need to switch to static library version Qt SDK</p>
  307. <pre><code class="lang-lua">target("test")
  308. add_rules("qt.widgetapp_static")
  309. add_files("src/*.cpp")
  310. add_files("src/mainwindow.ui")
  311. add_files("src/mainwindow.h") -- add meta header files with Q_OBJECT
  312. </code></pre>
  313. <p>For more descriptions of Qt, see: <a href="https://github.com/xmake-io/xmake/issues/160">#160</a></p>
  314. <h4 id="xcodebundle">xcode.bundle</h4>
  315. <p>Used to compile and generate ios/macos bundle program</p>
  316. <pre><code class="lang-lua">target("test")
  317. add_rules("xcode.bundle")
  318. add_files("src/*.m")
  319. add_files("src/Info.plist")
  320. </code></pre>
  321. <h4 id="xcodeframework">xcode.framework</h4>
  322. <p>Used to compile and generate ios/macos framework program</p>
  323. <pre><code class="lang-lua">target("test")
  324. add_rules("xcode.framework")
  325. add_files("src/*.m")
  326. add_files("src/Info.plist")
  327. </code></pre>
  328. <h4 id="xcodeapplication">xcode.application</h4>
  329. <p>Used to compile and generate ios/macos applications</p>
  330. <pre><code class="lang-lua">target("test")
  331. add_rules("xcode.application")
  332. add_files("src/*.m", "src/**.storyboard", "src/*.xcassets")
  333. add_files("src/Info.plist")
  334. </code></pre>
  335. <h4 id="wdkenvkmdf">wdk.env.kmdf</h4>
  336. <p>Application of the compilation environment setting of kmdf under WDK, need to cooperate with: <code>wdk.[driver|binary|static|shared]</code> and other rules to use.</p>
  337. <h4 id="wdkenvumdf">wdk.env.umdf</h4>
  338. <p>Application of the umdf compiler environment settings under WDK, you need to cooperate with: <code>wdk.[driver|binary|static|shared]</code> and other rules to use.</p>
  339. <h4 id="wdkenvwdm">wdk.env.wdm</h4>
  340. <p>Application wdm compiler environment settings under WDK, need to cooperate with: <code>wdk.[driver|binary|static|shared]</code> and other rules to use.</p>
  341. <h4 id="wdkdriver">wdk.driver</h4>
  342. <p>Compile and generate drivers based on the WDK environment under Windows. Currently, only the WDK10 environment is supported.</p>
  343. <p>Note: need to cooperate: <code>wdk.env.[umdf|kmdf|wdm]</code>Environmental rules are used.</p>
  344. <pre><code class="lang-lua">-- add target
  345. target("echo")
  346. -- add rules
  347. add_rules("wdk.driver", "wdk.env.kmdf")
  348. -- add files
  349. add_files("driver/*.c")
  350. add_files("driver/*.inx")
  351. -- add includedirs
  352. add_includedirs("exe")
  353. </code></pre>
  354. <h4 id="wdkbinary">wdk.binary</h4>
  355. <p>Compile and generate executable programs based on WDK environment under Windows. Currently, only WDK10 environment is supported.</p>
  356. <p>Note: It is necessary to cooperate with: environment rules such as <code>wdk.env.[umdf|kmdf|wdm]</code>.</p>
  357. <pre><code class="lang-lua">-- add target
  358. target("app")
  359. -- add rules
  360. add_rules("wdk.binary", "wdk.env.umdf")
  361. -- add files
  362. add_files("exe/*.cpp")
  363. </code></pre>
  364. <h4 id="wdkstatic">wdk.static</h4>
  365. <p>Compile and generate static library programs based on WDK environment under Windows. Currently, only WDK10 environment is supported.</p>
  366. <p>Note: It is necessary to cooperate with: environment rules such as <code>wdk.env.[umdf|kmdf|wdm]</code>.</p>
  367. <pre><code class="lang-lua">target("nonpnp")
  368. -- add rules
  369. add_rules("wdk.static", "wdk.env.kmdf")
  370. -- add flags for rule: wdk.tracewpp
  371. add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))")
  372. -- add files
  373. add_files("driver/*.c", {rule = "wdk.tracewpp"})
  374. </code></pre>
  375. <h4 id="wdkshared">wdk.shared</h4>
  376. <p>Compile and generate dynamic library programs based on WDK environment under Windows. Currently, only WDK10 environment is supported.</p>
  377. <p>Note: It is necessary to cooperate with: environment rules such as <code>wdk.env.[umdf|kmdf|wdm]</code>.</p>
  378. <pre><code class="lang-lua">target("nonpnp")
  379. -- add rules
  380. add_rules("wdk.shared", "wdk.env.wdm")
  381. -- add flags for rule: wdk.tracewpp
  382. add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))")
  383. -- add files
  384. add_files("driver/*.c", {rule = "wdk.tracewpp"})
  385. </code></pre>
  386. <h4 id="wdktracewpp">wdk.tracewpp</h4>
  387. <p>Used to enable tracewpp to preprocess source files:</p>
  388. <pre><code class="lang-lua">target("nonpnp")
  389. -- add rules
  390. add_rules("wdk.driver", "wdk.env.kmdf")
  391. -- add flags for rule: wdk.tracewpp
  392. add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))")
  393. -- add files
  394. add_files("driver/*.c", {rule = "wdk.tracewpp"})
  395. add_files("driver/*.rc")
  396. </code></pre>
  397. <p>For more information on WDK rules, see: <a href="https://github.com/xmake-io/xmake/issues/159">#159</a></p>
  398. <h4 id="winsdkapplication">win.sdk.application</h4>
  399. <p>Compile and generate the winsdk application.</p>
  400. <pre><code class="lang-lua">-- add rules
  401. add_rules("mode.debug", "mode.release")
  402. -- define target
  403. target("usbview")
  404. -- windows application
  405. add_rules("win.sdk.application")
  406. -- add files
  407. add_files("*.c", "*.rc")
  408. add_files("xmlhelper.cpp", {rule = "win.sdk.dotnet"})
  409. </code></pre>
  410. <h4 id="wdksdkdotnet">wdk.sdk.dotnet</h4>
  411. <p>Used to specify certain c++ source files to be compiled as c++.net.</p>
  412. <pre><code class="lang-lua">add_files("xmlhelper.cpp", {rule = "win.sdk.dotnet"})
  413. </code></pre>
  414. <p>For more information on WDK rules, see: <a href="https://github.com/xmake-io/xmake/issues/159">#159</a></p>
  415. <h4 id="pluginvsxmakeautoupdate">plugin.vsxmake.autoupdate</h4>
  416. <p>We can use this rule to automatically update the VS project file (when each build is completed) in the VS project generated by <code>xmake project -k vsxmake</code>.</p>
  417. <pre><code class="lang-lua">add_rules("plugin.vsxmake.autoupdate")
  418. target("test")
  419. set_kind("binary")
  420. add_files("src/*.c")
  421. </code></pre>
  422. <h4 id="plugincompile_commandsautoupdate">plugin.compile_commands.autoupdate</h4>
  423. <p>We can also use this rule to automatically update the generated compile_commandss.json</p>
  424. <pre><code class="lang-lua">add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})
  425. target("test")
  426. set_kind("binary")
  427. add_files("src/*.c")
  428. </code></pre>
  429. <h4 id="utilssymbolsexport_all">utils.symbols.export_all</h4>
  430. <p>Provided in v2.5.2 and above, we can use it to automatically export all dynamic library symbols. Currently, only the symbol export of windows dll target programs is supported, even if there is no export interface through <code>__declspec(dllexport)</code> in the code.<br>xmake will also automatically export all c/c++ interface symbols.</p>
  431. <pre><code class="lang-lua">add_rules("mode.release", "mode.debug")
  432. target("foo")
  433. set_kind("shared")
  434. add_files("src/foo.c")
  435. add_rules("utils.symbols.export_all")
  436. target("test")
  437. set_kind("binary")
  438. add_deps("foo")
  439. add_files("src/main.c")
  440. </code></pre>
  441. <p>c++</p>
  442. <pre><code class="lang-lua">add_rules("utils.symbols.export_all", {export_classes = true})
  443. </code></pre>
  444. <p>Versions from 2.9.5 onwards also support custom filters to filter the symbol names and source file names that need to be exported:</p>
  445. <pre><code class="lang-lua">target("bar")
  446. set_kind("shared")
  447. add_files("src/bar.cpp")
  448. add_rules("utils.symbols.export_all", {export_filter = function (symbol, opt)
  449. local filepath = opt.sourcefile or opt.objectfile
  450. if filepath and filepath:find("bar.cpp", 1, true) and symbol:find("add", 1, true) then
  451. print("export: %s at %s", symbol, filepath)
  452. return true
  453. end
  454. end})
  455. </code></pre>
  456. <p>Related issue <a href="https://github.com/xmake-io/xmake/issues/1123">#1123</a></p>
  457. <h4 id="utilssymbolsexport_list">utils.symbols.export_list</h4>
  458. <p>We can define the list of exported symbols directly in xmake.lua, for example:</p>
  459. <pre><code class="lang-lua">target("foo")
  460. set_kind("shared")
  461. add_files("src/foo.c")
  462. add_rules("utils.symbols.export_list", {symbols = {
  463. "add",
  464. "sub"}})
  465. </code></pre>
  466. <p>Alternatively, add a list of exported symbols in the <code>*.export.txt</code> file.</p>
  467. <pre><code class="lang-lua">target("foo2")
  468. set_kind("shared")
  469. add_files("src/foo.c")
  470. add_files("src/foo.export.txt")
  471. add_rules("utils.symbols.export_list")
  472. </code></pre>
  473. <p>For a complete project example, see: <a href="https://github.com/xmake-io/xmake/tree/dev/tests/projects/c/shared_library_export_list">Export Symbol Example</a></p>
  474. <h4 id="utilsinstallcmake_importfiles">utils.install.cmake_importfiles</h4>
  475. <p>We can use this rule to export the .cmake file when installing the target library file for the library import and search of other cmake projects.</p>
  476. <h4 id="utilsinstallpkgconfig_importfiles">utils.install.pkgconfig_importfiles</h4>
  477. <p>We can use this rule to export the pkgconfig/.pc file when installing the target target library file for library import and search for other projects.</p>
  478. <h4 id="utilsbin2c">utils.bin2c</h4>
  479. <p>This rule can be used in versions above v2.5.7 to introduce some binary files into the project, and see them as c/c++ header files for developers to use to obtain the data of these files.</p>
  480. <p>For example, we can embed some png/jpg resource files into the code in the project.</p>
  481. <pre><code class="lang-lua">target("console")
  482. set_kind("binary")
  483. add_rules("utils.bin2c", {extensions = {".png", ".jpg"}})
  484. add_files("src/*.c")
  485. add_files("res/*.png", "res/*.jpg")
  486. </code></pre>
  487. <p>!> The setting of extensions is optional, the default extension is .bin</p>
  488. <p>Then, we can import and use it through <code>#include "filename.png.h"</code>, xmake will automatically generate the corresponding header file for you, and add the corresponding search directory.</p>
  489. <pre><code class="lang-c">static unsigned char g_png_data[] = {
  490. #include "image.png.h"
  491. };
  492. int main(int argc, char** argv)
  493. {
  494. printf("image.png: %s, size: %d\n", g_png_data, sizeof(g_png_data));
  495. return 0;
  496. }
  497. </code></pre>
  498. <p>The content of the generated header file is similar:</p>
  499. <pre><code class="lang-console">cat build/.gens/test/macosx/x86_64/release/rules/c++/bin2c/image.png.h
  500. 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x78, 0x6D, 0x61, 0x6B, 0x65, 0x21, 0x0A, 0x00
  501. </code></pre>
  502. <h4 id="utilsglsl2spv">utils.glsl2spv</h4>
  503. <p>This rule can be used in v2.6.1 and above. Import glsl shader files such as <code>*.vert/*.frag</code> into the project, and then realize automatic compilation to generate <code>*.spv</code> files.</p>
  504. <p>In addition, we also support binary embedding spv file data in the form of C/C++ header file, which is convenient for program use.</p>
  505. <h5 id="compileandgeneratespvfile">Compile and generate spv file</h5>
  506. <p>xmake will automatically call glslangValidator or glslc to compile shaders to generate .spv files, and then output them to the specified <code>{outputdir = "build"}</code> directory.</p>
  507. <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
  508. add_requires("glslang", {configs = {binaryonly = true}})
  509. target("test")
  510. set_kind("binary")
  511. add_rules("utils.glsl2spv", {outputdir = "build"})
  512. add_files("src/*.c")
  513. add_files("src/*.vert", "src/*.frag")
  514. add_packages("glslang")
  515. </code></pre>
  516. <p>Note that the <code>add_packages("glslang")</code> here is mainly used to import and bind the glslangValidator in the glslang package to ensure that xmake can always use it.</p>
  517. <p>Of course, if you have already installed it on your own system, you don’t need to bind this package additionally, but I still recommend adding it.</p>
  518. <h5 id="compileandgenerateccheaderfiles">Compile and generate c/c++ header files</h5>
  519. <p>We can also use the bin2c module internally to generate the corresponding binary header file from the compiled spv file, which is convenient for direct import in user code. We only need to enable <code>{bin2c = true}</code>. :w</p>
  520. <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
  521. add_requires("glslang", {configs = {binaryonly = true}})
  522. target("test")
  523. set_kind("binary")
  524. add_rules("utils.glsl2spv", {bin2c = true})
  525. add_files("src/*.c")
  526. add_files("src/*.vert", "src/*.frag")
  527. add_packages("glslang")
  528. </code></pre>
  529. <p>Then we can introduce in the code like this:</p>
  530. <pre><code class="lang-c">static unsigned char g_test_vert_spv_data[] = {
  531. #include "test.vert.spv.h"
  532. };
  533. static unsigned char g_test_frag_spv_data[] = {
  534. #include "test.frag.spv.h"
  535. };
  536. </code></pre>
  537. <p>Similar to the usage of bin2c rules, see the complete example: <a href="https://github.com/xmake-io/xmake/tree/master/tests/projects/other/glsl2spv">glsl2spv example</a></p>
  538. <h4 id="utilshlsl2spv">utils.hlsl2spv</h4>
  539. <p>In addition to the <code>utils.glsl2spv</code> rule, we now support the <code>utils.hlsl2spv</code> rule.</p>
  540. <pre><code class="lang-bash">add_rules("mode.debug", "mode.release")
  541. add_requires("glslang", {configs = {binaryonly = true}})
  542. target("test")
  543. set_kind("binary")
  544. add_rules("utils.hlsl2spv", {bin2c = true})
  545. add_files("src/*.c")
  546. add_files("src/*.hlsl", "src/*.hlsl")
  547. add_packages("directxshadercompiler")
  548. </code></pre>
  549. <h4 id="pythonlibrary">python.library</h4>
  550. <p>We can use this rule to generate python library modules with pybind11, which will adjust the module name of the python library.</p>
  551. <pre><code class="lang-lua">add_rules("mode.release", "mode.debug")
  552. add_requires("pybind11")
  553. target("example")
  554. add_rules("python.library")
  555. add_files("src/*.cpp")
  556. add_packages("pybind11")
  557. set_languages("c++11")
  558. </code></pre>
  559. <p>with soabi:</p>
  560. <pre><code class="lang-lua">add_rules("mode.release", "mode.debug")
  561. add_requires("pybind11")
  562. target("example")
  563. add_rules("python.library", {soabi = true})
  564. add_files("src/*.cpp")
  565. add_packages("pybind11")
  566. set_languages("c++11")
  567. </code></pre>
  568. <h4 id="nodejsmodule">nodejs.module</h4>
  569. <p>Build nodejs module.</p>
  570. <pre><code class="lang-lua">add_requires("node-addon-api")
  571. target("foo")
  572. set_languages("cxx17")
  573. add_rules("nodejs.module")
  574. add_packages("node-addon-api")
  575. add_files("*.cc")
  576. end
  577. </code></pre>
  578. <h4 id="utilsipsc">utils.ipsc</h4>
  579. <p>The ipsc compiler rules are supported and are used as follows.</p>
  580. <pre><code class="lang-lua">target("test")
  581. set_kind("binary")
  582. add_rules("utils.ispc", {header_extension = "_ispc.h"})
  583. set_values("ispc.flags", "--target=host")
  584. add_files("src/*.ispc")
  585. add_files("src/*.cpp")
  586. </code></pre>
  587. <h3 id="rule">rule</h3>
  588. <h4 id="definingrules">Defining rules</h4>
  589. <pre><code class="lang-lua">rule("markdown")
  590. set_extensions(".md", ".markdown")
  591. on_build_file(function (target, sourcefile, opt)
  592. os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
  593. end)
  594. </code></pre>
  595. <h3 id="ruleadd_deps">rule:add_deps</h3>
  596. <h4 id="addingruledependencies">Adding rule dependencies</h4>
  597. <p>Associated dependencies can bind a batch of rules, i.e. instead of adding rules one by one to a target using <code>add_rules()</code>, just apply a rule that will take effect for it and all its dependencies.</p>
  598. <p>For example</p>
  599. <pre><code class="lang-lua">rule("foo")
  600. add_deps("bar")
  601. rule("bar")
  602. ...
  603. </code></pre>
  604. <p>We only need <code>add_rules("foo")</code> to apply both foo and bar rules.</p>
  605. <p>However, by default there is no order of execution between dependencies, and scripts such as <code>on_build_file</code> for foo and bar are executed in parallel, in an undefined order.</p>
  606. <p>To strictly control the order of execution, you can configure <code>add_deps("bar", {order = true})</code> to tell xmake that we need to execute scripts at the same level according to the order of dependencies.</p>
  607. <p>Example.</p>
  608. <pre><code class="lang-lua">rule("foo")
  609. add_deps("bar", {order = true})
  610. on_build_file(function (target, sourcefile)
  611. end)
  612. rule("bar")
  613. on_build_file(function (target, sourcefile)
  614. end)
  615. </code></pre>
  616. <p>bar&#39;s <code>on_build_file</code> will be executed first.</p>
  617. <p>!> To control the order of dependencies, we need xmake 2.7.2 or above to support this.</p>
  618. <p>However, this way of controlling dependencies only works if both foo and bar rules are custom rules, and this does not work if you want to insert your own rules to be executed before xmake&#39;s built-in rules.</p>
  619. <p>In this case, we need to use a more flexible dynamic rule creation and injection approach to modify the built-in rules.</p>
  620. <p>For example, if we want to execute the <code>on_build_file</code> script for a custom cppfront rule before the built-in <code>c++.build</code> rule, we can do this in the following way.</p>
  621. <pre><code class="lang-lua">rule("cppfront")
  622. set_extensions(".cpp2")
  623. on_load(function (target)
  624. local rule = target:rule("c++.build"):clone()
  625. rule:add("deps", "cppfront", {order = true})
  626. target:rule_add(rule)
  627. end)
  628. on_build_file(function (target, sourcefile, opt)
  629. print("build cppfront file")
  630. end)
  631. target("test")
  632. set_kind("binary")
  633. add_rules("cppfront")
  634. add_files("src/*.cpp")
  635. add_files("src/*.cpp2")
  636. </code></pre>
  637. <h3 id="ruleadd_imports">rule:add_imports</h3>
  638. <h4 id="addimportedmodulesforallcustomscripts">Add imported modules for all custom scripts</h4>
  639. <p>For usage and description, please see: <a href="#targetadd_imports">target:add_imports</a>, the usage is the same.</p>
  640. <h3 id="ruleset_extensions">rule:set_extensions</h3>
  641. <h4 id="settingthefileextensiontypesupportedbytherule">Setting the file extension type supported by the rule</h4>
  642. <p>Apply rules to files with these suffixes by setting the supported extension file types, for example:</p>
  643. <pre><code class="lang-lua">-- Define a build rule for a markdown file
  644. rule("markdown")
  645. set_extensions(".md", ".markdown")
  646. on_build_file(function (target, sourcefile, opt)
  647. os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
  648. end)
  649. target("test")
  650. set_kind("binary")
  651. -- Make the test target support the construction rules of the markdown file
  652. add_rules("markdown")
  653. -- Adding a markdown file to build
  654. add_files("src/*.md")
  655. add_files("src/*.markdown")
  656. </code></pre>
  657. <h3 id="ruleon_load">rule:on_load</h3>
  658. <h4 id="customloadscript">Custom load script</h4>
  659. <p>The load script used to implement the custom rules will be executed when the target is loaded. You can customize some target configurations in it, for example:</p>
  660. <pre><code class="lang-lua">rule("test")
  661. on_load(function (target)
  662. target:add("defines", "TEST")
  663. end)
  664. </code></pre>
  665. <h3 id="ruleon_config">rule:on_config</h3>
  666. <h4 id="customconfigurationscript">custom configuration script</h4>
  667. <p>After <code>xmake config</code> is executed, this script is executed before Build, which is usually used for configuration work before compilation. It differs from on_load in that on_load is executed as soon as the target is loaded, and the execution timing is earlier.</p>
  668. <p>If some configuration cannot be configured prematurely in on_load, it can be configured in on_config.</p>
  669. <p>In addition, its execution time is earlier than before_build, and the approximate execution flow is as follows:</p>
  670. <pre><code>on_load -> after_load -> on_config -> before_build -> on_build -> after_build
  671. </code></pre><h3 id="ruleon_link">rule:on_link</h3>
  672. <h4 id="customlinkscript">Custom link script</h4>
  673. <p>The link script used to implement the custom rules overrides the default link behavior of the applied target, for example:</p>
  674. <pre><code class="lang-lua">rule("test")
  675. on_link(function (target)
  676. end)
  677. </code></pre>
  678. <h3 id="ruleon_build">rule:on_build</h3>
  679. <h4 id="customcompilationscript">Custom compilation script</h4>
  680. <p>The build script used to implement the custom rules overrides the default build behavior of the target being applied, for example:</p>
  681. <pre><code class="lang-lua">rule("markdown")
  682. on_build(function (target)
  683. end)
  684. </code></pre>
  685. <h3 id="ruleon_clean">rule:on_clean</h3>
  686. <h4 id="customcleanupscript">Custom cleanup script</h4>
  687. <p>The cleanup script used to implement the custom rules will override the default cleanup behavior of the applied target, for example:</p>
  688. <pre><code class="lang-lua">rule("markdown")
  689. on_clean(function (target)
  690. -- remove sourcefile.html
  691. end)
  692. </code></pre>
  693. <h3 id="ruleon_package">rule:on_package</h3>
  694. <h4 id="custompackagingscript">Custom packaging script</h4>
  695. <p>A packaging script for implementing custom rules that overrides the default packaging behavior of the target being applied, for example:</p>
  696. <pre><code class="lang-lua">rule("markdown")
  697. on_package(function (target)
  698. -- package sourcefile.html
  699. end)
  700. </code></pre>
  701. <h3 id="ruleon_install">rule:on_install</h3>
  702. <h4 id="custominstallationscript">Custom installation script</h4>
  703. <p>An installation script for implementing custom rules that overrides the default installation behavior of the target being applied, for example:</p>
  704. <pre><code class="lang-lua">rule("markdown")
  705. on_install(function (target)
  706. end)
  707. </code></pre>
  708. <h3 id="ruleon_uninstall">rule:on_uninstall</h3>
  709. <h4 id="customuninstallscript">Custom Uninstall Script</h4>
  710. <p>An uninstall script for implementing custom rules that overrides the default uninstall behavior of the target being applied, for example:</p>
  711. <pre><code class="lang-lua">rule("markdown")
  712. on_uninstall(function (target)
  713. end)
  714. </code></pre>
  715. <h3 id="ruleon_build_file">rule:on_build_file</h3>
  716. <h4 id="customizingthebuildscripttoprocessonesourcefileatatime">Customizing the build script to process one source file at a time</h4>
  717. <pre><code class="lang-lua">rule("markdown")
  718. on_build_file(function (target, sourcefile, opt)
  719. print("%%%d: %s", opt.progress, sourcefile)
  720. end)
  721. </code></pre>
  722. <p>The third parameter opt is an optional parameter, which is used to obtain some information state during the compilation process. For example, opt.progress is the compilation progress of the current period.</p>
  723. <h3 id="ruleon_buildcmd_file">rule:on_buildcmd_file</h3>
  724. <h4 id="custombatchcompilescriptprocessonesourcefileatatime">Custom batch compile script, process one source file at a time</h4>
  725. <p>This is a new interface added in version 2.5.2. The script inside will not directly construct the source file, but will construct a batch command line task through the batchcmds object.<br>When xmake actually executes the build, it executes these commands once.</p>
  726. <p>This is very useful for project generator plugins such as <code>xmake project</code>, because third-party project files generated by the generator do not support the execution of built-in scripts such as <code>on_build_files</code>.</p>
  727. <p>But the final result of <code>on_buildcmd_files</code> construction is a batch of original cmd command lines, which can be directly executed as custom commands for other project files.</p>
  728. <p>In addition, compared to <code>on_build_files</code>, it also simplifies the implementation of compiling extension files, is more readable and easy to configure, and is more user-friendly.</p>
  729. <pre><code class="lang-lua">rule("foo")
  730. set_extensions(".xxx")
  731. on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  732. batchcmds:vrunv("gcc", {"-o", objectfile, "-c", sourcefile})
  733. batchcmds:add_depfiles("/xxxxx/dependfile.h", ...)
  734. -- batchcmds:add_depvalues(...)
  735. -- batchcmds:set_depmtime(os.mtime(...))
  736. -- batchcmds:set_depcache("xxxx.d")
  737. end)
  738. </code></pre>
  739. <p>In addition to <code>batchcmds:vrunv</code>, we also support some other batch commands, such as:</p>
  740. <pre><code class="lang-lua">batchcmds:show("hello %s", "xmake")
  741. batchcmds:vrunv("gcc", {"-o", objectfile, "-c", sourcefile}, {envs = {LD_LIBRARY_PATH="/xxx"}})
  742. batchcmds:mkdir("/xxx") - and cp, mv, rm, ln ..
  743. batchcmds:compile(sourcefile_cx, objectfile, {configs = {includedirs = sourcefile_dir, languages ​​= (sourcekind == "cxx" and "c++11")}})
  744. batchcmds:link(objectfiles, targetfile, {configs = {linkdirs = ""}})
  745. </code></pre>
  746. <p>At the same time, we also simplify the configuration of dependency execution in it. The following is a complete example:</p>
  747. <pre><code class="lang-lua">rule("lex")
  748. set_extensions(".l", ".ll")
  749. on_buildcmd_file(function (target, batchcmds, sourcefile_lex, opt)
  750. - imports
  751. import("lib.detect.find_tool")
  752. - get lex
  753. local lex = assert(find_tool("flex") or find_tool("lex"), "lex not found!")
  754. - get c/c++ source file for lex
  755. local extension = path.extension(sourcefile_lex)
  756. local sourcefile_cx = path.join(target:autogendir(), "rules", "lex_yacc", path.basename(sourcefile_lex) .. (extension == ".ll" and ".cpp" or ".c"))
  757. - add objectfile
  758. local objectfile = target:objectfile(sourcefile_cx)
  759. table.insert(target:objectfiles(), objectfile)
  760. - add commands
  761. batchcmds:show_progress(opt.progress, "${color.build.object}compiling.lex %s", sourcefile_lex)
  762. batchcmds:mkdir(path.directory(sourcefile_cx))
  763. batchcmds:vrunv(lex.program, {"-o", sourcefile_cx, sourcefile_lex})
  764. batchcmds:compile(sourcefile_cx, objectfile)
  765. - add deps
  766. batchcmds:add_depfiles(sourcefile_lex)
  767. batchcmds:set_depmtime(os.mtime(objectfile))
  768. batchcmds:set_depcache(target:dependfile(objectfile))
  769. end)
  770. </code></pre>
  771. <p>For a detailed description and background of this, see: <a href="https://github.com/xmake-io/xmake/issues/1246">issue 1246</a></p>
  772. <h3 id="ruleon_build_files">rule:on_build_files</h3>
  773. <h4 id="customizingthebuildscripttoprocessmultiplesourcefilesatonce">Customizing the build script to process multiple source files at once</h4>
  774. <p>Most of the custom build rules, each time processing a single file, output a target file, for example: a.c => a.o</p>
  775. <p>However, in some cases, we need to enter multiple source files together to build an object file, for example: a.c b.c d.c => x.o</p>
  776. <p>For this situation, we can achieve this by customizing this script:</p>
  777. <pre><code class="lang-lua">rule("markdown")
  778. on_build_files(function (target, sourcebatch, opt)
  779. -- build some source files
  780. for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
  781. -- ...
  782. end
  783. end)
  784. </code></pre>
  785. <h3 id="ruleon_buildcmd_files">rule:on_buildcmd_files</h3>
  786. <h4 id="customizebatchcompilingscriptprocessmultiplesourcefilesatonce">Customize batch compiling script, process multiple source files at once</h4>
  787. <p>For a detailed description of this, see: <a href="#ruleon_buildcmd_file">rule:on_buildcmd_file</a></p>
  788. <pre><code class="lang-lua">rule("foo")
  789. set_extensions(".xxx")
  790. on_buildcmd_files(function (target, batchcmds, sourcebatch, opt)
  791. for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
  792. batchcmds:vrunv("gcc", {"-o", objectfile, "-c", sourcefile})
  793. end
  794. end)
  795. </code></pre>
  796. <h3 id="rulebefore_config">rule:before_config</h3>
  797. <h4 id="custompreconfigurationscript">Custom pre-configuration script</h4>
  798. <p>Used to implement the execution script before custom target configuration, for example:</p>
  799. <pre><code class="lang-lua">rule("test")
  800. before_config(function (target)
  801. end)
  802. </code></pre>
  803. <p>It will be executed before on_config.</p>
  804. <h3 id="rulebefore_link">rule:before_link</h3>
  805. <h4 id="customprelinkscript">Custom pre-link script</h4>
  806. <p>Execution scripts used to implement custom target links, for example:</p>
  807. <pre><code class="lang-lua">rule("test")
  808. before_link(function (target)
  809. end)
  810. </code></pre>
  811. <h3 id="rulebefore_build">rule:before_build</h3>
  812. <h4 id="customprecompilationscript">Custom pre-compilation script</h4>
  813. <p>Used to implement the execution script before the custom target is built, for example:</p>
  814. <pre><code class="lang-lua">rule("markdown")
  815. before_build(function (target)
  816. end)
  817. </code></pre>
  818. <h3 id="rulebefore_clean">rule:before_clean</h3>
  819. <h4 id="customprecleanupscript">Custom pre-cleanup script</h4>
  820. <p>Used to implement the execution script before the custom target cleanup, for example:</p>
  821. <pre><code class="lang-lua">rule("markdown")
  822. before_clean(function (target)
  823. end)
  824. </code></pre>
  825. <h3 id="rulebefore_package">rule:before_package</h3>
  826. <h4 id="customtheprepackagescript">Custom the pre-package script</h4>
  827. <p>Used to implement the execution script before the custom target is packaged, for example:</p>
  828. <pre><code class="lang-lua">rule("markdown")
  829. before_package(function (target)
  830. end)
  831. </code></pre>
  832. <h3 id="rulebefore_install">rule:before_install</h3>
  833. <h4 id="custompreinstallationscript">Custom pre-installation script</h4>
  834. <p>Used to implement the execution script before the custom target installation, for example:</p>
  835. <pre><code class="lang-lua">rule("markdown")
  836. before_install(function (target)
  837. end)
  838. </code></pre>
  839. <h3 id="rulebefore_uninstall">rule:before_uninstall</h3>
  840. <h4 id="custompreuninstallscript">Custom pre-uninstall script</h4>
  841. <p>Used to implement the execution script before the custom target is uninstalled, for example:</p>
  842. <pre><code class="lang-lua">rule("markdown")
  843. before_uninstall(function (target)
  844. end)
  845. </code></pre>
  846. <h3 id="rulebefore_build_file">rule:before_build_file</h3>
  847. <h4 id="customprecompilationscripttoprocessonesourcefileatatime">Custom pre-compilation script to process one source file at a time</h4>
  848. <p>Similar to <a href="#ruleon_build_file">rule:on_build_file</a>, but the timing of this interface is called before compiling a source file.<br>Generally used to preprocess some source files before compiling.</p>
  849. <h3 id="rulebefore_buildcmd_file">rule:before_buildcmd_file</h3>
  850. <h4 id="customizetheprecompilationbatchscriptprocessonesourcefileatatime">Customize the pre-compilation batch script, process one source file at a time</h4>
  851. <p>Similar to the usage of <a href="#ruleon_buildcmd_file">rule:on_buildcmd_file</a>, but the time when this interface is called is before compiling a certain source file.<br>It is generally used to pre-process certain source files before compilation.</p>
  852. <h3 id="rulebefore_build_files">rule:before_build_files</h3>
  853. <h4 id="customizeprecompilationscriptstoprocessmultiplesourcefilesatonce">Customize pre-compilation scripts to process multiple source files at once</h4>
  854. <p>Similar to the usage of <a href="#ruleon_build_files">rule:on_build_files</a>, but the time when this interface is called is before compiling some source files,<br>It is generally used to pre-process certain source files before compilation.</p>
  855. <h3 id="rulebefore_buildcmd_files">rule:before_buildcmd_files</h3>
  856. <h4 id="customizetheprecompilationbatchscripttoprocessmultiplesourcefilesatonce">Customize the pre-compilation batch script to process multiple source files at once</h4>
  857. <p>Similar to the usage of <a href="#ruleon_buildcmd_files">rule:on_buildcmd_files</a>, but the time when this interface is called is before compiling some source files,<br>It is generally used to pre-process certain source files before compilation.</p>
  858. <h3 id="ruleafter_config">rule:after_config</h3>
  859. <h4 id="custompostconfigurationscript">Custom post-configuration script</h4>
  860. <p>Used to implement the execution script after custom target configuration, for example:</p>
  861. <pre><code class="lang-lua">rule("test")
  862. after_config(function (target)
  863. end)
  864. </code></pre>
  865. <p>It will be executed after on_config.</p>
  866. <h3 id="ruleafter_link">rule:after_link</h3>
  867. <h4 id="custompostlinkingscript">Custom post-linking script</h4>
  868. <p>The execution script used to implement the custom target link is similar to <a href="#ruleafter_link">rule:after_link</a>.</p>
  869. <h3 id="ruleafter_build">rule:after_build</h3>
  870. <h4 id="custompostcompilationscript">Custom post-compilation script</h4>
  871. <p>The execution script used to implement the custom target build is similar to <a href="#rulebefore_build">rule:before_build</a>.</p>
  872. <h3 id="ruleafter_clean">rule:after_clean</h3>
  873. <h4 id="custompostcleaningscript">Custom post-cleaning script</h4>
  874. <p>The execution script used to implement the custom target cleanup is similar to <a href="#rulebefore_clean">rule:before_clean</a>.</p>
  875. <h3 id="ruleafter_package">rule:after_package</h3>
  876. <h4 id="custompostpackagingscript">Custom post-packaging script</h4>
  877. <p>The execution script used to implement the custom target package is similar to <a href="#rulebefore_package">rule:before_package</a>.</p>
  878. <h3 id="ruleafter_install">rule:after_install</h3>
  879. <h4 id="custompostinstallationscript">Custom post-installation script</h4>
  880. <p>The execution script used to implement the custom target installation is similar to <a href="#rulebefore_install">rule:before_install</a>.</p>
  881. <h3 id="ruleafter_uninstall">rule:after_uninstall</h3>
  882. <h4 id="custompostuninstallationscript">Custom post-uninstallation Script</h4>
  883. <p>The execution script used to implement the custom target uninstallation is similar to <a href="#rulebefore_uninstall">rule:before_uninstall</a>.</p>
  884. <h3 id="ruleafter_build_file">rule:after_build_file</h3>
  885. <h4 id="custompostcompilationscriptstoprocessonesourcefileatatime">Custom post-compilation scripts to process one source file at a time</h4>
  886. <p>Similar to <a href="#ruleon_build_file">rule:on_build_file</a>, but the timing of this interface is called after compiling a source file.<br>Generally used to post-process some compiled object files.</p>
  887. <h3 id="ruleafter_buildcmd_file">rule:after_buildcmd_file</h3>
  888. <h4 id="customizethecompiledbatchscriptprocessonesourcefileatatime">Customize the compiled batch script, process one source file at a time</h4>
  889. <p>Similar to the usage of <a href="#ruleon_buildcmd_file">rule:on_buildcmd_file</a>, but the time when this interface is called is after compiling a certain source file,<br>Generally used for post-processing some compiled object files.</p>
  890. <h3 id="ruleafter_build_files">rule:after_build_files</h3>
  891. <h4 id="customizethecompiledscripttoprocessmultiplesourcefilesatonce">Customize the compiled script to process multiple source files at once</h4>
  892. <p>The usage is similar to <a href="#ruleon_build_files">rule:on_build_files</a>, but the time when this interface is called is after some source files are compiled,<br>Generally used for post-processing some compiled object files.</p>
  893. <h3 id="ruleafter_buildcmd_files">rule:after_buildcmd_files</h3>
  894. <h4 id="customizethecompiledbatchscripttoprocessmultiplesourcefilesatonce">Customize the compiled batch script to process multiple source files at once</h4>
  895. <p>The usage is similar to <a href="#ruleon_buildcmd_files">rule:on_buildcmd_files</a>, but the time when this interface is called is after compiling some source files,<br>Generally used for post-processing some compiled object files.</p>
  896. <h3 id="rule_end">rule_end</h3>
  897. <h4 id="enddefinitionrules">End definition rules</h4>
  898. <p>This is optional. If you want to manually end the rule definition, you can call it:</p>
  899. <pre><code class="lang-lua">rule("test")
  900. -- ..
  901. rule_end()
  902. </code></pre>
  903. </article>
  904. </body>
  905. </html>