Skip to content

Commit

Permalink
Updated platform triple mapping to support T3 platforms without std.
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Sep 24, 2024
1 parent 144d34f commit 801012c
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 72 deletions.
2 changes: 1 addition & 1 deletion crate_universe/3rdparty/crates/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions crate_universe/3rdparty/crates/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crate_universe/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crate_universe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cargo_metadata = "0.18.1"
cargo_toml = "0.19.2"
cargo-lock = "9.0.0"
cargo-platform = "0.1.4"
cfg-expr = "0.15.5"
cfg-expr = "0.17.0"
clap = { version = "4.3.11", features = ["derive", "env"] }
crates-index = { version = "2.2.0", default-features = false, features = [
"git",
Expand Down
6 changes: 0 additions & 6 deletions rust/platform/cpu/BUILD.bazel

This file was deleted.

4 changes: 2 additions & 2 deletions rust/platform/platform.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
load(
":triple_mappings.bzl",
"SUPPORTED_PLATFORM_TRIPLES",
"ALL_PLATFORM_TRIPLES",
"cpu_arch_to_constraints",
"system_to_constraints",
"triple_to_constraint_set",
Expand Down Expand Up @@ -59,7 +59,7 @@ def declare_config_settings():
actual = ":darwin",
)

all_supported_triples = SUPPORTED_PLATFORM_TRIPLES
all_supported_triples = ALL_PLATFORM_TRIPLES
for triple in all_supported_triples:
native.config_setting(
name = triple,
Expand Down
140 changes: 88 additions & 52 deletions rust/platform/triple_mappings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,101 @@

load("//rust/platform:triple.bzl", "triple")

def _support(*, std = False, host_tools = False):
"""Identify the type of support an associated platform triple has.
The source of truth is:
https://doc.rust-lang.org/nightly/rustc/platform-support.html
Args:
std (bool, optional): Whether or not platform has a standard library artifact.
host_tools (bool, optional): Whether or not platform has host tools artifacts.
Returns:
struct: The parameters above.
"""
return struct(
std = std,
host_tools = host_tools,
)

# All T1 Platforms should be supported, but aren't, see inline notes.
SUPPORTED_T1_PLATFORM_TRIPLES = [
"aarch64-unknown-linux-gnu",
"aarch64-unknown-nixos-gnu", # Same as `aarch64-unknown-linux-gnu` but with `@platforms//os:nixos`.
"i686-apple-darwin",
"i686-pc-windows-msvc",
"i686-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-unknown-nixos-gnu", # Same as `x86_64-unknown-linux-gnu` but with `@platforms//os:nixos`.
SUPPORTED_T1_PLATFORM_TRIPLES = {
"aarch64-apple-darwin": _support(std = True, host_tools = True),
"aarch64-unknown-linux-gnu": _support(std = True, host_tools = True),
"aarch64-unknown-nixos-gnu": _support(std = True, host_tools = True), # Same as `aarch64-unknown-linux-gnu` but with `@platforms//os:nixos`.
"i686-apple-darwin": _support(std = True, host_tools = True),
"i686-pc-windows-msvc": _support(std = True, host_tools = True),
"i686-unknown-linux-gnu": _support(std = True, host_tools = True),
"x86_64-apple-darwin": _support(std = True, host_tools = True),
"x86_64-pc-windows-msvc": _support(std = True, host_tools = True),
"x86_64-unknown-linux-gnu": _support(std = True, host_tools = True),
"x86_64-unknown-nixos-gnu": _support(std = True, host_tools = True), # Same as `x86_64-unknown-linux-gnu` but with `@platforms//os:nixos`.
# N.B. These "alternative" envs are not supported, as bazel cannot distinguish between them
# and others using existing @platforms// config_values
#
#"i686-pc-windows-gnu",
#"x86_64-pc-windows-gnu",
]

# Some T2 Platforms are supported, provided we have mappings to @platforms// entries.
# See @rules_rust//rust/platform:triple_mappings.bzl for the complete list.
SUPPORTED_T2_PLATFORM_TRIPLES = [
"aarch64-apple-darwin",
"aarch64-apple-ios-sim",
"aarch64-apple-ios",
"aarch64-fuchsia",
"aarch64-linux-android",
"aarch64-pc-windows-msvc",
"arm-unknown-linux-gnueabi",
"armv7-linux-androideabi",
"armv7-unknown-linux-gnueabi",
"i686-linux-android",
"i686-unknown-freebsd",
"powerpc-unknown-linux-gnu",
"riscv32imc-unknown-none-elf",
"riscv64gc-unknown-none-elf",
"s390x-unknown-linux-gnu",
"thumbv7em-none-eabi",
"thumbv8m.main-none-eabi",
"wasm32-unknown-unknown",
"wasm32-wasi",
"x86_64-apple-ios",
"x86_64-fuchsia",
"x86_64-linux-android",
"x86_64-unknown-freebsd",
"x86_64-unknown-none",
]

# Note that only platforms with `std` artifacts should be added
# to this list: https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-3
SUPPORTED_T3_PLATFORM_TRIPLES = [
"aarch64-unknown-nto-qnx710",
]

SUPPORTED_PLATFORM_TRIPLES = SUPPORTED_T1_PLATFORM_TRIPLES + SUPPORTED_T2_PLATFORM_TRIPLES + SUPPORTED_T3_PLATFORM_TRIPLES

# CPUs that map to a "@platforms//cpu entry
}

# Some T2 Platforms are supported, provided we have mappings to `@platforms//...` entries.
# See `@rules_rust//rust/platform:triple_mappings.bzl` for the complete list.
SUPPORTED_T2_PLATFORM_TRIPLES = {
"aarch64-apple-ios": _support(std = True, host_tools = False),
"aarch64-apple-ios-sim": _support(std = True, host_tools = False),
"aarch64-fuchsia": _support(std = True, host_tools = False),
"aarch64-linux-android": _support(std = True, host_tools = False),
"aarch64-pc-windows-msvc": _support(std = True, host_tools = True),
"arm-unknown-linux-gnueabi": _support(std = True, host_tools = True),
"armv7-linux-androideabi": _support(std = True, host_tools = False),
"armv7-unknown-linux-gnueabi": _support(std = True, host_tools = True),
"i686-linux-android": _support(std = True, host_tools = False),
"i686-unknown-freebsd": _support(std = True, host_tools = False),
"powerpc-unknown-linux-gnu": _support(std = True, host_tools = True),
"riscv32imc-unknown-none-elf": _support(std = True, host_tools = False),
"riscv64gc-unknown-none-elf": _support(std = True, host_tools = False),
"s390x-unknown-linux-gnu": _support(std = True, host_tools = True),
"thumbv7em-none-eabi": _support(std = True, host_tools = False),
"thumbv8m.main-none-eabi": _support(std = True, host_tools = False),
"wasm32-unknown-unknown": _support(std = True, host_tools = False),
"wasm32-wasi": _support(std = True, host_tools = False),
"x86_64-apple-ios": _support(std = True, host_tools = False),
"x86_64-fuchsia": _support(std = True, host_tools = False),
"x86_64-linux-android": _support(std = True, host_tools = False),
"x86_64-unknown-freebsd": _support(std = True, host_tools = True),
"x86_64-unknown-none": _support(std = True, host_tools = False),
}

_T3_PLATFORM_TRIPLES = {
"aarch64-unknown-nto-qnx710": _support(std = True, host_tools = False),
"wasm64-unknown-unknown": _support(std = False, host_tools = False),
}

# The only T3 triples that are supported are ones with at least a stdlib
# artifact. However, it can be useful to know of additional triples so
# this list exists separate from the full list above.
SUPPORTED_T3_PLATFORM_TRIPLES = {
triple: support
for triple, support in _T3_PLATFORM_TRIPLES.items()
if support.std
}

SUPPORTED_PLATFORM_TRIPLES = sorted(
SUPPORTED_T1_PLATFORM_TRIPLES.keys() + SUPPORTED_T2_PLATFORM_TRIPLES.keys() + SUPPORTED_T3_PLATFORM_TRIPLES.keys(),
)

# Represents all platform triples `rules_rust` is configured to handle in some way.
# Note that with T3 platforms some artifacts may not be available which can lead to
# failures in the analysis phase. This list should be used sparingly.
ALL_PLATFORM_TRIPLES = sorted(
SUPPORTED_T1_PLATFORM_TRIPLES.keys() + SUPPORTED_T2_PLATFORM_TRIPLES.keys() + _T3_PLATFORM_TRIPLES.keys(),
)

# CPUs that map to a `@platforms//cpu` entry
_CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX = {
"aarch64": "aarch64",
"arm": "arm",
"arm64e": "arm64e",
"armv7": "armv7",
"armv7s": None,
"asmjs": None,
Expand All @@ -83,8 +119,8 @@ _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX = {
"thumbv7em": "armv7e-m",
"thumbv7m": "armv7-m",
"thumbv8m.main": "armv8-m",
"wasm32": None,
"wasm64": None,
"wasm32": "wasm32",
"wasm64": "wasm64",
"x86_64": "x86_64",
}

Expand Down

0 comments on commit 801012c

Please sign in to comment.