1# Copyright 2024 The Bazel 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""" 16EXPERIMENTAL: This is experimental and may be removed without notice 17 18This module implements the uv toolchain rule 19""" 20 21load("//python/uv/private:providers.bzl", "UvToolchainInfo") 22 23def _uv_toolchain_impl(ctx): 24 uv = ctx.attr.uv 25 26 default_info = DefaultInfo( 27 files = uv.files, 28 runfiles = uv[DefaultInfo].default_runfiles, 29 ) 30 uv_toolchain_info = UvToolchainInfo( 31 uv = uv, 32 version = ctx.attr.version, 33 ) 34 35 # Export all the providers inside our ToolchainInfo 36 # so the current_toolchain rule can grab and re-export them. 37 toolchain_info = platform_common.ToolchainInfo( 38 default_info = default_info, 39 uv_toolchain_info = uv_toolchain_info, 40 ) 41 return [ 42 default_info, 43 toolchain_info, 44 ] 45 46uv_toolchain = rule( 47 implementation = _uv_toolchain_impl, 48 attrs = { 49 "uv": attr.label( 50 doc = "A static uv binary.", 51 mandatory = True, 52 allow_single_file = True, 53 executable = True, 54 cfg = "target", 55 ), 56 "version": attr.string(mandatory = True, doc = "Version of the uv binary."), 57 }, 58 doc = "Defines a uv toolchain.", 59) 60