<p>I'm writing a console program and intend on taking advantage of Go's cross compilation to create a binary for every OS and CPU architecture it supports. Ideally, I'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't imagine I'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 ".exe" file when I'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 "$(uname -m)" in
'armv6l') executable='prog.arm6' ;;
'x86_64') executable='prog.amd64' ;;
* ) echo "unknown arch ($(uname -m))"; 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'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'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's as well, though then they'll care more about wasted space.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传