remote_build.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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/#/features/remote_build">https://xmake.io/#/features/remote_build</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. <h1 id="remotebuilding">Remote building</h1>
  86. <p>Version 2.6.5 provides remote compilation support, through which we can compile code on a remote server, run and debug remotely. The server can be deployed on Linux/MacOS/Windows to achieve cross-platform compilation, for example: compile and run Windows programs on Linux, and compile and run macOS/Linux programs on Windows.</p>
  87. <p>Compared with ssh remote login and compilation, it is more stable and smoother to use. It will not cause ssh terminal input to be stuck due to network instability, and it can also quickly edit code files locally. Even we can seamlessly implement remote compilation in editors and IDEs such as vs/sublime/vscode/idea without relying on the IDE&#39;s own support for remote compilation.</p>
  88. <h2 id="starttheservice">Start the service</h2>
  89. <pre><code class="lang-bash">$ xmake service
  90. <remote_build_server>: listening 0.0.0.0:9091 ..
  91. </code></pre>
  92. <p>We can also start the service and echo detailed log information.</p>
  93. <pre><code class="lang-bash">$ xmake service -vD
  94. <remote_build_server>: listening 0.0.0.0:9091 ..
  95. </code></pre>
  96. <h3 id="starttheserviceindaemonmode">Start the service in Daemon mode</h3>
  97. <p>To start and control the service when in daemon mode, you can issue the following commands:</p>
  98. <pre><code class="lang-bash">$ xmake service --start
  99. $ xmake service --restart
  100. $ xmake service --stop
  101. </code></pre>
  102. <h3 id="configuretheserver">Configure the server</h3>
  103. <p>We first, run the <code>xmake service</code> command, it will automatically generate a default <code>server.conf</code> configuration file, stored in <code>~/.xmake/service/server.conf</code>.</p>
  104. <p>!> Version 2.6.5, the configuration address is in <code>~/.xmake/service.conf</code>. Subsequent versions have made a lot of improvements and separated the configuration file. If you are using version 2.6.6 or above, please use the new configuration file.</p>
  105. <p>Then, we edit it, fixing the server&#39;s listening port (optional).</p>
  106. <pre><code class="lang-bash">{
  107. known_hosts = { },
  108. logfile = "/Users/ruki/.xmake/service/server/logs.txt",
  109. remote_build = {
  110. listen = "0.0.0.0:9691",
  111. workdir = "/Users/ruki/.xmake/service/server/remote_build"
  112. },
  113. tokens = {
  114. "e438d816c95958667747c318f1532c0f"
  115. }
  116. }
  117. </code></pre>
  118. <h3 id="configuretheclient">Configure the client</h3>
  119. <p>The client configuration file is in <code>~/.xmake/service/client.conf</code>, where we can configure the server address that the client needs to connect to.</p>
  120. <p>!> Version 2.6.5, the configuration address is in <code>~/.xmake/service.conf</code>. Subsequent versions have made a lot of improvements and separated the configuration file. If you are using version 2.6.6 or above, please use the new configuration file.</p>
  121. <pre><code class="lang-bash">{
  122. remote_build = {
  123. connect = "127.0.0.1:9691",
  124. token = "e438d816c95958667747c318f1532c0f"
  125. }
  126. }
  127. </code></pre>
  128. <h3 id="userauthorization">User authorization</h3>
  129. <p>!> Version 2.6.6 and above supports user authentication; version 2.6.5 can only connect anonymously.</p>
  130. <p>Before the actual connection, we briefly introduce several authentication mechanisms currently provided by the services provided by Xmake.</p>
  131. <ol>
  132. <li>Token authentication</li>
  133. <li>Password authentication</li>
  134. <li>Trusted host verification</li>
  135. </ol>
  136. <h4 id="tokenauthentication">Token Authentication</h4>
  137. <p>This is also the default recommended method, which is more secure, more convenient to configure and connect, and does not need to enter a password every time you connect. When we execute the <code>xmake service</code> command, a server and client configuration file will be generated by default, and a default token will be automatically generated, so the local direct connection does not require any configuration.</p>
  138. <h5 id="serverauthenticationconfiguration">Server authentication configuration</h5>
  139. <p>The server can configure multiple tokens for authorizing connections to different user hosts, and of course, can share one token.</p>
  140. <pre><code class="lang-bash">{
  141. known_hosts = { },
  142. logfile = "/Users/ruki/.xmake/service/server/logs.txt",
  143. remote_build = {
  144. listen = "0.0.0.0:9691",
  145. workdir = "/Users/ruki/.xmake/service/server/remote_build"
  146. },
  147. tokens = {
  148. "e438d816c95958667747c318f1532c0f"
  149. }
  150. }
  151. </code></pre>
  152. <h5 id="clientauthenticationconfiguration">Client Authentication Configuration</h5>
  153. <p>The client only needs to add the token on the server to the corresponding client configuration.</p>
  154. <pre><code class="lang-bash">{
  155. remote_build = {
  156. connect = "127.0.0.1:9691",
  157. token = "e438d816c95958667747c318f1532c0f"
  158. }
  159. }
  160. </code></pre>
  161. <h5 id="manuallygeneratenewtoken">Manually generate new token</h5>
  162. <p>We can also execute the following command to manually generate a new token and add it to the server configuration ourselves.</p>
  163. <pre><code class="lang-bash">$ xmake service --gen-token
  164. New token a7b9fc2d3bfca1472aabc38bb5f5d612 is generated!
  165. </code></pre>
  166. <h4 id="passwordauthentication">Password authentication</h4>
  167. <p>We also provide an authorization mode of password authentication. Compared with token authentication, it requires users to enter a password every time they connect, and can only be connected after the verification is passed.</p>
  168. <h5 id="serverauthenticationconfiguration">Server authentication configuration</h5>
  169. <p>For password authentication, we do not need to manually configure the token, just execute the following command to add a user. During the adding process, the user will be prompted to enter a password.</p>
  170. <pre><code class="lang-bash">$ xmake service --add-user=ruki
  171. Please input user ruki password:
  172. 123456
  173. Add user ruki ok!
  174. </code></pre>
  175. <p>Then, Xmake will generate a new token from the username and password and add it to the token list of the server configuration.</p>
  176. <pre><code class="lang-bash">{
  177. known_hosts = { },
  178. logfile = "/Users/ruki/.xmake/service/server/logs.txt",
  179. remote_build = {
  180. listen = "0.0.0.0:9691",
  181. workdir = "/Users/ruki/.xmake/service/server/remote_build"
  182. },
  183. tokens = {
  184. "e438d816c95958667747c318f1532c0f",
  185. "7889e25402413e93fd37395a636bf942"
  186. }
  187. }
  188. </code></pre>
  189. <p>Of course, we can also delete the specified user and password.</p>
  190. <pre><code class="lang-bash">$ xmake service --rm-user=ruki
  191. Please input user ruki password:
  192. 123456
  193. Remove user ruki ok!
  194. </code></pre>
  195. <h5 id="clientauthenticationconfiguration">Client Authentication Configuration</h5>
  196. <p>For the client, we no longer need to set the token of the server. We only need to add the user name that needs to be connected in the connection configuration to enable password authentication. The format is: <code>user@address:port</code></p>
  197. <pre><code class="lang-bash">{
  198. remote_build = {
  199. connect = "[email protected]:9691"
  200. }
  201. }
  202. </code></pre>
  203. <p>!> If the username is removed and the token is not configured, it is anonymous mode. If the server is not configured with a token, the authentication is completely disabled and the connection is made directly.</p>
  204. <h4 id="trustedhostverification">Trusted host verification</h4>
  205. <p>In addition, in order to further improve security, we also provide server-side trusted host verification. If the server-configured <code>known_hosts</code> list is configured with the ip address of the client host that can be connected,<br>Then only these hosts can successfully connect to this server, and other host&#39;s connections to it will be prompted to be untrusted and refuse the connection, even if token and password authentication are OK.</p>
  206. <pre><code class="lang-bash">{
  207. logfile = "/Users/ruki/.xmake/service/logs.txt",
  208. server = {
  209. tokens = {
  210. "4b928c7563a0cba10ff4c3f5ca0c8e24"
  211. },
  212. known_hosts = { "127.0.0.1", "xx.xx.xx.xx"}
  213. }
  214. }
  215. </code></pre>
  216. <h3 id="connecttoaremoteserver">Connect to a remote server</h3>
  217. <p>Next, we only need to enter the root directory of the project that needs to be compiled remotely, and execute the <code>xmake service --connect</code> command to connect.</p>
  218. <p>If it is the token authentication mode, then no additional password input is required, and the connection is directly connected.</p>
  219. <pre><code class="lang-bash">$ xmake create test
  220. $ cd test
  221. $ xmake service --connect
  222. <remote_build_client>: connect 192.168.56.110:9091 ..
  223. <remote_build_client>: connected!
  224. <remote_build_client>: sync files in 192.168.56.110:9091 ..
  225. Scanning files ..
  226. Comparing 3 files ..
  227. [+]: src/main.cpp
  228. [+]: .gitignore
  229. [+]: xmake.lua
  230. 3 files has been changed!
  231. Archiving files ..
  232. Uploading files with 1372 bytes ..
  233. <remote_build_client>: sync files ok!
  234. </code></pre>
  235. <p>If it is password authentication, the user will be prompted to enter the password to continue the connection.</p>
  236. <pre><code class="lang-bash">$ xmake service --connect
  237. Please input user root password:
  238. 000000
  239. <remote_build_client>: connect 127.0.0.1:9691 ..
  240. <remote_build_client>: connected!
  241. <remote_build_client>: sync files in 127.0.0.1:9691 ..
  242. Scanning files ..
  243. Comparing 3 files ..
  244. [+]: xmake.lua
  245. [+]: .gitignore
  246. [+]: src/main.cpp
  247. 3 files has been changed!
  248. Archiving files ..
  249. Uploading files with 1591 bytes ..
  250. <remote_build_client>: sync files ok!
  251. </code></pre>
  252. <p>If the password is incorrect, an error message will be displayed.</p>
  253. <pre><code class="lang-bash">$ xmake service --connect
  254. Please input user root password:
  255. 123
  256. <remote_build_client>: connect 127.0.0.1:9691 ..
  257. <remote_build_client>: connect 127.0.0.1:9691 failed, user and password are incorrect!
  258. </code></pre>
  259. <h3 id="remotebuildproject">Remote build project</h3>
  260. <p>After the connection is successful, we can compile remotely like normal local compilation.</p>
  261. <pre><code class="lang-bash">$ xmake
  262. <remote_build_client>: run xmake in 192.168.56.110:9091 ..
  263. checking for platform... macosx
  264. checking for architecture ... x86_64
  265. checking for Xcode directory ... /Applications/Xcode.app
  266. checking for Codesign Identity of Xcode ... Apple Development: [email protected] (T3NA4MRVPU)
  267. checking for SDK version of Xcode for macosx (x86_64) ... 11.3
  268. checking for Minimal target version of Xcode for macosx (x86_64) ... 11.4
  269. [ 25%]: cache compiling.release src/main.cpp
  270. [ 50%]: linking.release test
  271. [100%]: build ok!
  272. <remote_build_client>: run command ok!
  273. </code></pre>
  274. <h3 id="runthetargetprogramremotely">Run the target program remotely</h3>
  275. <p>We can also run and debug the compiled target program remotely like running and debugging locally.</p>
  276. <pre><code class="lang-bash">$ xmake run
  277. <remote_build_client>: run xmake run in 192.168.56.110:9091 ..
  278. hello world!
  279. <remote_build_client>: run command ok!
  280. </code></pre>
  281. <h3 id="remoterebuildproject">Remote Rebuild Project</h3>
  282. <pre><code class="lang-bash">$ xmake -rv
  283. <remote_build_client>: run xmake -rv in 192.168.56.110:9091 ..
  284. [ 25%]: cache compiling.release src/main.cpp
  285. /usr/local/bin/ccache /usr/bin/xcrun -sdk macosx clang -c -Qunused-arguments -arch x86_64 -mmacosx-version-min=11.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/ MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -o build/.objs/test/macosx/x86_64/release/src/main.cpp.o src /main.cpp
  286. [ 50%]: linking.release test
  287. "/usr/bin/xcrun -sdk macosx clang++" -o build/macosx/x86_64/release/test build/.objs/test/macosx/x86_64/release/src/main.cpp.o -arch x86_64 -mmacosx-version -min=11.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -stdlib=libc++ -Wl,-x -lz
  288. [100%]: build ok!
  289. <remote_build_client>: run command ok!
  290. </code></pre>
  291. <h3 id="remoteconfigurationcompilationparameters">Remote configuration compilation parameters</h3>
  292. <pre><code class="lang-bash">$ xmake f --xxx --yy
  293. </code></pre>
  294. <h3 id="manuallysyncprojectfiles">Manually sync project files</h3>
  295. <p>When connecting, the code will be automatically synchronized once, and the code will be changed later. You can execute this command to manually synchronize the changed files.</p>
  296. <pre><code class="lang-bash">$ xmake service --sync
  297. <remote_build_client>: sync files in 192.168.56.110:9091 ..
  298. Scanning files ..
  299. Comparing 3 files ..
  300. [+]: src/main.cpp
  301. [+]: .gitignore
  302. [+]: xmake.lua
  303. 3 files has been changed!
  304. Archiving files ..
  305. Uploading files with 1372 bytes ..
  306. <remote_build_client>: sync files ok!
  307. </code></pre>
  308. <h3 id="pullremotefiles">Pull remote files</h3>
  309. <p>In version v2.7.1, we added a parameter to pull the remote specified file.<br>Usually, we can use it to pull the target file after the build and download the compiled library file to the local.</p>
  310. <p>For example:</p>
  311. <pre><code class="lang-bash">xmake service --pull &#39;build/**&#39; outputdir
  312. </code></pre>
  313. <p>We can specify the remote path <code>build/**</code> to pull all matching files to the local outputdir directory.</p>
  314. <h3 id="disconnectfromremote">Disconnect from remote</h3>
  315. <p>For the current project, disconnect the connection, which only affects the current project, and other projects can still be connected and compiled at the same time.</p>
  316. <pre><code class="lang-bash">$ xmake service --disconnect
  317. <remote_build_client>: disconnect 192.168.56.110:9091 ..
  318. <remote_build_client>: disconnected!
  319. </code></pre>
  320. <h3 id="viewserverlog">View server log</h3>
  321. <pre><code class="lang-bash">$ xmake service --logs
  322. </code></pre>
  323. <h3 id="cleanremoteservicecacheandbuildfiles">Clean remote service cache and build files</h3>
  324. <p>We can also manually clean any caches and build generated files from the remote.</p>
  325. <pre><code class="lang-bash">$ cd projectdir
  326. $ xmake service --clean
  327. </code></pre>
  328. </article>
  329. </body>
  330. </html>