1*9bb1b549SSpandan Das# Copyright 2017 The Bazel Authors. All rights reserved. 2*9bb1b549SSpandan Das# 3*9bb1b549SSpandan Das# Licensed under the Apache License, Version 2.0 (the "License"); 4*9bb1b549SSpandan Das# you may not use this file except in compliance with the License. 5*9bb1b549SSpandan Das# You may obtain a copy of the License at 6*9bb1b549SSpandan Das# 7*9bb1b549SSpandan Das# http://www.apache.org/licenses/LICENSE-2.0 8*9bb1b549SSpandan Das# 9*9bb1b549SSpandan Das# Unless required by applicable law or agreed to in writing, software 10*9bb1b549SSpandan Das# distributed under the License is distributed on an "AS IS" BASIS, 11*9bb1b549SSpandan Das# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9bb1b549SSpandan Das# See the License for the specific language governing permissions and 13*9bb1b549SSpandan Das# limitations under the License. 14*9bb1b549SSpandan Das 15*9bb1b549SSpandan Dasload( 16*9bb1b549SSpandan Das "//go/private:context.bzl", 17*9bb1b549SSpandan Das "go_context", 18*9bb1b549SSpandan Das) 19*9bb1b549SSpandan Dasload( 20*9bb1b549SSpandan Das "//go/private:go_toolchain.bzl", 21*9bb1b549SSpandan Das "GO_TOOLCHAIN", 22*9bb1b549SSpandan Das) 23*9bb1b549SSpandan Dasload( 24*9bb1b549SSpandan Das "//go/private:providers.bzl", 25*9bb1b549SSpandan Das "GoLibrary", 26*9bb1b549SSpandan Das) 27*9bb1b549SSpandan Das 28*9bb1b549SSpandan Dasdef _go_source_impl(ctx): 29*9bb1b549SSpandan Das """Implements the go_source() rule.""" 30*9bb1b549SSpandan Das go = go_context(ctx) 31*9bb1b549SSpandan Das library = go.new_library(go) 32*9bb1b549SSpandan Das source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented()) 33*9bb1b549SSpandan Das return [ 34*9bb1b549SSpandan Das library, 35*9bb1b549SSpandan Das source, 36*9bb1b549SSpandan Das DefaultInfo( 37*9bb1b549SSpandan Das files = depset(source.srcs), 38*9bb1b549SSpandan Das ), 39*9bb1b549SSpandan Das ] 40*9bb1b549SSpandan Das 41*9bb1b549SSpandan Dasgo_source = rule( 42*9bb1b549SSpandan Das implementation = _go_source_impl, 43*9bb1b549SSpandan Das attrs = { 44*9bb1b549SSpandan Das "data": attr.label_list( 45*9bb1b549SSpandan Das allow_files = True, 46*9bb1b549SSpandan Das doc = """List of files needed by this rule at run-time. This may include data files 47*9bb1b549SSpandan Das needed or other programs that may be executed. The [bazel] package may be 48*9bb1b549SSpandan Das used to locate run files; they may appear in different places depending on the 49*9bb1b549SSpandan Das operating system and environment. See [data dependencies] for more 50*9bb1b549SSpandan Das information on data files. 51*9bb1b549SSpandan Das """, 52*9bb1b549SSpandan Das ), 53*9bb1b549SSpandan Das "srcs": attr.label_list( 54*9bb1b549SSpandan Das allow_files = True, 55*9bb1b549SSpandan Das doc = """The list of Go source files that are compiled to create the package. 56*9bb1b549SSpandan Das The following file types are permitted: `.go, .c, .s, .S .h`. 57*9bb1b549SSpandan Das The files may contain Go-style [build constraints]. 58*9bb1b549SSpandan Das """, 59*9bb1b549SSpandan Das ), 60*9bb1b549SSpandan Das "deps": attr.label_list( 61*9bb1b549SSpandan Das providers = [GoLibrary], 62*9bb1b549SSpandan Das doc = """List of Go libraries this source list imports directly. 63*9bb1b549SSpandan Das These may be go_library rules or compatible rules with the [GoLibrary] provider. 64*9bb1b549SSpandan Das """, 65*9bb1b549SSpandan Das ), 66*9bb1b549SSpandan Das "embed": attr.label_list( 67*9bb1b549SSpandan Das providers = [GoLibrary], 68*9bb1b549SSpandan Das doc = """List of Go libraries whose sources should be compiled together with this 69*9bb1b549SSpandan Das package's sources. Labels listed here must name `go_library`, 70*9bb1b549SSpandan Das `go_proto_library`, or other compatible targets with the [GoLibrary] and 71*9bb1b549SSpandan Das [GoSource] providers. Embedded libraries must have the same `importpath` as 72*9bb1b549SSpandan Das the embedding library. At most one embedded library may have `cgo = True`, 73*9bb1b549SSpandan Das and the embedding library may not also have `cgo = True`. See [Embedding] 74*9bb1b549SSpandan Das for more information. 75*9bb1b549SSpandan Das """, 76*9bb1b549SSpandan Das ), 77*9bb1b549SSpandan Das "gc_goopts": attr.string_list( 78*9bb1b549SSpandan Das doc = """List of flags to add to the Go compilation command when using the gc compiler. 79*9bb1b549SSpandan Das Subject to ["Make variable"] substitution and [Bourne shell tokenization]. 80*9bb1b549SSpandan Das """, 81*9bb1b549SSpandan Das ), 82*9bb1b549SSpandan Das "_go_config": attr.label(default = "//:go_config"), 83*9bb1b549SSpandan Das "_cgo_context_data": attr.label(default = "//:cgo_context_data_proxy"), 84*9bb1b549SSpandan Das }, 85*9bb1b549SSpandan Das toolchains = [GO_TOOLCHAIN], 86*9bb1b549SSpandan Das doc = """This declares a set of source files and related dependencies that can be embedded into one of the 87*9bb1b549SSpandan Das other rules. 88*9bb1b549SSpandan Das This is used as a way of easily declaring a common set of sources re-used in multiple rules.<br><br> 89*9bb1b549SSpandan Das **Providers:** 90*9bb1b549SSpandan Das <ul> 91*9bb1b549SSpandan Das <li>[GoLibrary]</li> 92*9bb1b549SSpandan Das <li>[GoSource]</li> 93*9bb1b549SSpandan Das </ul> 94*9bb1b549SSpandan Das """, 95*9bb1b549SSpandan Das) 96*9bb1b549SSpandan Das# See docs/go/core/rules.md#go_source for full documentation. 97