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.
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.
评论:
patrickdappollonio:
vortexman100: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?
martindo: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...
Spirit_of_Stallman:Why would you want to distribute them all together? Why not offer a download per platform?
oakes:case "$(uname -m)" in 'armv6l') executable='prog.arm6' ;; 'x86_64') executable='prog.amd64' ;;
* ) echo "unknown arch ($(uname -m))"; exit; ;;
esac
But I think that to distribute all-in-one archive it is not the right way.
stone_henge:Thanks, looks like that's what I need to do. And I can run
uname -s
to get the system.
PaluMacil: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.
x86_64
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.
