Golang gc: Difference between revisions
From wikinotes
(→build) |
(→build) |
||
Line 22: | Line 22: | ||
= build = | = build = | ||
<blockquote> | |||
== Basics == | |||
<blockquote> | <blockquote> | ||
Go build creates an executable with the name of your package.<br> | Go build creates an executable with the name of your package.<br> | ||
Line 35: | Line 37: | ||
go clean -x # print commands as deletes | go clean -x # print commands as deletes | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Basics --> | |||
== cross-compilation == | |||
<blockquote> | |||
<syntaxhighlight lang="bash"> | |||
GOOS=darwin GOARCH=386 go build # build for macos | |||
GOOS=windows GOARCH=386 go build # build for windows | |||
</syntaxhighlight> | |||
</blockquote><!-- cross-compilation --> | |||
</blockquote><!-- build --> | </blockquote><!-- build --> | ||
Revision as of 01:14, 19 June 2022
This page documents the builtin golang compilation tools.
go's build/install/clean aim to replace the functionality of a Makefile.
run
go run
is a convenience tool that builds/runs an executable.go run . # compile package at cwd, and run it's 'main()' method go run . --help # cli params for the program can be passed to go run go run main.go lib.go ... # compile only these files, and run detected 'main()' method go run some/package # compile a specific packageIt accepts all of the same build-flags as
go build
,
which includes some validation tools.go run -race . # compile/run, and detect race conditions
build
Basics
Go build creates an executable with the name of your package.
If your package includes slashes, it is only the basename.
(ex: package:example.com/x/foo
creates executablefoo
)go build # build executable for package at cwd go build -o altname # build executable as 'altname' go clean # removes build go clean -i # removes 'go install'ed executable go clean -x # print commands as deletescross-compilation
GOOS=darwin GOARCH=386 go build # build for macos GOOS=windows GOARCH=386 go build # build for windows