summary refs log tree commit diff
path: root/pkgs/build-support/rust/build-rust-crate/lib.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/rust/build-rust-crate/lib.sh')
-rw-r--r--pkgs/build-support/rust/build-rust-crate/lib.sh27
1 files changed, 24 insertions, 3 deletions
diff --git a/pkgs/build-support/rust/build-rust-crate/lib.sh b/pkgs/build-support/rust/build-rust-crate/lib.sh
index 24c712468ea..d4d9317496f 100644
--- a/pkgs/build-support/rust/build-rust-crate/lib.sh
+++ b/pkgs/build-support/rust/build-rust-crate/lib.sh
@@ -13,6 +13,7 @@ build_lib() {
     $BUILD_OUT_DIR \
     $EXTRA_BUILD \
     $EXTRA_FEATURES \
+    $EXTRA_RUSTC_FLAGS \
     --color $colors
 
   EXTRA_LIB=" --extern $CRATE_NAME=target/lib/lib$CRATE_NAME-$metadata.rlib"
@@ -22,9 +23,10 @@ build_lib() {
 }
 
 build_bin() {
-  crate_name=$1
-  crate_name_=$(echo $crate_name | tr '-' '_')
-  main_file=""
+  local crate_name=$1
+  local crate_name_=$(echo $crate_name | tr '-' '_')
+  local main_file=""
+
   if [[ ! -z $2 ]]; then
     main_file=$2
   fi
@@ -43,6 +45,7 @@ build_bin() {
     $BUILD_OUT_DIR \
     $EXTRA_BUILD \
     $EXTRA_FEATURES \
+    $EXTRA_RUSTC_FLAGS \
     --color ${colors} \
 
   if [ "$crate_name_" != "$crate_name" ]; then
@@ -50,6 +53,24 @@ build_bin() {
   fi
 }
 
+build_lib_test() {
+    local file="$1"
+    EXTRA_RUSTC_FLAGS="--test $EXTRA_RUSTC_FLAGS" build_lib "$1" "$2"
+}
+
+build_bin_test() {
+    local crate="$1"
+    local file="$2"
+    EXTRA_RUSTC_FLAGS="--test $EXTRA_RUSTC_FLAGS" build_bin "$1" "$2"
+}
+
+build_bin_test_file() {
+    local file="$1"
+    local derived_crate_name="${file//\//_}"
+    derived_crate_name="${derived_crate_name%.rs}"
+    build_bin_test "$derived_crate_name" "$file"
+}
+
 setup_link_paths() {
   EXTRA_LIB=""
   if [[ -e target/link_ ]]; then