1# Copyright (C) 2023 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://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, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15load("@rules_rust//rust:defs.bzl", "rust_library", "rust_stdlib_filegroup") 16 17package(default_visibility = ["//visibility:public"]) 18 19exports_files(["bin/*"]) 20 21filegroup( 22 name = "binaries", 23 srcs = glob([ 24 "bin/*", 25 "lib/*", 26 "lib64/*", 27 ]), 28) 29 30# sysroot prebuilts for x86_64_unknown-linux-gnu 31rust_stdlib_filegroup( 32 name = "prebuilt_stdlibs", 33 srcs = glob(["lib/rustlib/x86_64-unknown-linux-gnu/lib/*"]), 34) 35 36# sysroot prebuilts for aarch64_unknown-uefi 37rust_stdlib_filegroup( 38 name = "aarch64-unknown-uefi_prebuilt_stdlibs", 39 srcs = glob(["lib/rustlib/aarch64-unknown-uefi/lib/*"]), 40) 41 42# sysroot prebuilts for x86_64-unknown-uefi 43rust_stdlib_filegroup( 44 name = "x86_64-unknown-uefi_prebuilt_stdlibs", 45 srcs = glob(["lib/rustlib/x86_64-unknown-uefi/lib/*"]), 46) 47 48# sysroot prebuilts for i686-unknown-uefi 49rust_stdlib_filegroup( 50 name = "i686-unknown-uefi_prebuilt_stdlibs", 51 srcs = glob(["lib/rustlib/i686-unknown-uefi/lib/*"]), 52) 53 54rust_library( 55 name = "liballoc", 56 srcs = glob(["src/stdlibs/library/alloc/src/**/*.rs"]), 57 compile_data = glob(["src/stdlibs/library/alloc/src/**/*.md"]), 58 crate_name = "alloc", 59 edition = "2021", 60 deps = [ 61 "libcompiler_builtins", 62 "libcore", 63 ], 64) 65 66COMPILER_BUILTIN_X86_SRC = "src/stdlibs/vendor/compiler_builtins/src/x86.rs" 67 68COMPILER_BUILTIN_X86_PATCH = "@gbl//patches:rust-libcompiler-builtins-enable-chkstk-on-uefi.patch" 69 70# Apply patches to x86 to enable the compiler built-in for chkstk(), alloca() function. 71# TODO(b/337114254): Remove this patch once upstream is fixed. 72genrule( 73 name = "x86_uefi_chkstk_patch", 74 srcs = [ 75 COMPILER_BUILTIN_X86_SRC, 76 COMPILER_BUILTIN_X86_PATCH, 77 ], 78 # Bazel does not let us override the same x86.rs. But module name needs to be the same. Thus we 79 # output as "x86/mod.rs" instead. 80 outs = ["src/stdlibs/vendor/compiler_builtins/src/x86/mod.rs"], 81 cmd = " cp $(location {}) $(OUTS) && patch -u -f $(OUTS) $(location {})" 82 .format(COMPILER_BUILTIN_X86_SRC, COMPILER_BUILTIN_X86_PATCH), 83) 84 85rust_library( 86 name = "libcompiler_builtins", 87 srcs = glob( 88 [ 89 "src/stdlibs/vendor/compiler_builtins/src/**/*.rs", 90 "src/stdlibs/vendor/compiler_builtins/libm/src/**/*.rs", 91 ], 92 ), 93 compile_data = glob(["src/stdlibs/vendor/compiler_builtins/src/**/*.md"]), 94 crate_features = [ 95 "compiler-builtins", 96 "core", 97 "default", 98 "mem", 99 ], 100 crate_name = "compiler_builtins", 101 edition = "2015", 102 rustc_flags = ["--cap-lints=allow"], 103 deps = ["libcore"], 104) 105 106rust_library( 107 name = "libcore", 108 srcs = glob([ 109 "src/stdlibs/library/core/src/**/*.rs", 110 "src/stdlibs/library/stdarch/crates/core_arch/src/**/*.rs", 111 "src/stdlibs/library/portable-simd/crates/core_simd/src/**/*.rs", 112 ]), 113 compile_data = glob([ 114 "src/stdlibs/library/core/src/**/*.md", 115 "src/stdlibs/library/core/primitive_docs/*.md", 116 "src/stdlibs/library/stdarch/crates/core_arch/src/**/*.md", 117 "src/stdlibs/library/portable-simd/crates/core_simd/src/**/*.md", 118 ]), 119 crate_features = ["stdsimd"], 120 crate_name = "core", 121 edition = "2021", 122 rustc_flags = ["--cap-lints=allow"], 123) 124