Using a bash script to run the correct Go binary for your OS / CPU

xuanbao · · 490 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m writing a console program and intend on taking advantage of Go&#39;s cross compilation to create a binary for every OS and CPU architecture it supports. Ideally, I&#39;d like to distribute them all in an archive that includes a bash script that my users will run. The script should just choose the correct binary to run for the given system.</p> <p>Does anyone have a working example of such a script? I can&#39;t imagine I&#39;m the first to want to do this, but my search has turned up nothing.</p> <hr/>**评论:**<br/><br/>patrickdappollonio: <pre><p>As an end user I would definitely prefer if I just have to download my own copy for my own platform. Why should I download a &#34;.exe&#34; file when I&#39;m on a Mac?</p></pre>vortexman100: <pre><p>Its not that, Linux is the problem. Best way would be an installer based around this script. On Linux you have more Archs than Mac...</p></pre>martindo: <pre><p>Why would you want to distribute them all together? Why not offer a download per platform?</p></pre>Spirit_of_Stallman: <pre><pre><code>case &#34;$(uname -m)&#34; in &#39;armv6l&#39;) executable=&#39;prog.arm6&#39; ;; &#39;x86_64&#39;) executable=&#39;prog.amd64&#39; ;; * ) echo &#34;unknown arch ($(uname -m))&#34;; exit; ;; esac </code></pre> <p>But I think that to distribute all-in-one archive it is not the right way.</p></pre>oakes: <pre><p>Thanks, looks like that&#39;s what I need to do. And I can run <code>uname -s</code> to get the system.</p></pre>stone_henge: <pre><p>There&#39;s a huge caveat here if you actually intend to cover every platform that Go supports: The OS may not be POSIX compliant, lacking the uname command or the flags you require. It may also lack bash or any sh compatible shell. Particularly, this could be true for Windows and (less likely) Linux+glibc.</p></pre>PaluMacil: <pre><blockquote> <p>x86_64</p> </blockquote> <p>I sorta feel that anyone not running x86_64 would know enough to know exactly what they needed, so I agree with your thoughts, but wish the OP best of luck on this. :) I suppose there could be a lot of inexperienced users on Raspberry Pi&#39;s as well, though then they&#39;ll care more about wasted space.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

490 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传