Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (45 sloc) 1.73 KB
# Copyright Jay Conrod. All rights reserved.
# This file is part of rules_go_simple. Use of this source code is governed by
# the 3-clause BSD license that can be found in the LICENSE.txt file.
load(":actions.bzl", "go_compile", "go_link")
def _go_binary_impl(ctx):
# Declare an output file for the main package and compile it from srcs. All
# our output files will start with a prefix to avoid conflicting with
# other rules.
prefix = + "%/"
main_archive = ctx.actions.declare_file(prefix + "main.a")
srcs = ctx.files.srcs,
out = main_archive,
# Declare an output file for the executable and link it. Note that output
# files may not have the same name as the rule, so we still need to use the
# prefix here.
executable = ctx.actions.declare_file(prefix +
main = main_archive,
out = executable,
# Return the DefaultInfo provider. This tells Bazel what files should be
# built when someone asks to build a go_binary rules. It also says which
# one is executable (in this case, there's only one).
return [DefaultInfo(
files = depset([executable]),
executable = executable,
# Declare the go_binary rule. This statement is evaluated during the loading
# phase when this file is loaded. The function body above is evaluated only
# during the analysis phase.
go_binary = rule(
attrs = {
"srcs": attr.label_list(
allow_files = [".go"],
doc = "Source files to compile for the main package of this binary",
doc = "Builds an executable program from Go source code",
executable = True,
You can’t perform that action at this time.