fabricedesre / cc3200-rs

Getting Rust to run on a TI cc3200
Mozilla Public License 2.0
7 stars 2 forks source link

Remove duplicate print() and println() from cc3200.rs #44

Closed tdz closed 7 years ago

tdz commented 7 years ago

The macros print() and println() are provided by the logger module. This patch removes them from cc3200.rs.

tdz commented 7 years ago

Fixes the problem described at https://github.com/mozilla-sensorweb/sensorweb-firmware/issues/32

dhylands commented 7 years ago

I've noticed similar failures like the one on Travis, and I haven't figured out how to fix this.

dhylands commented 7 years ago

I think I figured it out. You need to add an additional level of braces to the print macro in logger.

diff --git a/src/logger.rs b/src/logger.rs
index 93b715e..9cb8c16 100644
--- a/src/logger.rs
+++ b/src/logger.rs
@@ -8,14 +8,14 @@ use log::{self, LogRecord, LogLevelFilter, LogMetadata, SetLoggerError};

 #[macro_export]
 macro_rules! print {
-    ($($args:tt)*) => {
+    ($($args:tt)*) => {{
         // Ignore logging errors. It's not worth killing the program because of
         // failed debug output. It would be nicer to save the error and report
         // it later, however.
         use core::fmt::Write;
         let mut console = $crate::cc3200::Console {};
         let _ = write!(console, $($args)*);
-    }
+    }}
 }

 #[macro_export]

With that minor addition then all of the examples build cleanly.

tdz commented 7 years ago

With both patches applied, it builds locally and on Travis.

dhylands commented 7 years ago

I also figured out that you can look a "macro expanded" version of the source by doing:

xargo rustc --target=thumbv7em-none-eabi --example XXX -- -Z unstable-options --pretty=expanded

Replace XXX by the name of the example you're trying to build. Then it was obvious the outer braces are not included in the generated source.

dhylands commented 7 years ago

This looks good to me - r+

fabricedesre commented 7 years ago

Ok, let's take that. Still would like to know if we hit a rustc bug or not...