Skip to content

Commit

Permalink
create separate toolchain for runtime vtool
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Feb 2, 2024
1 parent c9e6d2b commit c402ec5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ register_toolchains(
"@aspect_rules_py//py/private/toolchain:vtool_darwin_arm64_toolchain",
"@aspect_rules_py//py/private/toolchain:vtool_linux_amd64_toolchain",
"@aspect_rules_py//py/private/toolchain:vtool_linux_arm64_toolchain",
"@aspect_rules_py//py/private/toolchain:vtool_darwin_amd64_runtime_toolchain",
"@aspect_rules_py//py/private/toolchain:vtool_darwin_arm64_runtime_toolchain",
"@aspect_rules_py//py/private/toolchain:vtool_linux_amd64_runtime_toolchain",
"@aspect_rules_py//py/private/toolchain:vtool_linux_arm64_runtime_toolchain",
)
9 changes: 5 additions & 4 deletions py/private/py_unpacked_wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

load("@bazel_skylib//lib:paths.bzl", "paths")
load("//py/private:py_library.bzl", _py_library = "py_library_utils")
load("//py/private:utils.bzl", "PY_TOOLCHAIN", "VTOOL_TOOLCHAIN", "resolve_toolchain")
load("//py/private:utils.bzl", "PY_TOOLCHAIN", "VTOOL_RUNTIME_TOOLCHAIN", "resolve_toolchain")

def _py_unpacked_wheel_impl(ctx):
py_toolchain = resolve_toolchain(ctx)
vtool_toolchain = ctx.toolchains[VTOOL_TOOLCHAIN]
vtool_toolchain = ctx.toolchains[VTOOL_RUNTIME_TOOLCHAIN]

unpack_directory = ctx.actions.declare_directory("{}".format(ctx.attr.name))

Expand Down Expand Up @@ -36,6 +36,7 @@ def _py_unpacked_wheel_impl(ctx):
arguments = [arguments],
mnemonic = "PyUnpackedWheel",
progress_message = "Unpacking wheel {}".format(ctx.file.src.basename),
toolchain = VTOOL_RUNTIME_TOOLCHAIN,
)

import_path = paths.join(
Expand Down Expand Up @@ -81,8 +82,8 @@ _py_unpacked_wheel_rule = rule(
provides = [PyInfo],
toolchains = [
PY_TOOLCHAIN,
VTOOL_TOOLCHAIN,
],
VTOOL_RUNTIME_TOOLCHAIN,
]
)

def py_unpacked_wheel(name, **kwargs):
Expand Down
4 changes: 4 additions & 0 deletions py/private/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ toolchain_type(
name = "vtool_toolchain_type",
)

toolchain_type(
name = "vtool_runtime_toolchain_type",
)

make_vtool_toolchains()

exports_files(
Expand Down
9 changes: 8 additions & 1 deletion py/private/toolchain/vtool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ def make_vtool_toolchains(name = "vtool", version = DEFAULT_VTOOL_VERSION):
)
native.toolchain(
name = "{}_{}_toolchain".format(name, platform),
exec_compatible_with = meta.compatible_with,
target_compatible_with = meta.compatible_with,
toolchain = ":{}_toolchain_{}".format(name, platform),
toolchain_type = "@aspect_rules_py//py/private/toolchain:vtool_toolchain_type",
)
native.toolchain(
name = "{}_{}_runtime_toolchain".format(name, platform),
exec_compatible_with = meta.compatible_with,
toolchain = ":{}_toolchain_{}".format(name, platform),
toolchain_type = "@aspect_rules_py//py/private/toolchain:vtool_runtime_toolchain_type",
)

def register_vtool_toolchains(name = "vtool"):
for [platform, meta] in VTOOL_PLATFORMS.items():
native.register_toolchains("@aspect_rules_py//py/private/toolchain:{}_{}_toolchain".format(name, platform))
native.register_toolchains("@aspect_rules_py//py/private/toolchain:{}_{}_runtime_toolchain".format(name, platform))
1 change: 1 addition & 0 deletions py/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
PY_TOOLCHAIN = "@bazel_tools//tools/python:toolchain_type"
SH_TOOLCHAIN = "@bazel_tools//tools/sh:toolchain_type"
VTOOL_TOOLCHAIN = "@aspect_rules_py//py/private/toolchain:vtool_toolchain_type"
VTOOL_RUNTIME_TOOLCHAIN = "@aspect_rules_py//py/private/toolchain:vtool_runtime_toolchain_type"

INTERPRETER_FLAGS = ["-B", "-I"]

Expand Down

0 comments on commit c402ec5

Please sign in to comment.