Building Go Packages

In this lesson, we'll take a look into building Go programs and discuss the build command and some flags that will help us analyze what's going on when building a package and how dependencies are managed.

We'll cover the following

Building packages

Go uses caching of pre-built dependencies. To see what would happen if we had to build everything from scratch we can use the -a and -n flags. The -a flag forces a rebuild of all packages, and t. The -n flag just prints the commands that need to be run but doesn’t actually run them. In combination, we can see what a full build entails without actually wasting time. The output is pretty verbose even for a small program like multi-git, so we will review just a few interesting bits after redirecting the output to a file. It must redirect standard output AND standard error streams:

$ go build -n -a &> 1.txt

The resulting file has more than 3,000 lines!

$ cat 1.txt| wc -l
    3152

Let’s review some of the highlights. First, Go will build internal packages like internal or cpu using the asm (assembly language) tool and compile tool:

Get hands-on with 1400+ tech skills courses.