Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log! macro fails when cross compiling with no_std #73

Closed
zeonin opened this issue Jan 26, 2016 · 3 comments
Closed

log! macro fails when cross compiling with no_std #73

zeonin opened this issue Jan 26, 2016 · 3 comments

Comments

@zeonin
Copy link

zeonin commented Jan 26, 2016

I'm using a nightly rustc (1.8.0-nightly, ba356ffbc 2016-01-24) on an x86_64 linux system, and trying to cross compile liblog to i686. I'm able to compile libcore and liblog just fine, but when I try to use the log! macro, rust chokes.

Compiled with rustc -L $LIB_I686_DIR --target i686-unknown-linux-gnu temp.rs

temp.rs

Output:

<log macros>:1:37: 1:50 error: unresolved name `log::INFO` [E0425]
<log macros>:1 ( $ ( $ arg : tt ) * ) => ( log ! ( :: log:: INFO , $ ( $ arg ) * ) )
                                                   ^~~~~~~~~~~~~
<log macros>:1:29: 1:68 note: in this expansion of log! (defined in <log macros>)
temp.rs:36:5: 36:27 note: in this expansion of info! (defined in <log macros>)
<log macros>:1:37: 1:50 help: run `rustc --explain E0425` to see a detailed explanation
<log macros>:3:28: 3:42 error: unresolved name `log::DEBUG` [E0425]
<log macros>:3 let lvl = $ lvl ; ( lvl != :: log:: DEBUG || cfg ! ( debug_assertions ) ) &&
                                          ^~~~~~~~~~~~~~
<log macros>:5:24: 5:45 note: in this expansion of log_enabled! (defined in <log macros>)
<log macros>:1:29: 1:68 note: in this expansion of log! (defined in <log macros>)
temp.rs:36:5: 36:27 note: in this expansion of info! (defined in <log macros>)
<log macros>:3:28: 3:42 help: run `rustc --explain E0425` to see a detailed explanation
<log macros>:4:8: 4:26 error: unresolved name `log::log_level` [E0425]
<log macros>:4 lvl <= :: log:: log_level (  ) && :: log:: mod_enabled (
                      ^~~~~~~~~~~~~~~~~~
<log macros>:5:24: 5:45 note: in this expansion of log_enabled! (defined in <log macros>)
<log macros>:1:29: 1:68 note: in this expansion of log! (defined in <log macros>)
temp.rs:36:5: 36:27 note: in this expansion of info! (defined in <log macros>)
<log macros>:4:8: 4:26 help: run `rustc --explain E0425` to see a detailed explanation
<log macros>:4:35: 4:55 error: unresolved name `log::mod_enabled` [E0425]
<log macros>:4 lvl <= :: log:: log_level (  ) && :: log:: mod_enabled (
                                                 ^~~~~~~~~~~~~~~~~~~~
<log macros>:5:24: 5:45 note: in this expansion of log_enabled! (defined in <log macros>)
<log macros>:1:29: 1:68 note: in this expansion of log! (defined in <log macros>)
temp.rs:36:5: 36:27 note: in this expansion of info! (defined in <log macros>)
<log macros>:4:35: 4:55 help: run `rustc --explain E0425` to see a detailed explanation
<log macros>:6:1: 6:13 error: unresolved name `log::log` [E0425]
<log macros>:6 :: log:: log ( lvl , & LOC , format_args ! ( $ ( $ arg ) + ) ) } } )
               ^~~~~~~~~~~~
<log macros>:1:29: 1:68 note: in this expansion of log! (defined in <log macros>)
temp.rs:36:5: 36:27 note: in this expansion of info! (defined in <log macros>)
<log macros>:6:1: 6:13 help: run `rustc --explain E0425` to see a detailed explanation
<log macros>:4:1: 4:5 error: structure `log::LogLocation` has no field named `line`
<log macros>:4 line : line ! (  ) , file : file ! (  ) , module_path : module_path ! (  ) , }
               ^~~~
<log macros>:4:1: 4:5 help: did you mean `__line`?
<log macros>:4 line : line ! (  ) , file : file ! (  ) , module_path : module_path ! (  ) , }
               ^~~~
<log macros>:4:22: 4:26 error: structure `log::LogLocation` has no field named `file`
<log macros>:4 line : line ! (  ) , file : file ! (  ) , module_path : module_path ! (  ) , }
                                    ^~~~
<log macros>:4:22: 4:26 help: did you mean `__file`?
<log macros>:4 line : line ! (  ) , file : file ! (  ) , module_path : module_path ! (  ) , }
                                    ^~~~
<log macros>:4:43: 4:54 error: structure `log::LogLocation` has no field named `module_path`
<log macros>:4 line : line ! (  ) , file : file ! (  ) , module_path : module_path ! (  ) , }
                                                         ^~~~~~~~~~~
<log macros>:4:43: 4:54 help: did you mean `__module_path`?
<log macros>:4 line : line ! (  ) , file : file ! (  ) , module_path : module_path ! (  ) , }
                                                         ^~~~~~~~~~~
error: aborting due to 8 previous errors

When I do a pretty expansion, the info!() turns into this:

{
    static LOC: ::log::LogLocation =
        ::log::LogLocation{line: 36u32,
        file: "temp.rs",
        module_path: "temp",};
    let lvl = ::log::INFO;
    if {
        let lvl = lvl;
        (lvl != ::log::DEBUG || true) && lvl <= ::log::log_level() &&
            ::log::mod_enabled(lvl, "temp")
    } {
        ::log::log(lvl, &LOC,
                   ::core::fmt::Arguments::new_v1({
                       static __STATIC_FMTSTR:
                       &'static [&'static str]
                       =
                       &["Hello World!"];
                   __STATIC_FMTSTR
                   },
                   &match () {
                       () => [],
                   }))
    }
};

It looks like rust is stripping leading underscores within the log!() macro, and converting LogLevels into all caps.

@sfackler
Copy link
Member

It looks like you're linking to rustc's internal liblog: https://github.com/rust-lang/rust/blob/master/src/liblog/lib.rs

@zeonin
Copy link
Author

zeonin commented Jan 26, 2016

Interesting!

That log!() looks like what rust has been outputting, but the errors suggest that it's trying to link against this library, using the internal macros. Is there a way to disable or override a macro definition?

@zeonin zeonin closed this as completed Jan 26, 2016
@zeonin zeonin reopened this Jan 26, 2016
@zeonin
Copy link
Author

zeonin commented Jan 26, 2016

Ah, the crate needs to be named something other than log, otherwise it attempts to pull in the macros from rust's internal liblog.

Thanks!

@zeonin zeonin closed this as completed Jan 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants