| # Copyright 2017 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//build/go/go_build.gni") |
| import("//build/go/go_library.gni") |
| |
| # A template for an action that creates a Fuchsia Go binary. |
| # |
| # Parameters: same as go_build, along with |
| # |
| # gopackage (optional) |
| # The go package containing the main function. |
| # |
| # embed (optional) |
| # Alternative to gopackage, should contain exactly one element. |
| # Type: list of labels |
| # |
| # embedsrcs (optional) |
| # For sources used by go:embed. |
| # |
| # source_dir, sources |
| # Same meaning as defined in go_library.gni. |
| # |
| template("go_binary") { |
| if (defined(invoker.sources)) { |
| assert( |
| !defined(invoker.gopackage) && !defined(invoker.embed), |
| "gopackage and embed can't be used when sources for this go_binary are explicitly listed") |
| lib_target = "_${target_name}_go_lib" |
| go_library(lib_target) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "embedsrcs", |
| "source_dir", |
| "sources", |
| ]) |
| } |
| embed = [ ":${lib_target}" ] |
| } |
| |
| go_build(target_name) { |
| # TODO(https://fxbug.dev/42136747): Deprecate `gopackage` in favor of `library`. |
| if (defined(invoker.gopackage)) { |
| gopackages = [ invoker.gopackage ] |
| } |
| forward_variables_from(invoker, "*") |
| } |
| } |