-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Introduce an experimental uv
toolchain
#1989
Merged
Merged
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
4a816ca
Spike uv
groodt 6d0bdeb
Spike uv
groodt c5c3f88
Adds Windows
groodt f038ce8
buildifier
groodt 8086333
buildifier
groodt 2591363
chore: add uv to rules_python bzlmod
aignas 2797a46
adapt the uv directly from http_archive
aignas 308fe32
bump uv version
aignas 04e5e6c
move the usage of the uv extension around
aignas 0fcdf65
fixup the buildozer fixup command
aignas 6d1743f
Merge branch 'main' into groodt-uv-hacks
groodt aea2ef9
Merge branch 'groodt-uv-hacks' of github.com:bazelbuild/rules_python …
groodt 9b1f5fd
Hacky toolchain. Needs py interpreter.
groodt abbcc97
Hacky toolchain. Needs py interpreter.
groodt 4a01495
Kinda works
groodt 850f254
Merge branch 'main' into groodt-uv-hacks
groodt c6bddea
.
groodt 750d8da
Init toolchain
groodt 3a1f889
Init toolchain
groodt 37859b8
Init toolchain
groodt 0ff0003
Init toolchain
groodt fb73a9f
Init toolchain
groodt aefd672
Init toolchain
groodt 8002c0e
Working toolchain
groodt 1c8bf77
Working toolchain
groodt 4356066
Working executable rule
groodt 26a87f2
Working executable rule
groodt eea3f34
Working executable rule
groodt 2cede41
Fix copyright date
rickeylev 76b381a
address some nit/style type of comments
rickeylev c4b01c7
Merge branch 'main' into groodt-uv-hacks
groodt 6041414
.
groodt ba09edc
Address review comments
groodt ec0f6fa
Address review comments
groodt 4cb451a
Address review comments
groodt 07c1ff6
Address review comments
groodt a60a308
Address review comments
groodt ec0f9f4
Address review comments
groodt 014afbb
Address review comments
groodt e8fbfa1
Address review comments
groodt 23628ea
Address review comments
groodt c2d7694
Address review comments
groodt fd9eebf
Address review comments
groodt a59ab24
Address review comments
groodt 431c79f
Address review comments
groodt e67fdc8
Address review comments
groodt d141195
Address review comments
groodt 3a0441b
Address review comments
groodt 40ccfb0
Address review comments
groodt 7750195
Address review comments
groodt 8342931
Address review comments
groodt d98ba65
Address review comments
groodt dc0df0b
Address review comments
groodt 4c8c490
Address review comments
groodt ae45048
Address review comments
groodt 0b0d49c
Address review comments
groodt 93e81c6
Address review comments
groodt 5ecc345
Address review comments
groodt 5733118
Address review comments
groodt ec10150
Address review comments
groodt 6adac07
Merge branch 'main' into groodt-uv-hacks
groodt 8e3cbe9
Bump to uv 0.2.23
groodt 7dd729c
Address review comments
groodt bb2996c
Address review comments
groodt c31f6f9
Address review comments
groodt 6f22655
Add EXPERIMENTAL comments and visibility restrictions
groodt 22ad69f
Add EXPERIMENTAL comments and visibility restrictions
groodt f4c8790
Address review comments
groodt 02c537d
Address review comments
groodt dfa24fe
Address review comments
groodt 5c11f75
Address review comments
groodt 93829ca
Address review comments
groodt a0f3d5c
Address review comments
groodt 7fb7af1
Address review comments
groodt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# EXPERIMENTAL: This is experimental and may be removed without notice | ||
|
||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("//python/uv/private:current_toolchain.bzl", "current_toolchain") | ||
|
||
package(default_visibility = ["//:__subpackages__"]) | ||
|
||
filegroup( | ||
name = "distribution", | ||
srcs = glob(["**"]) + [ | ||
"//python/uv/private:distribution", | ||
], | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
# For stardoc to reference the files | ||
exports_files(["defs.bzl"]) | ||
|
||
toolchain_type( | ||
name = "uv_toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
current_toolchain( | ||
name = "current_toolchain", | ||
# Marked manual so that `bazel test //...` passes | ||
# even if no toolchain is registered. | ||
tags = ["manual"], | ||
# EXPERIMENTAL: Visibility is restricted to allow for changes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to factor visibility into a variable? I just mention it in case you plan to patch-out the visibility restrictions to experiment with. It'd be easier to patch the variable than all the various visibility lines |
||
visibility = ["@rules_python//examples:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "defs", | ||
srcs = ["defs.bzl"], | ||
# EXPERIMENTAL: Visibility is restricted to allow for changes. | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "extensions", | ||
srcs = ["extensions.bzl"], | ||
# EXPERIMENTAL: Visibility is restricted to allow for changes. | ||
visibility = ["//:__subpackages__"], | ||
deps = [":repositories"], | ||
) | ||
|
||
bzl_library( | ||
name = "repositories", | ||
srcs = ["repositories.bzl"], | ||
# EXPERIMENTAL: Visibility is restricted to allow for changes. | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//python/uv/private:toolchains_repo", | ||
"//python/uv/private:versions", | ||
], | ||
) | ||
|
||
bzl_library( | ||
name = "toolchain", | ||
srcs = ["toolchain.bzl"], | ||
# EXPERIMENTAL: Visibility is restricted to allow for changes. | ||
visibility = ["//:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
EXPERIMENTAL: This is experimental and may be removed without notice | ||
|
||
A toolchain for uv | ||
""" | ||
|
||
load("//python/uv/private:providers.bzl", _UvToolchainInfo = "UvToolchainInfo") | ||
|
||
UvToolchainInfo = _UvToolchainInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
EXPERIMENTAL: This is experimental and may be removed without notice | ||
|
||
A module extension for working with uv. | ||
""" | ||
|
||
load("//python/uv:repositories.bzl", "uv_register_toolchains") | ||
|
||
_DOC = """\ | ||
A module extension for working with uv. | ||
""" | ||
|
||
uv_toolchain = tag_class(attrs = { | ||
"uv_version": attr.string(doc = "Explicit version of uv.", mandatory = True), | ||
}) | ||
|
||
def _uv_toolchain_extension(module_ctx): | ||
for mod in module_ctx.modules: | ||
for toolchain in mod.tags.toolchain: | ||
if not mod.is_root: | ||
fail( | ||
"Only the root module may configure the uv toolchain.", | ||
"This prevents conflicting registrations with any other modules.", | ||
"NOTE: We may wish to enforce a policy where toolchain configuration is only allowed in the root module, or in rules_python. See https://github.com/bazelbuild/bazel/discussions/22024", | ||
) | ||
|
||
uv_register_toolchains( | ||
uv_version = toolchain.uv_version, | ||
register_toolchains = False, | ||
) | ||
|
||
uv = module_extension( | ||
doc = _DOC, | ||
implementation = _uv_toolchain_extension, | ||
tag_classes = {"toolchain": uv_toolchain}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
groodt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
|
||
filegroup( | ||
name = "distribution", | ||
srcs = glob(["**"]), | ||
visibility = ["//python/uv:__pkg__"], | ||
) | ||
|
||
bzl_library( | ||
name = "current_toolchain", | ||
srcs = ["current_toolchain.bzl"], | ||
visibility = ["//python/uv:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "toolchain_types", | ||
srcs = ["toolchain_types.bzl"], | ||
visibility = ["//python/uv:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "toolchains_repo", | ||
srcs = ["toolchains_repo.bzl"], | ||
visibility = ["//python/uv:__subpackages__"], | ||
) | ||
|
||
bzl_library( | ||
name = "versions", | ||
srcs = ["versions.bzl"], | ||
visibility = ["//python/uv:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This module implements an alias rule to the resolved toolchain. | ||
""" | ||
|
||
load("//python/uv/private:toolchain_types.bzl", "UV_TOOLCHAIN_TYPE") | ||
|
||
_DOC = """\ | ||
Exposes a concrete toolchain which is the result of Bazel resolving the | ||
toolchain for the execution or target platform. | ||
Workaround for https://github.com/bazelbuild/bazel/issues/14009 | ||
""" | ||
|
||
# Forward all the providers | ||
def _current_toolchain_impl(ctx): | ||
toolchain_info = ctx.toolchains[UV_TOOLCHAIN_TYPE] | ||
|
||
# Bazel requires executable rules to create the executable themselves, | ||
# so we create a symlink in this rule so that it appears this rule created its executable. | ||
original_uv_executable = toolchain_info.uv_toolchain_info.uv[DefaultInfo].files_to_run.executable | ||
symlink_uv_executable = ctx.actions.declare_file("uv_symlink_{}".format(original_uv_executable.basename)) | ||
ctx.actions.symlink(output = symlink_uv_executable, target_file = original_uv_executable) | ||
|
||
new_default_info = DefaultInfo( | ||
files = depset([symlink_uv_executable]), | ||
runfiles = toolchain_info.default_info.default_runfiles, | ||
executable = symlink_uv_executable, | ||
) | ||
|
||
return [ | ||
toolchain_info, | ||
new_default_info, | ||
toolchain_info.template_variable_info, | ||
toolchain_info.uv_toolchain_info, | ||
] | ||
|
||
# Copied from java_toolchain_alias | ||
# https://cs.opensource.google/bazel/bazel/+/master:tools/jdk/java_toolchain_alias.bzl | ||
current_toolchain = rule( | ||
implementation = _current_toolchain_impl, | ||
toolchains = [UV_TOOLCHAIN_TYPE], | ||
doc = _DOC, | ||
executable = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This module contains the definitions of all providers.""" | ||
|
||
UvToolchainInfo = provider( | ||
doc = "Information about how to invoke the uv executable.", | ||
fields = { | ||
"uv": """ | ||
:type: Target | ||
|
||
The uv binary `Target` | ||
""", | ||
"version": """ | ||
:type: str | ||
|
||
The uv version | ||
""", | ||
}, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if having
python/uv/private
is better thanpython/private/uv
but I don't we can discuss/bikeshed it later, we can merge it as is right now.