change proc-macro debugging code to be feature gated
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 2 Sep 2021 23:00:58 +0000 (16:00 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 2 Sep 2021 23:00:58 +0000 (16:00 -0700)
.gitignore
power-instruction-analyzer-proc-macro/Cargo.toml
power-instruction-analyzer-proc-macro/src/lib.rs

index c7acde7874d6674fdf6808bce5b402a19a759e22..54c4c800c5016351b02034baf62cd5df46670590 100644 (file)
@@ -2,3 +2,4 @@
 __pycache__
 *.pyc
 /output-for-*
+/proc-macro-out.rs
index 6b1b1931a79443906ae4206d5aeb15e11f027806..c2cc3a05c0217d7a719768b2afbbdb068bb659ec 100644 (file)
@@ -15,3 +15,6 @@ proc-macro = true
 quote = "1.0"
 proc-macro2 = "1.0"
 syn = { version = "1.0", features = ["full", "parsing", "extra-traits"] }
+
+[features]
+debug-proc-macro = []
index 923363bb490356b40d819b1ae556cf7e5e356f47..cd6d34257b4c9aaadefd7f3aedfbfbe2abef7860 100644 (file)
@@ -16,13 +16,18 @@ pub fn instructions(input: TokenStream) -> TokenStream {
     let input = parse_macro_input!(input as Instructions);
     match input.to_tokens() {
         Ok(retval) => {
-            fs::write(
-                Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("out.rs"),
-                retval.to_string(),
-            )
-            .unwrap();
-            quote! {
-                include!(concat!(env!("CARGO_MANIFEST_DIR"), "/out.rs"));
+            if cfg!(feature = "debug-proc-macro") {
+                fs::write(
+                    Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap())
+                        .join("proc-macro-out.rs"),
+                    retval.to_string(),
+                )
+                .unwrap();
+                quote! {
+                    include!(concat!(env!("CARGO_MANIFEST_DIR"), "/proc-macro-out.rs"));
+                }
+            } else {
+                retval
             }
         }
         Err(err) => err.to_compile_error(),