Google's Go Language on the MAXI

Started by lucio, January 24, 2013, 05:40:52 PM

Previous topic - Next topic

lucio

If you're not yet familiar with Go (officially GoLang for web searches), I strongly recommend investigating it.

Go is designed for the development of scalable, multitasking applications, in a nutshell. The designers applied their combined experience and produced a language that is nice to use and, difficult to quantify as that may be, less prone to programmer error (that's my opinion, most Go programmers who are prepared to voice an opinion seem to feel the same way).

I haven't tried to build the Go distribution <golang.org> on the MAXI because it is unlikely to succeed, 64MiB is too little memory.  For those who are curious, the Go linker does much of the hard work needed for the production of good code and it needs to load sometimes very large lumps of code into memory.  This is a problem that is much more readily solved by adding memory to computers than by any other means.  The A13 and A10 modules being produced by Olimex will no doubt be better in this department.

But it is extremely easy to produce a workbench for the MAXI on any of a number of platforms: I have used Ubuntu, NetBSD and Plan 9, I know that OSX, any of the *BSDs and Windows are good candidates too.  I may be a little hesitant about Windows, it is the odd man out.

It may even be possible to build the Go workbench for the MAXI without building one for the native platform, although it seems silly to do so.  Rough instructions, from memory, are:

1. Download the Go source distribution (I use mercurial and keep the most recent, "tip", release in my hosts.  The details are on the GoLang web site.

2. Change directory to "src" within the distribution.

3. Set the following shell variables:
    export GOOS=linux
    export GOARCH=arm
    export GOARM=5
    export CGO_ENABLED=0

   The build system will figure out you are on a Linux platform, so the first may be redundant, the third is intended to make sure that the features of more advanced ARM architectures are not used and I don't think it is necessary for the build, but it does no harm. The fourth entry is specifically for the cross-build, its purpose need not concern us.

4. Bash is essential, make sure it is available, then execute the simple command: ./make.bash; it will take a few minutes and, if everything completes correctly there will be messages at the end about where the binaries have been installed for further use.  If not, then some error occurred during the build and you may want to send me the output for help.  Append the "bin" directory to your PATH, the executables in there are named pretty uniquely.  The program that does all the hard work is called, predictably, "go".  Run it with "env" as its command line argument and it will disclose its default settings.

I don't have a pristine environment to check the above, but I'm running the build on my NetBSD server as we speak (Rel 6.0 is required) and I won't send this until it completes successfully.

Building projects with Go is clever, but intentionally different from the conventional autoconf/automake hell.  You need to spend some effort learning the ropes, although trivial projects are easy to deal with.  I will not insult anyone by posting instructions for a "hello world" type program here, but as soon as I have my first I2C utility in place for the MAXI, I will provide full instructions.

Another note you may not spot immediately is that Go produces static executables.  This means that the binaries you generate will be completely self-contained and will execute in the most deprived environments.  In particular, your target MAXI does not require any support software to run Go binaries.  That is what attracted me to get Go tested on the MAXI, the release of Linux that came with my development board had no program development tools.  Comparing the complexity of installing and using a GCC cross-development system on Ubuntu versus doing the same for (to me much more familiar) Go left me in no doubt which way to swing.

Let me know if you have trouble finding what you're looking for from the official web site, I'm collecting notes about Go in various environments, I'll be happy to help you resolve your problems and make sure they are reported and avoided in future.

Lucio.