1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 # By default, there is no go build tool, because go builds are not supported.
10 # Declare a go test binary target.
12 # The target generates a go test executable, linking against other C code,
13 # which is compiled into a static library and linked against Go.
15 # Only works on linux. |go_build_tool| must be set to the absolute path
16 # of the go build tool.
18 # Variables (all required)
19 # sources: list of .go files to compile
20 # static_library_sources: list of C sources needed for the static library
21 # deps: dependencies for the static library
23 template("go_test_binary") {
24 # Only available on linux for now.
26 assert(defined(invoker.sources))
27 assert(go_build_tool != "")
29 static_library_name = target_name + "_static_library"
31 static_library(static_library_name) {
32 sources = invoker.static_library_sources
34 complete_static_lib = true
39 ":$static_library_name",
41 script = "//build/go/go.py"
42 outputs = [ "${target_out_dir}/${target_name}" ]
43 # Since go test does not permit specifying an output directory or output
44 # binary name, we create a temporary build directory, and the python
45 # script will later identify the output, copy it to the target location,
46 # and clean up the temporary build directory.
47 build_dir = "${target_out_dir}/${target_name}_build"
51 rebase_path(build_dir, root_build_dir),
52 rebase_path(target_out_dir, root_build_dir) + "/${target_name}",
53 rebase_path("//", root_build_dir),
54 "-I" + rebase_path("//"),
55 " -L" + rebase_path(target_out_dir) +
56 " -l" + static_library_name +
57 " -lstdc++ -lpthread -lm -lglib-2.0",
59 ] + rebase_path(invoker.sources, build_dir)
63 template("go_shared_library") {
64 # Only available on android for now.
66 assert(defined(invoker.sources))
67 assert(go_build_tool != "")
69 static_library_name = target_name + "_static_library"
71 static_library(static_library_name) {
72 complete_static_lib = true
77 deps = [ ":$static_library_name" ]
78 script = "//build/go/go.py"
79 outputs = [ "${target_out_dir}/${target_name}" ]
80 # Since go test does not permit specifying an output directory or output
81 # binary name, we create a temporary build directory, and the python
82 # script will later identify the output, copy it to the target location,
83 # and clean up the temporary build directory.
84 build_dir = "${target_out_dir}/${target_name}_build"
87 "CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 ${go_build_tool}",
88 rebase_path(build_dir, root_build_dir),
89 rebase_path(target_out_dir, root_build_dir) + "/${target_name}",
90 rebase_path("//", root_build_dir),
91 "-I" + rebase_path("//"),
92 " -L" + rebase_path(target_out_dir) +
93 " -l" + static_library_name + "",
94 "build -ldflags=-shared",
95 ] + rebase_path(invoker.sources, build_dir)