[rust] Add make rules for std and its deps

Bug: 193278128
Test: build.py
Change-Id: I0927d87390e20dcf9dc11a37a96cc7eae2be8fe8
diff --git a/lib/libhashbrown-rust/rules.mk b/lib/libhashbrown-rust/rules.mk
new file mode 100644
index 0000000..a796560
--- /dev/null
+++ b/lib/libhashbrown-rust/rules.mk
@@ -0,0 +1,46 @@
+# Copyright (C) 2021 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.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+HASHBROWN_DIR = $(RUST_BINDIR)/../src/stdlibs/vendor/hashbrown
+
+MODULE_SRCS := $(HASHBROWN_DIR)/src/lib.rs
+
+MODULE_CRATE_NAME := hashbrown
+
+MODULE_RUST_EDITION := 2021
+
+MODULE_ADD_IMPLICIT_DEPS := false
+
+MODULE_RUSTFLAGS += \
+	--cfg 'feature="rustc-dep-of-std"' \
+	--cfg 'feature="nightly"' \
+	--cfg 'feature="rustc-internal-api"' \
+
+# Suppress warnings since the crate generates warnings when being built as a
+# dependency of std. We use `--cap-lints=allow` because that's done when
+# building dependencies for rustc.
+MODULE_RUSTFLAGS += \
+	--cap-lints=allow \
+
+MODULE_LIBRARY_DEPS += \
+	trusty/user/base/lib/libcore-rust \
+	trusty/user/base/lib/liballoc-rust \
+	trusty/user/base/lib/libcompiler_builtins-rust \
+
+include make/library.mk
diff --git a/lib/libpanic_abort-rust/rules.mk b/lib/libpanic_abort-rust/rules.mk
new file mode 100644
index 0000000..61a03be
--- /dev/null
+++ b/lib/libpanic_abort-rust/rules.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2022 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.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+SRC_DIR := $(RUST_BINDIR)/../src/stdlibs/library/panic_abort
+
+MODULE_SRCS := $(SRC_DIR)/src/lib.rs
+
+MODULE_CRATE_NAME := panic_abort
+
+MODULE_RUST_EDITION := 2021
+
+MODULE_LIBRARY_DEPS += \
+	trusty/user/base/lib/liballoc-rust \
+	trusty/user/base/lib/cfg-if-rust \
+	trusty/user/base/lib/libcore-rust \
+	trusty/user/base/lib/libc-rust \
+	trusty/user/base/lib/libcompiler_builtins-rust \
+
+include make/library.mk
diff --git a/lib/librustc-demangle-rust/rules.mk b/lib/librustc-demangle-rust/rules.mk
new file mode 100644
index 0000000..80de0f2
--- /dev/null
+++ b/lib/librustc-demangle-rust/rules.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2022 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.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+RUSTC_DEMANGLE_DIR = $(RUST_BINDIR)/../src/stdlibs/vendor/rustc-demangle
+
+MODULE_SRCS := $(RUSTC_DEMANGLE_DIR)/src/lib.rs
+
+MODULE_CRATE_NAME := rustc_demangle
+
+MODULE_RUST_EDITION := 2015
+
+MODULE_RUSTFLAGS += \
+	--cfg 'feature="rustc-dep-of-std"' \
+
+MODULE_LIBRARY_DEPS += \
+	trusty/user/base/lib/libcompiler_builtins-rust \
+	trusty/user/base/lib/libcore-rust \
+
+include make/library.mk
diff --git a/lib/libstd-rust/rules.mk b/lib/libstd-rust/rules.mk
new file mode 100644
index 0000000..2778d5c
--- /dev/null
+++ b/lib/libstd-rust/rules.mk
@@ -0,0 +1,61 @@
+# Copyright (C) 2022 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.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+LIBSTD_DIR = $(RUST_BINDIR)/../src/stdlibs/library/std
+
+MODULE_SRCS := $(LIBSTD_DIR)/src/lib.rs
+
+MODULE_CRATE_NAME := std
+
+MODULE_RUST_EDITION := 2018
+
+MODULE_LIBRARY_DEPS += \
+	trusty/user/base/lib/libcore-rust \
+	trusty/user/base/lib/libc-rust \
+	trusty/user/base/lib/liballoc-rust \
+	trusty/user/base/lib/libunwind-rust \
+	trusty/user/base/lib/libhashbrown-rust \
+	trusty/user/base/lib/libstd_detect-rust \
+	trusty/user/base/lib/librustc-demangle-rust \
+	trusty/user/base/lib/libpanic_abort-rust \
+
+MODULE_RUSTFLAGS += \
+	--cfg 'backtrace_in_libstd' \
+	-Z force-unstable-if-unmarked \
+
+# Suppress known warnings. The libstd source code generates warnings which are
+# normally suppressed with `--cap-lints=allow` during the rustbuild process. We
+# opt to suppress lints individually in order to avoid missing warnings that
+# might be specific to the Trusty build process. These may need to be updated
+# for future Rust releases.
+MODULE_RUSTFLAGS += \
+	-A unused-variables \
+	-A non-fmt-panics \
+
+MODULE_ADD_IMPLICIT_DEPS := false
+
+ifeq ($(ARCH),arm)
+MODULE_RUST_ENV += STD_ENV_ARCH=arm
+else ifeq ($(ARCH),arm64)
+MODULE_RUST_ENV += STD_ENV_ARCH=aarch64
+else
+$(error Unrecognized arch $(ARCH), expected arm or arm64)
+endif
+
+include make/library.mk
diff --git a/lib/libstd_detect-rust/rules.mk b/lib/libstd_detect-rust/rules.mk
new file mode 100644
index 0000000..11abade
--- /dev/null
+++ b/lib/libstd_detect-rust/rules.mk
@@ -0,0 +1,38 @@
+# Copyright (C) 2021 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.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+SRC_DIR = $(RUST_BINDIR)/../src/stdlibs/library/stdarch/crates/std_detect
+
+MODULE_SRCS := $(SRC_DIR)/src/lib.rs
+
+MODULE_CRATE_NAME := std_detect
+
+MODULE_RUST_EDITION := 2018
+
+MODULE_RUSTFLAGS += \
+	--cfg 'feature="rustc-dep-of-std"' \
+
+MODULE_LIBRARY_DEPS += \
+	trusty/user/base/lib/libcore-rust \
+	trusty/user/base/lib/libc-rust \
+	trusty/user/base/lib/liballoc-rust \
+	trusty/user/base/lib/libcompiler_builtins-rust \
+	trusty/user/base/lib/cfg-if-rust \
+
+include make/library.mk
diff --git a/lib/libunwind-rust/rules.mk b/lib/libunwind-rust/rules.mk
new file mode 100644
index 0000000..884cde2
--- /dev/null
+++ b/lib/libunwind-rust/rules.mk
@@ -0,0 +1,36 @@
+# Copyright (C) 2021 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.
+#
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+LIBUNWIND_DIR = $(RUST_BINDIR)/../src/stdlibs/library/unwind
+
+MODULE_SRCS := $(LIBUNWIND_DIR)/src/lib.rs
+
+MODULE_CRATE_NAME := unwind
+
+MODULE_RUST_EDITION := 2021
+
+MODULE_LIBRARY_DEPS += \
+	trusty/user/base/lib/libcore-rust \
+	trusty/user/base/lib/libc-rust \
+	trusty/user/base/lib/libcompiler_builtins-rust \
+	trusty/user/base/lib/cfg-if-rust \
+
+MODULE_ADD_IMPLICIT_DEPS := false
+
+include make/library.mk