| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>xmake</title>
- <link rel="icon" href="/assets/img/favicon.ico">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
- <meta name="description" content="Description">
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
- <style>
- .markdown-body {
- box-sizing: border-box;
- min-width: 200px;
- max-width: 980px;
- margin: 0 auto;
- padding: 45px;
- }
- @media (max-width: 767px) {
- .markdown-body {
- padding: 15px;
- }
- }
- </style>
- </head>
- <body>
- <article class="markdown-body">
- <h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/zh-cn/features/remote_build">https://xmake.io/#/zh-cn/features/remote_build</a>
- <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>
- </br>
- <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
- <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
- <style>
- #carbonads {
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
- Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
- }
- #carbonads {
- display: flex;
- max-width: 330px;
- background-color: hsl(0, 0%, 98%);
- box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
- }
- #carbonads a {
- color: inherit;
- text-decoration: none;
- }
- #carbonads a:hover {
- color: inherit;
- }
- #carbonads span {
- position: relative;
- display: block;
- overflow: hidden;
- }
- #carbonads .carbon-wrap {
- display: flex;
- }
- .carbon-img {
- display: block;
- margin: 0;
- line-height: 1;
- }
- .carbon-img img {
- display: block;
- }
- .carbon-text {
- font-size: 13px;
- padding: 10px;
- line-height: 1.5;
- text-align: left;
- }
- .carbon-poweredby {
- display: block;
- padding: 8px 10px;
- 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);
- text-align: center;
- text-transform: uppercase;
- letter-spacing: .5px;
- font-weight: 600;
- font-size: 9px;
- line-height: 1;
- }
- </style>
- <p>2.6.5 版本提供了远程编译支持,我们可以通过它可以远程服务器上编译代码,远程运行和调试。</p>
- <p>服务器可以部署在 Linux/MacOS/Windows 上,实现跨平台编译,例如:在 Linux 上编译运行 Windows 程序,在 Windows 上编译运行 macOS/Linux 程序。</p>
- <p>相比 ssh 远程登入编译,它更加的稳定,使用更加流畅,不会因为网络不稳定导致 ssh 终端输入卡顿,也可以实现本地快速编辑代码文件。</p>
- <p>甚至我们可以在 vs/sublime/vscode/idea 等编辑器和IDE 中无缝实现远程编译,而不需要依赖 IDE 本身对远程编译的支持力度。</p>
- <h3 id="">开启服务</h3>
- <pre><code class="lang-console">$ xmake service
- <remote_build_server>: listening 0.0.0.0:9091 ..
- </code></pre>
- <p>我们也可以开启服务的同时,回显详细日志信息。</p>
- <pre><code class="lang-console">$ xmake service -vD
- <remote_build_server>: listening 0.0.0.0:9091 ..
- </code></pre>
- <h3 id="daemon">以 Daemon 模式开启服务</h3>
- <pre><code class="lang-console">$ xmake service --start
- $ xmake service --restart
- $ xmake service --stop
- </code></pre>
- <h3 id="">配置服务端</h3>
- <p>我们首先,运行 <code>xmake service</code> 命令,它会自动生成一个默认的 <code>server.conf</code> 配置文件,存储到 <code>~/.xmake/service/server.conf</code>。</p>
- <p>!> 2.6.5 版本,配置地址在 <code>~/.xmake/service.conf</code>,后续版本做了大量改进,分离了配置文件,如果用的是 2.6.6 以上版本,请使用新的配置文件。</p>
- <p>然后,我们编辑它,修复服务器的监听端口(可选)。</p>
- <pre><code class="lang-bash">$ cat ~/.xmake/service/server.conf
- {
- known_hosts = { },
- logfile = "/Users/ruki/.xmake/service/server/logs.txt",
- remote_build = {
- listen = "0.0.0.0:9691",
- workdir = "/Users/ruki/.xmake/service/server/remote_build"
- },
- tokens = {
- "e438d816c95958667747c318f1532c0f"
- }
- }
- </code></pre>
- <h3 id="">配置客户端</h3>
- <p>客户端配置文件在 <code>~/.xmake/service/client.conf</code>,我们可以在里面配置客户端需要连接的服务器地址。</p>
- <p>!> 2.6.5 版本,配置地址在 <code>~/.xmake/service.conf</code>,后续版本做了大量改进,分离了配置文件,如果用的是 2.6.6 以上版本,请使用新的配置文件。</p>
- <pre><code class="lang-console">$ cat ~/.xmake/service/client.conf
- {
- remote_build = {
- connect = "127.0.0.1:9691",
- token = "e438d816c95958667747c318f1532c0f"
- }
- }
- </code></pre>
- <h3 id="">用户认证和授权</h3>
- <p>!> 2.6.6 以上版本才支持用户认证,2.6.5 版本只能匿名连接。</p>
- <p>在实际连接之前,我们简单介绍下 xmake 提供的服务目前提供的几种认证机制。</p>
- <ol>
- <li>Token 认证</li>
- <li>密码认证</li>
- <li>可信主机验证</li>
- </ol>
- <h4 id="token">Token 认证</h4>
- <p>这也是我们默认推荐的方式,更加安全,配置和连接也更加方便,每次连接也不用输入密码。</p>
- <p>我们在执行 <code>xmake service</code> 命令时候,默认就会生成一个服务端和客户端的配置文件,并且自动生成一个默认的 token,因此本地直连是不需要任何配置的。</p>
- <h5 id="">服务端认证配置</h5>
- <p>服务端可以配置多个 token 用于对不同用户主机进行授权连接,当然也可以共用一个 token。</p>
- <pre><code class="lang-bash">$ cat ~/.xmake/service/server.conf
- {
- known_hosts = { },
- logfile = "/Users/ruki/.xmake/service/server/logs.txt",
- remote_build = {
- listen = "0.0.0.0:9691",
- workdir = "/Users/ruki/.xmake/service/server/remote_build"
- },
- tokens = {
- "e438d816c95958667747c318f1532c0f"
- }
- }
- </code></pre>
- <h5 id="">客户端认证配置</h5>
- <p>客户端只需要添加服务器上的 token 到对应的客户端配置中即可。</p>
- <pre><code class="lang-bash">$ cat ~/.xmake/service/client.conf
- {
- remote_build = {
- connect = "127.0.0.1:9691",
- token = "e438d816c95958667747c318f1532c0f"
- }
- }
- </code></pre>
- <h5 id="token">手动生成新 token</h5>
- <p>我们也可以执行下面的命令,手动生成一个新的 token,自己添加到服务器配置中。</p>
- <pre><code class="lang-bash">$ xmake service --gen-token
- New token a7b9fc2d3bfca1472aabc38bb5f5d612 is generated!
- </code></pre>
- <h4 id="">密码认证</h4>
- <p>我们也提供密码认证的授权模式,相比 token 认证,它需要用户每次连接的时候,输入密码,验证通过后,才能连接上。</p>
- <h5 id="">服务端认证配置</h5>
- <p>密码认证,我们不需要手动配置 token,只需要执行下面的命令,添加用户就行了,添加过程中,会提示用户输入密码。</p>
- <pre><code class="lang-bash">$ xmake service --add-user=ruki
- Please input user ruki password:
- 123456
- Add user ruki ok!
- </code></pre>
- <p>然后,xmake 就会通过用户名,密码生成一个新的 token 添加到服务器配置的 token 列表中去。</p>
- <pre><code class="lang-bash">$ cat ~/.xmake/service/server.conf
- {
- known_hosts = { },
- logfile = "/Users/ruki/.xmake/service/server/logs.txt",
- remote_build = {
- listen = "0.0.0.0:9691",
- workdir = "/Users/ruki/.xmake/service/server/remote_build"
- },
- tokens = {
- "e438d816c95958667747c318f1532c0f",
- "7889e25402413e93fd37395a636bf942"
- }
- }
- </code></pre>
- <p>当然,我们也可以删除指定的用户和密码。</p>
- <pre><code class="lang-bash">$xmake service --rm-user=ruki
- Please input user ruki password:
- 123456
- Remove user ruki ok!
- </code></pre>
- <h5 id="">客户端认证配置</h5>
- <p>对于客户端,我们不再需要设置服务器的 token 了,只需要在连接配置中,追加需要连接的用户名即可开启密码认证,格式:<code>user@address:port</code></p>
- <pre><code class="lang-bash">$ cat ~/.xmake/service/client.conf
- {
- remote_build = {
- connect = "[email protected]:9691"
- }
- }
- </code></pre>
- <p>!> 如果去掉用户名,也没配置 token,那就是匿名模式,如果服务器也没配置 token,就是完全禁用认证,直接连接。</p>
- <h4 id="">可信主机验证</h4>
- <p>另外,为了更进一步提高安全性,我们还提供了服务端可信主机验证,如果在服务器配置的 known_hosts 列表中,配置了可以连接的客户端主机 ip 地址,<br>那么只有这些主机可以成功连接上这台服务器,其他主机对它的连接都会被提示为不可信而拒绝连接,即使 token 和密码认证都没问题也不行。</p>
- <pre><code class="lang-bash">$ cat ~/.xmake/service/server.conf
- {
- logfile = "/Users/ruki/.xmake/service/logs.txt",
- server = {
- tokens = {
- "4b928c7563a0cba10ff4c3f5ca0c8e24"
- },
- known_hosts = { "127.0.0.1", "xx.xx.xx.xx"}
- }
- }
- </code></pre>
- <h3 id="">连接远程的服务器</h3>
- <p>接下来,我们只需要进入需要远程编译的工程根目录,执行 <code>xmake service --connect</code> 命令,进行连接。</p>
- <p>如果是 token 认证模式,那么不需要的额外的密码输入,直接连接。</p>
- <pre><code class="lang-console">$ xmake create test
- $ cd test
- $ xmake service --connect
- <remote_build_client>: connect 192.168.56.110:9091 ..
- <remote_build_client>: connected!
- <remote_build_client>: sync files in 192.168.56.110:9091 ..
- Scanning files ..
- Comparing 3 files ..
- [+]: src/main.cpp
- [+]: .gitignore
- [+]: xmake.lua
- 3 files has been changed!
- Archiving files ..
- Uploading files with 1372 bytes ..
- <remote_build_client>: sync files ok!
- </code></pre>
- <p>如果是密码认证,那么会提示用户输入密码,才能继续连接。</p>
- <pre><code class="lang-bash">$ xmake service --connect
- Please input user root password:
- 000000
- <remote_build_client>: connect 127.0.0.1:9691 ..
- <remote_build_client>: connected!
- <remote_build_client>: sync files in 127.0.0.1:9691 ..
- Scanning files ..
- Comparing 3 files ..
- [+]: xmake.lua
- [+]: .gitignore
- [+]: src/main.cpp
- 3 files has been changed!
- Archiving files ..
- Uploading files with 1591 bytes ..
- <remote_build_client>: sync files ok!
- </code></pre>
- <p>如果密码不对,就会提示错误。</p>
- <pre><code class="lang-bash">$ xmake service --connect
- Please input user root password:
- 123
- <remote_build_client>: connect 127.0.0.1:9691 ..
- <remote_build_client>: connect 127.0.0.1:9691 failed, user and password are incorrect!
- </code></pre>
- <h3 id="">远程构建工程</h3>
- <p>连接成功后,我们就可以像正常本地编译一样,进行远程编译。</p>
- <pre><code class="lang-console">$ xmake
- <remote_build_client>: run xmake in 192.168.56.110:9091 ..
- checking for platform ... macosx
- checking for architecture ... x86_64
- checking for Xcode directory ... /Applications/Xcode.app
- checking for Codesign Identity of Xcode ... Apple Development: [email protected] (T3NA4MRVPU)
- checking for SDK version of Xcode for macosx (x86_64) ... 11.3
- checking for Minimal target version of Xcode for macosx (x86_64) ... 11.4
- [ 25%]: cache compiling.release src/main.cpp
- [ 50%]: linking.release test
- [100%]: build ok!
- <remote_build_client>: run command ok!
- </code></pre>
- <h3 id="">远程运行目标程序</h3>
- <p>我们也可以像本地运行调试那样,远程运行调试编译的目标程序。</p>
- <pre><code class="lang-console">$ xmake run
- <remote_build_client>: run xmake run in 192.168.56.110:9091 ..
- hello world!
- <remote_build_client>: run command ok!
- </code></pre>
- <h3 id="">远程重建工程</h3>
- <pre><code class="lang-console">$ xmake -rv
- <remote_build_client>: run xmake -rv in 192.168.56.110:9091 ..
- [ 25%]: cache compiling.release src/main.cpp
- /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
- [ 50%]: linking.release test
- "/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
- [100%]: build ok!
- <remote_build_client>: run command ok!
- </code></pre>
- <h3 id="">远程配置编译参数</h3>
- <pre><code class="lang-console">$ xmake f --xxx --yy
- </code></pre>
- <h3 id="">手动同步工程文件</h3>
- <p>连接的时候,会自动同步一次代码,后期代码改动,可以执行此命令来手动同步改动的文件。</p>
- <pre><code class="lang-console">$ xmake service --sync
- <remote_build_client>: sync files in 192.168.56.110:9091 ..
- Scanning files ..
- Comparing 3 files ..
- [+]: src/main.cpp
- [+]: .gitignore
- [+]: xmake.lua
- 3 files has been changed!
- Archiving files ..
- Uploading files with 1372 bytes ..
- <remote_build_client>: sync files ok!
- </code></pre>
- <h3 id="">拉取远程文件</h3>
- <p>v2.7.1 版本我们新增了一个参数用于拉取远程指定的文件,通常我们可以用来完成构建后目标文件的拉取,将编译后的库文件下载到本地。</p>
- <p>例如:</p>
- <pre><code class="lang-bash">xmake service --pull 'build/**' outputdir
- </code></pre>
- <p>我们可以指定远程路径 <code>build/**</code> ,将所有匹配的文件全部拉取到本地 outputdir 目录下。</p>
- <h3 id="">断开远程连接</h3>
- <p>针对当前工程,断开连接,这仅仅影响当前工程,其他项目还是可以同时连接和编译。</p>
- <pre><code class="lang-console">$ xmake service --disconnect
- <remote_build_client>: disconnect 192.168.56.110:9091 ..
- <remote_build_client>: disconnected!
- </code></pre>
- <h3 id="">查看服务器日志</h3>
- <pre><code class="lang-console">$ xmake service --logs
- </code></pre>
- <h3 id="">清理远程服务缓存和构建文件</h3>
- <p>我们也可以手动清理远程的任何缓存和构建生成的文件。</p>
- <pre><code class="lang-console">$ cd projectdir
- $ xmake service --clean
- </code></pre>
- </article>
- </body>
- </html>
|