more_plugins.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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="improvethedevelopmentexperiencewithlsp">Improve the development experience with LSP</h3>
  110. <p>For a better C++ intellisense experience, xmake provides support for <a href="https://microsoft.github.io/language-server-protocol/">Language Server Protocol</a> (LSP for short). In vscode, you can use the >XMake: UpdateIntellisense command to generate .vscode/compile_commands.json (usually when modifying xmake.lua, this file will be generated automatically). At the same time, we can choose to install a intellisense plug-in that supports LSP, such as <a href="https://clangd.llvm.org/">clangd</a> published by LLVM, which is stable and efficient, and support different tool-chain through the LSP standard.</p>
  111. <p>When using clangd, there may be conflicts with the C/C++ plug-in, you can add settings in .vscode/settings.json: </p>
  112. <pre><code>{
  113. "C_Cpp.codeAnalysis.runAutomatically": false,
  114. "C_Cpp.intelliSenseEngine": "Disabled",
  115. "C_Cpp.formatting": "Disabled",
  116. "C_Cpp.autoAddFileAssociations": false,
  117. "C_Cpp.autocompleteAddParentheses": false,
  118. "C_Cpp.autocomplete": "Disabled",
  119. "C_Cpp.errorSquiggles": "Disabled",
  120. ...
  121. }
  122. </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>
  123. <pre><code>{
  124. "clangd.arguments": [
  125. "--compile-commands-dir=.vscode",
  126. ...
  127. ]
  128. ...
  129. }
  130. </code></pre><h2 id="sublimeplugin">Sublime Plugin</h2>
  131. <ul>
  132. <li><a href="https://github.com/xmake-io/xmake-sublime">xmake-sublime</a></li>
  133. </ul>
  134. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-sublime/master/res/problem.gif" width="650px" /></p>
  135. <h2 id="intellijideaclionpluin">Intellij IDEA/Clion Pluin</h2>
  136. <ul>
  137. <li><a href="https://github.com/xmake-io/xmake-idea">xmake-idea</a></li>
  138. </ul>
  139. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-idea/master/res/problem.gif" width="650px" /></p>
  140. <h2 id="vimplugin">Vim Plugin</h2>
  141. <ul>
  142. <li><a href="https://github.com/luzhlon/xmake.vim">xmake.vim</a> (third-party, thanks <a href="https://github.com/luzhlon">@luzhlon</a>)</li>
  143. </ul>
  144. <h2 id="gradlepluginjni">Gradle Plugin (JNI)</h2>
  145. <ul>
  146. <li><a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a>: A gradle plugin that integrates xmake seamlessly</li>
  147. </ul>
  148. <h3 id="pluginsdsl">plugins DSL</h3>
  149. <pre><code>plugins {
  150. id &#39;org.tboox.gradle-xmake-plugin&#39; version &#39;1.0.9&#39;
  151. }
  152. </code></pre><h3 id="legacypluginapplication">Legacy plugin application</h3>
  153. <pre><code>buildscript {
  154. repositories {
  155. maven {
  156. url "https://plugins.gradle.org/m2/"
  157. }
  158. }
  159. dependencies {
  160. classpath &#39;org.tboox:gradle-xmake-plugin:1.0.9&#39;
  161. }
  162. repositories {
  163. mavenCentral()
  164. }
  165. }
  166. apply plugin: "org.tboox.gradle-xmake-plugin"
  167. </code></pre><h3 id="simplestexample">Simplest Example</h3>
  168. <p>We add <code>xmake.lua</code> to <code>projectdir/jni/xmake.lua</code> and enable xmake in build.gradle.</p>
  169. <h4 id="buildgradle">build.gradle</h4>
  170. <pre><code>android {
  171. externalNativeBuild {
  172. xmake {
  173. path "jni/xmake.lua"
  174. }
  175. }
  176. }
  177. </code></pre><h4 id="jni">JNI</h4>
  178. <p>The JNI project structure:</p>
  179. <pre><code>projectdir
  180. - src
  181. - main
  182. - java
  183. - jni
  184. - xmake.lua
  185. - *.cpp
  186. </code></pre><p>xmake.lua:</p>
  187. <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
  188. target("nativelib")
  189. set_kind("shared")
  190. add_files("nativelib.cc")
  191. </code></pre>
  192. <h3 id="moregradleconfiguations">More Gradle Configuations</h3>
  193. <pre><code>android {
  194. defaultConfig {
  195. externalNativeBuild {
  196. xmake {
  197. // append the global cflags (optional)
  198. cFlags "-DTEST"
  199. // append the global cppflags (optional)
  200. cppFlags "-DTEST", "-DTEST2"
  201. // switch the build mode to `debug` for `xmake f -m debug` (optional)
  202. buildMode "debug"
  203. // set abi filters (optional), e.g. armeabi, armeabi-v7a, arm64-v8a, x86, x86_64
  204. // we can also get abiFilters from defaultConfig.ndk.abiFilters
  205. abiFilters "armeabi-v7a", "arm64-v8a"
  206. }
  207. }
  208. }
  209. externalNativeBuild {
  210. xmake {
  211. // enable xmake and set xmake.lua project file path
  212. path "jni/xmake.lua"
  213. // enable verbose output (optional), e.g. verbose, warning, normal
  214. logLevel "verbose"
  215. // set c++stl (optional), e.g. c++_static/c++_shared, gnustl_static/gnustl_shared, stlport_static/stlport_shared
  216. stl "c++_shared"
  217. // set the given xmake program path (optional)
  218. // program /usr/local/bin/xmake
  219. // disable stdc++ library (optional)
  220. // stdcxx false
  221. // set the given ndk directory path (optional)
  222. // ndk "/Users/ruki/files/android-ndk-r20b/"
  223. // set sdk version of ndk (optional)
  224. // sdkver 21
  225. }
  226. }
  227. }
  228. </code></pre><h3 id="buildjniandgenerateapk">Build JNI and generate apk</h3>
  229. <p>The <code>xmakeBuild</code> will be injected to <code>assemble</code> task automatically if the gradle-xmake-plugin has been applied.</p>
  230. <pre><code class="lang-console">$ ./gradlew app:assembleDebug
  231. > Task :nativelib:xmakeConfigureForArm64
  232. > Task :nativelib:xmakeBuildForArm64
  233. >> xmake build
  234. [ 50%]: cache compiling.debug nativelib.cc
  235. [ 75%]: linking.debug libnativelib.so
  236. [100%]: build ok!
  237. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a
  238. > Task :nativelib:xmakeConfigureForArmv7
  239. > Task :nativelib:xmakeBuildForArmv7
  240. >> xmake build
  241. [ 50%]: cache compiling.debug nativelib.cc
  242. [ 75%]: linking.debug libnativelib.so
  243. [100%]: build ok!
  244. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a
  245. > Task :nativelib:preBuild
  246. > Task :nativelib:assemble
  247. > Task :app:assembleDebug
  248. </code></pre>
  249. <h3 id="forcetorebuildjni">Force to rebuild JNI</h3>
  250. <pre><code class="lang-console">$ ./gradlew nativelib:xmakeRebuild
  251. </code></pre>
  252. </article>
  253. </body>
  254. </html>