Put Rust binding generation behind an explicit flag and only build bindings for the targeted Arch

Change-Id: I8ccd53bce0d73bd9d79f65770e544a75753ce4f8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/51025
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt
index d830bdd..f60ad47 100644
--- a/rust/CMakeLists.txt
+++ b/rust/CMakeLists.txt
@@ -6,57 +6,46 @@
 )
 
 # generate architecture specific wrappers
-foreach(TARGET
-    aarch64-unknown-linux-gnu
-    i686-pc-windows-gnu
-    x86_64-unknown-linux-gnu
-  )
+set(WRAPPER_TARGET ${CMAKE_BINARY_DIR}/rust/src/wrapper_${RUST_BINDINGS}.rs)
+set(COMMAND ${BINDGEN_EXECUTABLE} "wrapper.h"
+            -o ${WRAPPER_TARGET}
+            --no-derive-default
+            --enable-function-attribute-detection
+            --use-core
+            --size_t-is-usize
+            --default-macro-constant-type="signed"
+            --rustified-enum="point_conversion_form_t"
+            # These are not BoringSSL symbols, they are from glibc
+            # and are not relevant to the build besides throwing warnings
+            # about their 'long double' (aka u128) not being FFI safe.
+            # We block those functions so that the build doesn't
+            # spam warnings.
+            #
+            # https://github.com/rust-lang/rust-bindgen/issues/1549 describes the current problem
+            # and other folks' solutions.
+            #
+            # We will explore migrating to https://github.com/rust-lang/rust-bindgen/pull/2122
+            # when it lands
+            --blocklist-function="strtold"
+            --blocklist-function="qecvt"
+            --blocklist-function="qecvt_r"
+            --blocklist-function="qgcvt"
+            --blocklist-function="qfcvt"
+            --blocklist-function="qfcvt_r"
+            -- # these are LLVM arg passthroughs
+            -I../include
+            # https://doc.rust-lang.org/nightly/rustc/platform-support.html
+            --target=${RUST_BINDINGS})
 
-  set(WRAPPER_TARGET ${CMAKE_BINARY_DIR}/rust/src/wrapper_${TARGET}.rs)
-  set(COMMAND ${BINDGEN_EXECUTABLE} "wrapper.h"
-              -o ${WRAPPER_TARGET}
-              --no-derive-default
-              --enable-function-attribute-detection
-              --use-core
-              --size_t-is-usize
-              --default-macro-constant-type="signed"
-              --rustified-enum="point_conversion_form_t"
-              # These are not BoringSSL symbols, they are from glibc
-              # and are not relevant to the build besides throwing warnings
-              # about their 'long double' (aka u128) not being FFI safe.
-              # We block those functions so that the build doesn't
-              # spam warnings.
-              #
-              # https://github.com/rust-lang/rust-bindgen/issues/1549 describes the current problem
-              # and other folks' solutions.
-              #
-              # We will explore migrating to https://github.com/rust-lang/rust-bindgen/pull/2122
-              # when it lands
-              --blocklist-function="strtold"
-              --blocklist-function="qecvt"
-              --blocklist-function="qecvt_r"
-              --blocklist-function="qgcvt"
-              --blocklist-function="qfcvt"
-              --blocklist-function="qfcvt_r"
-              -- # these are LLVM arg passthroughs
-              -I../include
-              --target=${TARGET})
+set(INCLUDES "include!(\"wrapper_${RUST_BINDINGS}.rs\");\n")
 
-  add_custom_target(
-    bindgen_rust_${TARGET}
-    ALL
-    ${COMMAND}
-    BYPRODUCTS ${WRAPPER_TARGET}
-    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-  )
-  string(REPLACE "-" ";" TARGET_LIST ${TARGET})
-  list(GET TARGET_LIST 0 ARCH)
-  list(GET TARGET_LIST 1 VENDOR)
-
-  set(INCLUDES "${INCLUDES}\
-  #[cfg(all(target_arch = \"${ARCH}\", target_vendor = \"${VENDOR}\"))]\n\
-  include!(\"wrapper_${TARGET}.rs\");\n")
-endforeach()
+add_custom_target(
+  bindgen_rust_${RUST_BINDINGS}
+  ALL
+  ${COMMAND}
+  BYPRODUCTS ${WRAPPER_TARGET}
+  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
 
 # move files into build directory
 configure_file("src/lib.rs" "src/lib.rs")