Skip to content

Commit

Permalink
Try transitioning and avoiding default target config
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Oct 22, 2024
1 parent 02912ea commit e284a97
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion py/private/toolchain/venv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("//py/private/toolchain:tools.bzl", "source_toolchain")

source_toolchain(
name = "venv",
bin = "//py/tools/venv_bin",
bin = "//py/tools/venv_bin:venv_bin_for_platform",
# When running from source, we assume the target is the exec platform.
# TODO: when we have cross-compile Mac -> Linux, pre-release users should be able to
# build a py_image on their Mac and have the linux venv rust_binary end up in the container.
Expand Down
15 changes: 12 additions & 3 deletions py/tools/venv_bin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ rust_binary(
srcs = [
"src/main.rs",
],
visibility = [
"//visibility:public",
],
deps = [
"//py/tools/py",
"@crate_index//:clap",
Expand All @@ -23,6 +20,18 @@ alias(
tags = ["manual"],
)

alias(
name = "venv_bin_for_platform",
actual = select({
"//tools/platforms:macos_aarch64": ":venv_macos_aarch64_build",
"//tools/platforms:macos_x86_64": ":venv_macos_x86_64_build",
"//tools/platforms:linux_aarch64": ":venv_linux_aarch64_build",
"//tools/platforms:linux_x86_64": ":venv_linux_x86_64_build",
}),
tags = ["manual"],
visibility = ["//visibility:public"],
)

multi_arch_rust_binary_release(
name = "macos",
src = ":venv",
Expand Down
35 changes: 35 additions & 0 deletions tools/platforms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
config_setting(
name = "linux_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "linux_aarch64",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:linux",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "macos_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "macos_aarch64",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:macos",
],
visibility = ["//visibility:public"],
)
7 changes: 4 additions & 3 deletions tools/release/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Make releases for platforms supported by rules_py"

load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary")
load("@aspect_bazel_lib//tools/release:hashes.bzl", "hashes")

def _map_os_to_triple(os):
Expand All @@ -15,11 +15,12 @@ def _map_os_to_triple(os):
# buildozer: disable=function-docstring
def multi_arch_rust_binary_release(name, src, os, archs = ["aarch64", "x86_64"], **kwargs):
outs = []
actuals = {}
for arch in archs:
bin = Label(src).name
platform_transition_filegroup(
platform_transition_binary(
name = "{}_{}_{}_build".format(bin, os, arch),
srcs = [src],
binary = src,
target_platform = "//tools/release:{}_{}".format(os, arch),
target_compatible_with = ["@platforms//os:{}".format(os)],
)
Expand Down

0 comments on commit e284a97

Please sign in to comment.