1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Utilities for declaring Rust toolchains that are compatible with @bazel_embedded""" 15 16load("@rules_rust//rust:toolchain.bzl", "rust_toolchain") 17 18def pw_rust_toolchain(name, exec_cpu, exec_os, target_cpu, rust_target_triple, exec_triple): 19 proxy_toolchain = "@rust_{}_{}__{}__stable_tools".format(exec_os, exec_cpu, rust_target_triple) 20 21 rust_toolchain( 22 name = "{}_impl".format(name), 23 binary_ext = "", 24 dylib_ext = ".so", 25 exec_triple = exec_triple, 26 os = "none", 27 rust_doc = "{}//:rustdoc".format(proxy_toolchain), 28 rust_std = "{}//:rust_std-{}".format(proxy_toolchain, rust_target_triple), 29 rustc = "{}//:rustc".format(proxy_toolchain), 30 rustc_lib = "{}//:rustc_lib".format(proxy_toolchain), 31 staticlib_ext = ".a", 32 stdlib_linkflags = [], 33 target_triple = rust_target_triple, 34 ) 35 36 native.toolchain( 37 name = name, 38 exec_compatible_with = [ 39 "@platforms//cpu:{}".format(exec_cpu), 40 "@platforms//os:{}".format(exec_os), 41 ], 42 target_compatible_with = [ 43 "@platforms//cpu:{}".format(target_cpu), 44 "@bazel_embedded//constraints/fpu:none", 45 ], 46 toolchain = ":{}_impl".format(name), 47 toolchain_type = "@rules_rust//rust:toolchain", 48 ) 49