go: fix host builds that use CGO
Change-Id: If1a11c4d7e64e143ba6fef15763e67a892344d55
diff --git a/go/build.py b/go/build.py
index 03ce505..9053654 100755
--- a/go/build.py
+++ b/go/build.py
@@ -32,6 +32,8 @@
parser.add_argument('--go-dependency', help='Manifest of dest=src of dependencies',
action='append')
parser.add_argument('--binname', help='Output file', required=True)
+ parser.add_argument('--toolchain-prefix', help='Path to toolchain binaries',
+ required=False)
parser.add_argument('package', help='The package name')
args = parser.parse_args()
@@ -83,6 +85,10 @@
env['GOARCH'] = goarch
env['GOOS'] = goos
env['GOPATH'] = gopath + ":" + os.path.abspath(os.path.join(args.root_out_dir, "gen/go"))
+ # /usr/bin:/bin are required for basic things like bash(1) and env(1), but
+ # preference the toolchain path. Note that on Mac, ld is also found from
+ # /usr/bin.
+ env['PATH'] = args.toolchain_prefix + ":/usr/bin:/bin"
cmd = [args.go_tool]
if args.is_test:
diff --git a/go/go_build.gni b/go/go_build.gni
index b2ba3cd..b18f90b 100644
--- a/go/go_build.gni
+++ b/go/go_build.gni
@@ -31,6 +31,8 @@
# At miniumum there should be a go_dependencies declaration for the package to
# be built.
+import("//build/toolchain/clang_toolchain.gni")
+
template("go_build") {
assert(defined(invoker.gopackage),
"gopackage must be defined for $target_name")
@@ -72,7 +74,9 @@
"--go-tool",
rebase_path("//buildtools/go"),
"--binname",
- output_name
+ output_name,
+ "--toolchain-prefix",
+ rebase_path(clang_prefix)
]
if (defined(invoker.test) && invoker.test) {