rules.mk: Don't depend on spin in Trusty userland

Limit use of the spin dependency and feature flag to code being built
for use in the Trusty kernel no_std environment.

Test: build.py
Bug: None
Change-Id: I21c1e459b743b5ae9813804f42cd2451b2a13131
diff --git a/cargo_embargo.json b/cargo_embargo.json
index 5cbcf7d..7a5c7b3 100644
--- a/cargo_embargo.json
+++ b/cargo_embargo.json
@@ -7,7 +7,8 @@
     "lazy_static": {
       "dep_blocklist": [
         "libdoc_comment"
-      ]
+      ],
+      "rulesmk_patch": "patches/rules.mk.diff"
     }
   },
   "variants": [
@@ -33,16 +34,7 @@
     },
     {
       "generate_androidbp": false,
-      "generate_rulesmk": true,
-      "features": [
-        "spin",
-        "spin_no_std"
-      ],
-      "package": {
-        "lazy_static": {
-          "no_std": true
-        }
-      }
+      "generate_rulesmk": true
     }
   ]
 }
diff --git a/patches/rules.mk.diff b/patches/rules.mk.diff
new file mode 100644
index 0000000..6ccc19a
--- /dev/null
+++ b/patches/rules.mk.diff
@@ -0,0 +1,25 @@
+diff --git a/rules.mk b/rules.mk.desired
+index f088ce8..89de36e 100644
+--- a/rules.mk
++++ b/rules.mk.desired
+@@ -11,5 +11,20 @@ MODULE_SRCS := $(LOCAL_DIR)/src/lib.rs
+ MODULE_RUST_EDITION := 2015
+ MODULE_LIBRARY_DEPS := \
+ 	
++ifeq ($(call TOBOOL,$(TRUSTY_USERSPACE)),false)
++
++# avoid cyclic dependence by adding dependencies manually
++MODULE_ADD_IMPLICIT_DEPS := false
++
++MODULE_RUSTFLAGS += \
++	--cfg 'feature="spin"' \
++	--cfg 'feature="spin_no_std"' \
++
++MODULE_DEPS := \
++	external/rust/crates/spin \
++	trusty/user/base/lib/libcompiler_builtins-rust \
++	trusty/user/base/lib/libcore-rust
++
++endif
+ 
+ include make/library.mk
diff --git a/rules.mk b/rules.mk
index fca012a..89de36e 100644
--- a/rules.mk
+++ b/rules.mk
@@ -8,15 +8,23 @@
 MODULE_CRATE_NAME := lazy_static
 MODULE_RUST_CRATE_TYPES := rlib
 MODULE_SRCS := $(LOCAL_DIR)/src/lib.rs
-MODULE_ADD_IMPLICIT_DEPS := false
 MODULE_RUST_EDITION := 2015
+MODULE_LIBRARY_DEPS := \
+	
+ifeq ($(call TOBOOL,$(TRUSTY_USERSPACE)),false)
+
+# avoid cyclic dependence by adding dependencies manually
+MODULE_ADD_IMPLICIT_DEPS := false
+
 MODULE_RUSTFLAGS += \
 	--cfg 'feature="spin"' \
-	--cfg 'feature="spin_no_std"'
+	--cfg 'feature="spin_no_std"' \
 
-MODULE_LIBRARY_DEPS := \
+MODULE_DEPS := \
 	external/rust/crates/spin \
 	trusty/user/base/lib/libcompiler_builtins-rust \
 	trusty/user/base/lib/libcore-rust
 
+endif
+
 include make/library.mk