Skip to content
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

Allow specifying additional target triples in rust_register_toolchains() and fix androideabi system #1181

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rust/platform/triple.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def triple(triple):
system = component_parts[2]
abi = None

if system == "androideabi":
system = "android"
abi = "eabi"

if len(component_parts) == 4:
abi = component_parts[3]

Expand Down
78 changes: 14 additions & 64 deletions rust/platform/triple_mappings.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Helpers for constructing supported Rust platform triples"""

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

# All T1 Platforms should be supported, but aren't, see inline notes.
SUPPORTED_T1_PLATFORM_TRIPLES = [
"i686-apple-darwin",
Expand Down Expand Up @@ -196,58 +198,16 @@ def abi_to_constraints(abi):
# figure out how they're doing this
return []

def triple_to_system(triple):
def triple_to_system(target_triple):
"""Returns a system name for a given platform triple

Args:
triple (str): A platform triple. eg: `x86_64-unknown-linux-gnu`
target_triple (str): A platform triple. eg: `x86_64-unknown-linux-gnu`

Returns:
str: A system name
"""
if triple == "wasm32-wasi":
return "wasi"

component_parts = triple.split("-")
if len(component_parts) < 3:
fail("Expected target triple to contain at least three sections separated by '-'")

return component_parts[2]

def triple_to_arch(triple):
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
"""Returns a system architecture name for a given platform triple

Args:
triple (str): A platform triple. eg: `x86_64-unknown-linux-gnu`

Returns:
str: A cpu architecture
"""
if triple == "wasm32-wasi":
return "wasi"

component_parts = triple.split("-")
if len(component_parts) < 3:
fail("Expected target triple to contain at least three sections separated by '-'")

return component_parts[0]

def triple_to_abi(triple):
"""Returns a system abi name for a given platform triple

Args:
triple (str): A platform triple. eg: `x86_64-unknown-linux-gnu`

Returns:
str: The triple's abi
"""
component_parts = triple.split("-")
if len(component_parts) < 3:
fail("Expected target triple to contain at least three sections separated by '-'")

if len(component_parts) >= 4:
return component_parts[3]
return None
return triple(target_triple).system

def system_to_dylib_ext(system):
return _SYSTEM_TO_DYLIB_EXT[system]
Expand All @@ -261,42 +221,32 @@ def system_to_binary_ext(system):
def system_to_stdlib_linkflags(system):
return _SYSTEM_TO_STDLIB_LINKFLAGS[system]

def triple_to_constraint_set(triple):
def triple_to_constraint_set(target_triple):
"""Returns a set of constraints for a given platform triple

Args:
triple (str): A platform triple. eg: `x86_64-unknown-linux-gnu`
target_triple (str): A platform triple. eg: `x86_64-unknown-linux-gnu`

Returns:
list: A list of constraints (each represented by a list of strings)
"""
if triple == "wasm32-wasi":
if target_triple == "wasm32-wasi":
return [
"@rules_rust//rust/platform/cpu:wasm32",
"@rules_rust//rust/platform/os:wasi",
]
if triple == "wasm32-unknown-unknown":
if target_triple == "wasm32-unknown-unknown":
return [
"@rules_rust//rust/platform/cpu:wasm32",
"@rules_rust//rust/platform/os:unknown",
]

component_parts = triple.split("-")
if len(component_parts) < 3:
fail("Expected target triple to contain at least three sections separated by '-'")

cpu_arch = component_parts[0]
vendor = component_parts[1]
system = component_parts[2]
abi = None

if len(component_parts) == 4:
abi = component_parts[3]
triple_struct = triple(target_triple)

constraint_set = []
constraint_set += cpu_arch_to_constraints(cpu_arch)
constraint_set += vendor_to_constraints(vendor)
constraint_set += system_to_constraints(system)
constraint_set += abi_to_constraints(abi)
constraint_set += cpu_arch_to_constraints(triple_struct.arch)
constraint_set += vendor_to_constraints(triple_struct.vendor)
constraint_set += system_to_constraints(triple_struct.system)
constraint_set += abi_to_constraints(triple_struct.abi)

return constraint_set
4 changes: 3 additions & 1 deletion rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def rust_register_toolchains(
register_toolchains = True,
rustfmt_version = None,
sha256s = None,
extra_target_triples = ["wasm32-unknown-unknown", "wasm32-wasi"],
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
version = rust_common.default_version):
"""Emits a default set of toolchains for Linux, MacOS, and Freebsd
Expand Down Expand Up @@ -97,6 +98,7 @@ def rust_register_toolchains(
register_toolchains (bool): If true, repositories will be generated to produce and register `rust_toolchain` targets.
rustfmt_version (str, optional): The version of rustfmt. Either "nightly", "beta", or an exact version. Defaults to `version` if not specified.
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes.
extra_target_triples (list, optional): Additional rust-style targets that rust toolchains should support.
urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).
version (str, optional): The version of Rust. Either "nightly", "beta", or an exact version. Defaults to a modern version.
"""
Expand All @@ -113,7 +115,7 @@ def rust_register_toolchains(
dev_components = dev_components,
edition = edition,
exec_triple = exec_triple,
extra_target_triples = ["wasm32-unknown-unknown", "wasm32-wasi"],
extra_target_triples = extra_target_triples,
include_rustc_srcs = include_rustc_srcs,
iso_date = iso_date,
register_toolchain = register_toolchains,
Expand Down