more_plugins.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. </br>
  30. <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
  31. <style>
  32. #carbonads {
  33. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  34. Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
  35. }
  36. #carbonads {
  37. display: flex;
  38. max-width: 330px;
  39. background-color: hsl(0, 0%, 98%);
  40. box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
  41. }
  42. #carbonads a {
  43. color: inherit;
  44. text-decoration: none;
  45. }
  46. #carbonads a:hover {
  47. color: inherit;
  48. }
  49. #carbonads span {
  50. position: relative;
  51. display: block;
  52. overflow: hidden;
  53. }
  54. #carbonads .carbon-wrap {
  55. display: flex;
  56. }
  57. .carbon-img {
  58. display: block;
  59. margin: 0;
  60. line-height: 1;
  61. }
  62. .carbon-img img {
  63. display: block;
  64. }
  65. .carbon-text {
  66. font-size: 13px;
  67. padding: 10px;
  68. line-height: 1.5;
  69. text-align: left;
  70. }
  71. .carbon-poweredby {
  72. display: block;
  73. padding: 8px 10px;
  74. 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);
  75. text-align: center;
  76. text-transform: uppercase;
  77. letter-spacing: .5px;
  78. font-weight: 600;
  79. font-size: 9px;
  80. line-height: 1;
  81. }
  82. </style>
  83. <h2 id="vscodeplugin">VSCode Plugin</h2>
  84. <ul>
  85. <li><a href="https://github.com/xmake-io/xmake-vscode">xmake-vscode</a></li>
  86. </ul>
  87. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-vscode/master/res/problem.gif" width="650px" /></p>
  88. <p><a href="https://code.visualstudio.com/">VSCode</a>is a commonly used text editor, and xmake provides plug-ins&#39; support.</p>
  89. <h3 id="plugininstallation">Plugin installation</h3>
  90. <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>
  91. <ul>
  92. <li>XMake</li>
  93. <li>C/C++</li>
  94. <li>CodeLLDB</li>
  95. </ul>
  96. <p>After completing the installation of the plug-in, restart VSCode to see the status bar below:</p>
  97. <p><img src="/assets/img/guide/vscode_status_bar.png" alt=""></p>
  98. <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>
  99. <h3 id="customoptions">Custom options</h3>
  100. <p>If these options are not enough, you can create .vscode/settings.json and write the settings required by xmake, such as:</p>
  101. <pre><code>{
  102. ...
  103. "xmake.additionalConfigArguments": [
  104. "--my_option=true"
  105. ],
  106. ...
  107. }
  108. </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>
  109. <h3 id="configureintellsence">Configure Intellsence</h3>
  110. <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>
  111. <p>In vscode, we can provide intellsence support by using vscode-cpptools or clangd.</p>
  112. <p>In addition, in order to support intellsence, xmake provides compile_commands.json generation support.</p>
  113. <h4 id="generatecompile_commands">generate compile_commands</h4>
  114. <h5 id="automatictriggergeneration">Automatic trigger generation</h5>
  115. <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>
  116. <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>
  117. <h5 id="manuallytriggergeneration">Manually trigger generation</h5>
  118. <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>
  119. <h5 id="configurexmakeluatogenerateautomatically">Configure xmake.lua to generate automatically</h5>
  120. <p>Alternatively, we can also use this rule to automatically update and generate compile_commandss.json</p>
  121. <pre><code class="lang-lua">add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})
  122. target("test")
  123. set_kind("binary")
  124. add_files("src/*.c")
  125. </code></pre>
  126. <p>This will automatically update this file after each build.</p>
  127. <h5 id="manualexecutioncommandgeneration">Manual execution command generation</h5>
  128. <p>If the above methods are invalid, we can also execute the command to generate.</p>
  129. <pre><code class="lang-console">$ xmake project -k compile_commands .vscode
  130. </code></pre>
  131. <h4 id="vscodecpptools">vscode-cpptools</h4>
  132. <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>
  133. <p>When installed, this plugin provides intellsence and debugging support.</p>
  134. <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>
  135. <pre><code>{
  136. "env": {
  137. "myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
  138. "myCompilerPath": "/usr/local/bin/gcc-7"
  139. },
  140. "configurations": [
  141. {
  142. "name": "Mac",
  143. "intelliSenseMode": "clang-x64",
  144. "includePath": ["${myDefaultIncludePath}", "/another/path"],
  145. "macFrameworkPath": ["/System/Library/Frameworks"],
  146. "defines": ["FOO", "BAR=100"],
  147. "forcedInclude": ["${workspaceFolder}/include/config.h"],
  148. "compilerPath": "/usr/bin/clang",
  149. "cStandard": "c11",
  150. "cppStandard": "c++17",
  151. "compileCommands": "/path/to/compile_commands.json",
  152. "browse": {
  153. "path": ["${workspaceFolder}"],
  154. "limitSymbolsToIncludedHeaders": true,
  155. "databaseFilename": ""
  156. }
  157. }
  158. ],
  159. "version": 4
  160. }
  161. </code></pre><p>That is the <code>"compileCommands": "/path/to/compile_commands.json"</code> configuration item above.</p>
  162. <p>For how to open this configuration file, and more configuration instructions, see:</p>
  163. <ul>
  164. <li><a href="https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation">https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation</a></li>
  165. <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>
  166. </ul>
  167. <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>
  168. <p>Therefore, the default automatic configuration is not very good, and the author has no time and energy to improve it.</p>
  169. <h4 id="clangd">clangd</h4>
  170. <p>When using clangd, there may be conflicts with the C/C++ plug-in, you can add settings in .vscode/settings.json:</p>
  171. <pre><code>{
  172. "C_Cpp.codeAnalysis.runAutomatically": false,
  173. "C_Cpp.intelliSenseEngine": "Disabled",
  174. "C_Cpp.formatting": "Disabled",
  175. "C_Cpp.autoAddFileAssociations": false,
  176. "C_Cpp.autocompleteAddParentheses": false,
  177. "C_Cpp.autocomplete": "Disabled",
  178. "C_Cpp.errorSquiggles": "Disabled",
  179. ...
  180. }
  181. </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>
  182. <pre><code>{
  183. "clangd.arguments": [
  184. "--compile-commands-dir=.vscode",
  185. ...
  186. ]
  187. ...
  188. }
  189. </code></pre><h2 id="sublimeplugin">Sublime Plugin</h2>
  190. <ul>
  191. <li><a href="https://github.com/xmake-io/xmake-sublime">xmake-sublime</a></li>
  192. </ul>
  193. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-sublime/master/res/problem.gif" width="650px" /></p>
  194. <h2 id="intellijideaclionpluin">Intellij IDEA/Clion Pluin</h2>
  195. <ul>
  196. <li><a href="https://github.com/xmake-io/xmake-idea">xmake-idea</a></li>
  197. </ul>
  198. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-idea/master/res/problem.gif" width="650px" /></p>
  199. <h2 id="vimplugin">Vim Plugin</h2>
  200. <ul>
  201. <li><a href="https://github.com/luzhlon/xmake.vim">xmake.vim</a> (third-party, thanks <a href="https://github.com/luzhlon">@luzhlon</a>)</li>
  202. </ul>
  203. <h2 id="gradlepluginjni">Gradle Plugin (JNI)</h2>
  204. <ul>
  205. <li><a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a>: A gradle plugin that integrates xmake seamlessly</li>
  206. </ul>
  207. <h3 id="pluginsdsl">plugins DSL</h3>
  208. <pre><code>plugins {
  209. id &#39;org.tboox.gradle-xmake-plugin&#39; version &#39;1.0.9&#39;
  210. }
  211. </code></pre><h3 id="legacypluginapplication">Legacy plugin application</h3>
  212. <pre><code>buildscript {
  213. repositories {
  214. maven {
  215. url "https://plugins.gradle.org/m2/"
  216. }
  217. }
  218. dependencies {
  219. classpath &#39;org.tboox:gradle-xmake-plugin:1.0.9&#39;
  220. }
  221. repositories {
  222. mavenCentral()
  223. }
  224. }
  225. apply plugin: "org.tboox.gradle-xmake-plugin"
  226. </code></pre><h3 id="simplestexample">Simplest Example</h3>
  227. <p>We add <code>xmake.lua</code> to <code>projectdir/jni/xmake.lua</code> and enable xmake in build.gradle.</p>
  228. <h4 id="buildgradle">build.gradle</h4>
  229. <pre><code>android {
  230. externalNativeBuild {
  231. xmake {
  232. path "jni/xmake.lua"
  233. }
  234. }
  235. }
  236. </code></pre><h4 id="jni">JNI</h4>
  237. <p>The JNI project structure:</p>
  238. <pre><code>projectdir
  239. - src
  240. - main
  241. - java
  242. - jni
  243. - xmake.lua
  244. - *.cpp
  245. </code></pre><p>xmake.lua:</p>
  246. <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
  247. target("nativelib")
  248. set_kind("shared")
  249. add_files("nativelib.cc")
  250. </code></pre>
  251. <h3 id="moregradleconfiguations">More Gradle Configuations</h3>
  252. <pre><code>android {
  253. defaultConfig {
  254. externalNativeBuild {
  255. xmake {
  256. // append the global cflags (optional)
  257. cFlags "-DTEST"
  258. // append the global cppflags (optional)
  259. cppFlags "-DTEST", "-DTEST2"
  260. // switch the build mode to `debug` for `xmake f -m debug` (optional)
  261. buildMode "debug"
  262. // set abi filters (optional), e.g. armeabi, armeabi-v7a, arm64-v8a, x86, x86_64
  263. // we can also get abiFilters from defaultConfig.ndk.abiFilters
  264. abiFilters "armeabi-v7a", "arm64-v8a"
  265. }
  266. }
  267. }
  268. externalNativeBuild {
  269. xmake {
  270. // enable xmake and set xmake.lua project file path
  271. path "jni/xmake.lua"
  272. // enable verbose output (optional), e.g. verbose, warning, normal
  273. logLevel "verbose"
  274. // set c++stl (optional), e.g. c++_static/c++_shared, gnustl_static/gnustl_shared, stlport_static/stlport_shared
  275. stl "c++_shared"
  276. // set the given xmake program path (optional)
  277. // program /usr/local/bin/xmake
  278. // disable stdc++ library (optional)
  279. // stdcxx false
  280. // set the given ndk directory path (optional)
  281. // ndk "/Users/ruki/files/android-ndk-r20b/"
  282. // set sdk version of ndk (optional)
  283. // sdkver 21
  284. }
  285. }
  286. }
  287. </code></pre><h3 id="buildjniandgenerateapk">Build JNI and generate apk</h3>
  288. <p>The <code>xmakeBuild</code> will be injected to <code>assemble</code> task automatically if the gradle-xmake-plugin has been applied.</p>
  289. <pre><code class="lang-console">$ ./gradlew app:assembleDebug
  290. > Task :nativelib:xmakeConfigureForArm64
  291. > Task :nativelib:xmakeBuildForArm64
  292. >> xmake build
  293. [ 50%]: cache compiling.debug nativelib.cc
  294. [ 75%]: linking.debug libnativelib.so
  295. [100%]: build ok!
  296. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a
  297. > Task :nativelib:xmakeConfigureForArmv7
  298. > Task :nativelib:xmakeBuildForArmv7
  299. >> xmake build
  300. [ 50%]: cache compiling.debug nativelib.cc
  301. [ 75%]: linking.debug libnativelib.so
  302. [100%]: build ok!
  303. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a
  304. > Task :nativelib:preBuild
  305. > Task :nativelib:assemble
  306. > Task :app:assembleDebug
  307. </code></pre>
  308. <h3 id="forcetorebuildjni">Force to rebuild JNI</h3>
  309. <pre><code class="lang-console">$ ./gradlew nativelib:xmakeRebuild
  310. </code></pre>
  311. </article>
  312. </body>
  313. </html>