github.com/bazelbuild/rules_go@v0.47.2-0.20240515105122-e7ddb9ea474e/go/private/rules/stdlib.bzl (about) 1 # Copyright 2016 The Bazel Go Rules Authors. All rights reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 load( 16 "//go/private:common.bzl", 17 "GO_TOOLCHAIN", 18 ) 19 load( 20 "//go/private:context.bzl", 21 "go_context", 22 ) 23 load( 24 "//go/private:providers.bzl", 25 "GoConfigInfo", 26 ) 27 load( 28 "//go/private/rules:transition.bzl", 29 "go_stdlib_transition", 30 ) 31 32 def _stdlib_impl(ctx): 33 go = go_context(ctx) 34 source, library = go.toolchain.actions.stdlib(go) 35 return [source, library, source.stdlib] 36 37 stdlib = rule( 38 implementation = _stdlib_impl, 39 cfg = go_stdlib_transition, 40 attrs = { 41 "cgo_context_data": attr.label(), 42 "_go_config": attr.label( 43 default = "//:go_config", 44 providers = [GoConfigInfo], 45 ), 46 "_allowlist_function_transition": attr.label( 47 default = "@bazel_tools//tools/allowlists/function_transition_allowlist", 48 ), 49 }, 50 doc = """stdlib builds the standard library for the target configuration 51 or uses the precompiled standard library from the SDK if it is suitable.""", 52 toolchains = [GO_TOOLCHAIN], 53 )