more_plugins.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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/more_plugins">https://xmake.io/#/plugin/more_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="vscodeplugin">VSCode Plugin</h2>
  86. <ul>
  87. <li><a href="https://github.com/xmake-io/xmake-vscode">xmake-vscode</a></li>
  88. </ul>
  89. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-vscode/master/res/problem.gif" width="650px" /></p>
  90. <p><a href="https://code.visualstudio.com/">VSCode</a>is a commonly used text editor, and xmake provides plug-ins&#39; support.</p>
  91. <h3 id="plugininstallation">Plugin installation</h3>
  92. <p>Since VSCode itself only provides text editing functions, we need to install plug-ins to support configuration, compilation, debugging, intellisenses and other functions:</p>
  93. <ul>
  94. <li>XMake</li>
  95. <li>C/C++</li>
  96. <li>CodeLLDB</li>
  97. </ul>
  98. <p>After completing the installation of the plug-in, restart VSCode to see the status bar below:</p>
  99. <p><img src="/assets/img/guide/vscode_status_bar.png" alt=""></p>
  100. <p>You can set the platform, architecture, compilation mode, tool-chain and other options in the status bar, and then click Build to start the build.</p>
  101. <h3 id="customoptions">Custom options</h3>
  102. <p>If these options are not enough, you can create .vscode/settings.json and write the settings required by xmake, such as:</p>
  103. <pre><code>{
  104. ...
  105. "xmake.additionalConfigArguments": [
  106. "--my_option=true"
  107. ],
  108. ...
  109. }
  110. </code></pre><p>Other xmake options can also be setted in settings.json. After modification, the configuration can be refreshed through the >XMake: Configure command.</p>
  111. <h3 id="configureintellsence">Configure Intellsence</h3>
  112. <p>For a better C++ syntax prompt experience, xmake provides support for <a href="https://microsoft.github.io/language-server-protocol/">Language Server Protocol</a> (LSP for short).</p>
  113. <p>In vscode, we can provide intellsence support by using vscode-cpptools or clangd.</p>
  114. <p>In addition, in order to support intellsence, xmake provides compile_commands.json generation support.</p>
  115. <h4 id="generatecompile_commands">generate compile_commands</h4>
  116. <h5 id="automatictriggergeneration">Automatic trigger generation</h5>
  117. <p>Usually after modifying xmake.lua and clicking Save, the xmake-vscode plugin will trigger the automatic generation of compile_commands.json, which is stored in the .vscode directory by default.</p>
  118. <p>This is also the recommended way. Usually after installing the xmake-vscode plug-in and opening the project with xmake.lua, you only need to edit xmake.lua to save and trigger without any other additional operations.</p>
  119. <h5 id="manuallytriggergeneration">Manually trigger generation</h5>
  120. <p>Of course, if we don’t see the file being generated, we can also use the <code>>XMake: UpdateIntellisense</code> command to manually trigger the generation of .vscode/compile_commands.json in vscode.</p>
  121. <h5 id="configurexmakeluatogenerateautomatically">Configure xmake.lua to generate automatically</h5>
  122. <p>Alternatively, we can also use this rule to automatically update and generate compile_commandss.json</p>
  123. <pre><code class="lang-lua">add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})
  124. target("test")
  125. set_kind("binary")
  126. add_files("src/*.c")
  127. </code></pre>
  128. <p>This will automatically update this file after each build.</p>
  129. <h5 id="manualexecutioncommandgeneration">Manual execution command generation</h5>
  130. <p>If the above methods are invalid, we can also execute the command to generate.</p>
  131. <pre><code class="lang-console">$ xmake project -k compile_commands .vscode
  132. </code></pre>
  133. <h4 id="vscodecpptools">vscode-cpptools</h4>
  134. <p>If we use the vscode-cpptools plug-in to provide intellsence support, we need to go to the vscode plug-in market first, search for C++, the default first plug-in is to install it.</p>
  135. <p>When installed, this plugin provides intellsence and debugging support.</p>
  136. <p>Then, we need to configure the c_cpp_properties.json file and associate it with the <code>.vscode/compile_commands.json</code> we generated.</p>
  137. <pre><code>{
  138. "env": {
  139. "myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
  140. "myCompilerPath": "/usr/local/bin/gcc-7"
  141. },
  142. "configurations": [
  143. {
  144. "name": "Mac",
  145. "intelliSenseMode": "clang-x64",
  146. "includePath": ["${myDefaultIncludePath}", "/another/path"],
  147. "macFrameworkPath": ["/System/Library/Frameworks"],
  148. "defines": ["FOO", "BAR=100"],
  149. "forcedInclude": ["${workspaceFolder}/include/config.h"],
  150. "compilerPath": "/usr/bin/clang",
  151. "cStandard": "c11",
  152. "cppStandard": "c++17",
  153. "compileCommands": "/path/to/compile_commands.json",
  154. "browse": {
  155. "path": ["${workspaceFolder}"],
  156. "limitSymbolsToIncludedHeaders": true,
  157. "databaseFilename": ""
  158. }
  159. }
  160. ],
  161. "version": 4
  162. }
  163. </code></pre><p>That is the <code>"compileCommands": "/path/to/compile_commands.json"</code> configuration item above.</p>
  164. <p>For how to open this configuration file, and more configuration instructions, see:</p>
  165. <ul>
  166. <li><a href="https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation">https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation</a></li>
  167. <li><a href="https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference">https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference</a></li>
  168. </ul>
  169. <p>Of course, in theory, the xmake-vscode plugin can automatically associate and set this file, but considering that users do not necessarily use cpptools, they may also use clangd.</p>
  170. <p>Therefore, the default automatic configuration is not very good, and the author has no time and energy to improve it.</p>
  171. <h4 id="clangd">clangd</h4>
  172. <p>When using clangd, there may be conflicts with the C/C++ plug-in, you can add settings in .vscode/settings.json:</p>
  173. <pre><code>{
  174. "C_Cpp.codeAnalysis.runAutomatically": false,
  175. "C_Cpp.intelliSenseEngine": "Disabled",
  176. "C_Cpp.formatting": "Disabled",
  177. "C_Cpp.autoAddFileAssociations": false,
  178. "C_Cpp.autocompleteAddParentheses": false,
  179. "C_Cpp.autocomplete": "Disabled",
  180. "C_Cpp.errorSquiggles": "Disabled",
  181. ...
  182. }
  183. </code></pre><p>Also, since the compile_commands.json generated by XMake is in the .vscode directory, you need to set the clangd parameter to look for it in the correct location:</p>
  184. <pre><code>{
  185. "clangd.arguments": [
  186. "--compile-commands-dir=.vscode",
  187. ...
  188. ]
  189. ...
  190. }
  191. </code></pre><h2 id="sublimeplugin">Sublime Plugin</h2>
  192. <ul>
  193. <li><a href="https://github.com/xmake-io/xmake-sublime">xmake-sublime</a></li>
  194. </ul>
  195. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-sublime/master/res/problem.gif" width="650px" /></p>
  196. <h2 id="intellijideaclionpluin">Intellij IDEA/Clion Pluin</h2>
  197. <ul>
  198. <li><a href="https://github.com/xmake-io/xmake-idea">xmake-idea</a></li>
  199. </ul>
  200. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-idea/master/res/problem.gif" width="650px" /></p>
  201. <h2 id="vimplugin">Vim Plugin</h2>
  202. <ul>
  203. <li><a href="https://github.com/luzhlon/xmake.vim">xmake.vim</a> (third-party, thanks <a href="https://github.com/luzhlon">@luzhlon</a>)</li>
  204. </ul>
  205. <h2 id="neovimplugin">Neovim Plugin</h2>
  206. <ul>
  207. <li><a href="https://github.com/Mythos-404/xmake.nvim">xmake.nvim</a> (third-party, thanks <a href="https://github.com/Mythos-404">@Mythos_404</a>)</li>
  208. </ul>
  209. <p>The plugin provides easy-to-use configuration UI and auto-generation of <em>compile_commands.json</em> files</p>
  210. <p><img src="https://raw.githubusercontent.com/Mythos-404/xmake.nvim/main/assets/XmakePreview.gif" width="650px" /></p>
  211. <h2 id="gradlepluginjni">Gradle Plugin (JNI)</h2>
  212. <ul>
  213. <li><a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a>: A gradle plugin that integrates xmake seamlessly</li>
  214. </ul>
  215. <h3 id="pluginsdsl">plugins DSL</h3>
  216. <pre><code>plugins {
  217. id &#39;org.tboox.gradle-xmake-plugin&#39; version &#39;1.0.9&#39;
  218. }
  219. </code></pre><h3 id="legacypluginapplication">Legacy plugin application</h3>
  220. <pre><code>buildscript {
  221. repositories {
  222. maven {
  223. url "https://plugins.gradle.org/m2/"
  224. }
  225. }
  226. dependencies {
  227. classpath &#39;org.tboox:gradle-xmake-plugin:1.0.9&#39;
  228. }
  229. repositories {
  230. mavenCentral()
  231. }
  232. }
  233. apply plugin: "org.tboox.gradle-xmake-plugin"
  234. </code></pre><h3 id="simplestexample">Simplest Example</h3>
  235. <p>We add <code>xmake.lua</code> to <code>projectdir/jni/xmake.lua</code> and enable xmake in build.gradle.</p>
  236. <h4 id="buildgradle">build.gradle</h4>
  237. <pre><code>android {
  238. externalNativeBuild {
  239. xmake {
  240. path "jni/xmake.lua"
  241. }
  242. }
  243. }
  244. </code></pre><h4 id="jni">JNI</h4>
  245. <p>The JNI project structure:</p>
  246. <pre><code>projectdir
  247. - src
  248. - main
  249. - java
  250. - jni
  251. - xmake.lua
  252. - *.cpp
  253. </code></pre><p>xmake.lua:</p>
  254. <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
  255. target("nativelib")
  256. set_kind("shared")
  257. add_files("nativelib.cc")
  258. </code></pre>
  259. <h3 id="moregradleconfiguations">More Gradle Configuations</h3>
  260. <pre><code>android {
  261. defaultConfig {
  262. externalNativeBuild {
  263. xmake {
  264. // append the global cflags (optional)
  265. cFlags "-DTEST"
  266. // append the global cppflags (optional)
  267. cppFlags "-DTEST", "-DTEST2"
  268. // switch the build mode to `debug` for `xmake f -m debug` (optional)
  269. buildMode "debug"
  270. // set abi filters (optional), e.g. armeabi, armeabi-v7a, arm64-v8a, x86, x86_64
  271. // we can also get abiFilters from defaultConfig.ndk.abiFilters
  272. abiFilters "armeabi-v7a", "arm64-v8a"
  273. }
  274. }
  275. }
  276. externalNativeBuild {
  277. xmake {
  278. // enable xmake and set xmake.lua project file path
  279. path "jni/xmake.lua"
  280. // enable verbose output (optional), e.g. verbose, warning, normal
  281. logLevel "verbose"
  282. // set c++stl (optional), e.g. c++_static/c++_shared, gnustl_static/gnustl_shared, stlport_static/stlport_shared
  283. stl "c++_shared"
  284. // set the given xmake program path (optional)
  285. // program /usr/local/bin/xmake
  286. // disable stdc++ library (optional)
  287. // stdcxx false
  288. // set the given ndk directory path (optional)
  289. // ndk "/Users/ruki/files/android-ndk-r20b/"
  290. // set sdk version of ndk (optional)
  291. // sdkver 21
  292. }
  293. }
  294. }
  295. </code></pre><h3 id="buildjniandgenerateapk">Build JNI and generate apk</h3>
  296. <p>The <code>xmakeBuild</code> will be injected to <code>assemble</code> task automatically if the gradle-xmake-plugin has been applied.</p>
  297. <pre><code class="lang-console">$ ./gradlew app:assembleDebug
  298. > Task :nativelib:xmakeConfigureForArm64
  299. > Task :nativelib:xmakeBuildForArm64
  300. >> xmake build
  301. [ 50%]: cache compiling.debug nativelib.cc
  302. [ 75%]: linking.debug libnativelib.so
  303. [100%]: build ok!
  304. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a
  305. > Task :nativelib:xmakeConfigureForArmv7
  306. > Task :nativelib:xmakeBuildForArmv7
  307. >> xmake build
  308. [ 50%]: cache compiling.debug nativelib.cc
  309. [ 75%]: linking.debug libnativelib.so
  310. [100%]: build ok!
  311. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a
  312. > Task :nativelib:preBuild
  313. > Task :nativelib:assemble
  314. > Task :app:assembleDebug
  315. </code></pre>
  316. <h3 id="forcetorebuildjni">Force to rebuild JNI</h3>
  317. <pre><code class="lang-console">$ ./gradlew nativelib:xmakeRebuild
  318. </code></pre>
  319. </article>
  320. </body>
  321. </html>