# Copyright (C) 2023 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. load("@rules_rust//rust:defs.bzl", "rust_library", "rust_stdlib_filegroup") package(default_visibility = ["//visibility:public"]) exports_files(["bin/*"]) filegroup( name = "binaries", srcs = glob([ "bin/*", "lib/*", "lib64/*", ]), ) # sysroot prebuilts for x86_64_unknown-linux-gnu rust_stdlib_filegroup( name = "prebuilt_stdlibs", srcs = glob(["lib/rustlib/x86_64-unknown-linux-gnu/lib/*"]), ) # sysroot prebuilts for aarch64_unknown-uefi rust_stdlib_filegroup( name = "aarch64-unknown-uefi_prebuilt_stdlibs", srcs = glob(["lib/rustlib/aarch64-unknown-uefi/lib/*"]), ) # sysroot prebuilts for x86_64-unknown-uefi rust_stdlib_filegroup( name = "x86_64-unknown-uefi_prebuilt_stdlibs", srcs = glob(["lib/rustlib/x86_64-unknown-uefi/lib/*"]), ) # sysroot prebuilts for i686-unknown-uefi rust_stdlib_filegroup( name = "i686-unknown-uefi_prebuilt_stdlibs", srcs = glob(["lib/rustlib/i686-unknown-uefi/lib/*"]), ) rust_library( name = "liballoc", srcs = glob(["src/stdlibs/library/alloc/src/**/*.rs"]), compile_data = glob(["src/stdlibs/library/alloc/src/**/*.md"]), crate_name = "alloc", edition = "2021", deps = [ "libcompiler_builtins", "libcore", ], ) COMPILER_BUILTIN_X86_SRC = "src/stdlibs/vendor/compiler_builtins/src/x86.rs" COMPILER_BUILTIN_X86_PATCH = "@gbl//patches:rust-libcompiler-builtins-enable-chkstk-on-uefi.patch" # Apply patches to x86 to enable the compiler built-in for chkstk(), alloca() function. # TODO(b/337114254): Remove this patch once upstream is fixed. genrule( name = "x86_uefi_chkstk_patch", srcs = [ COMPILER_BUILTIN_X86_SRC, COMPILER_BUILTIN_X86_PATCH, ], # Bazel does not let us override the same x86.rs. But module name needs to be the same. Thus we # output as "x86/mod.rs" instead. outs = ["src/stdlibs/vendor/compiler_builtins/src/x86/mod.rs"], cmd = " cp $(location {}) $(OUTS) && patch -u -f $(OUTS) $(location {})" .format(COMPILER_BUILTIN_X86_SRC, COMPILER_BUILTIN_X86_PATCH), ) rust_library( name = "libcompiler_builtins", srcs = glob( [ "src/stdlibs/vendor/compiler_builtins/src/**/*.rs", "src/stdlibs/vendor/compiler_builtins/libm/src/**/*.rs", ], ), compile_data = glob(["src/stdlibs/vendor/compiler_builtins/src/**/*.md"]), crate_features = [ "compiler-builtins", "core", "default", "mem", ], crate_name = "compiler_builtins", edition = "2015", rustc_flags = ["--cap-lints=allow"], deps = ["libcore"], ) rust_library( name = "libcore", srcs = glob([ "src/stdlibs/library/core/src/**/*.rs", "src/stdlibs/library/stdarch/crates/core_arch/src/**/*.rs", "src/stdlibs/library/portable-simd/crates/core_simd/src/**/*.rs", ]), compile_data = glob([ "src/stdlibs/library/core/src/**/*.md", "src/stdlibs/library/core/primitive_docs/*.md", "src/stdlibs/library/stdarch/crates/core_arch/src/**/*.md", "src/stdlibs/library/portable-simd/crates/core_simd/src/**/*.md", ]), crate_features = ["stdsimd"], crate_name = "core", edition = "2021", rustc_flags = ["--cap-lints=allow"], )