rust-osdev / cargo-xbuild

Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.
Apache License 2.0
258 stars 25 forks source link

Still need `extern crate` when using Rust 2018 #17

Closed abbec closed 5 years ago

abbec commented 5 years ago

I recently ported some of our OS code to Rust 2018 and then a binary crate depending on a library crate does not compile if I remove the extern crate statement from it's main. The same example works when not cross-compiling (with a normal cargo build) so I guess it is something with the way cargo-xbuild works.

The error I get is this

  |                                                                                                                                                                                                                                                                                                                                    
7 | use salmiak::gpu;                                                                                                                                                                                                                                                                                                                  
  |     ^^^^^^^ Maybe a missing `extern crate salmiak;`?
abbec commented 5 years ago

I also get: error:#[panic_handler]function required, but not found and that one is implemented in the lib, can it have something to do with that?

phil-opp commented 5 years ago

Thanks for reporting! I tried to port blog_os to Rust 2018 but couldn't import the println macro from the library crate. It works if I keep #[macro_use] extern crate blog_os, but with a use statement I get:

error[E0432]: unresolved import `blog_os::vga_buffer::println`                  
 --> src/main.rs:6:5                                                            
  |             
6 | use blog_os::vga_buffer::println;                                           
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `println` in `vga_buffer`. Did you mean to use `print`?

Maybe that's a similar issue? (Although it seems to find the blog_os crate, otherwise it wouldn't make that suggestion.)

What's the output with --verbose? Do you have your code online somewhere so that I can test it?

abbec commented 5 years ago

That is kinda expected though and not the same issue :) My issue persists even if I comment out all macro usages. The code is in a private gitlab repo which I am happy to give you access to if you have an account on gitlab.com!

abbec commented 5 years ago

And this is verbose output:

cargo xbuild --release --target aarch64-unknown-none -vvvv
       Fresh salmiak v0.1.0 (/home/abbe/code/salmiak/salmiak)
   Compiling sneka v0.1.0 (/home/abbe/code/salmiak/sneka)
     Running `rustc --crate-name sneka sneka/src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C metadata=5ca3193d685df7f0 -C extra-filename=-5ca3193d685df7f0 --out-dir /home/abbe/code/salmiak/target/aarch64-unknown-none/release/deps --target aarch64-unknown-none -L dependency=/home/abbe/code/salmiak/target/aarch64-unknown-none/release/deps -L dependency=/home/abbe/code/salmiak/target/release/deps --extern salmiak=/home/abbe/code/salmiak/target/aarch64-unknown-none/release/deps/libsalmiak-b6e53d67c6a0c203.rlib -C link-arg=-Tlink.ld -C target-feature=-fp-armv8,+strict-align -C target-cpu=cortex-a53 --sysroot /home/abbe/code/salmiak/target/sysroot`
error[E0432]: unresolved import `salmiak`
 --> sneka/src/main.rs:7:5
  |
7 | use salmiak::gpu;
  |     ^^^^^^^ Maybe a missing `extern crate salmiak;`?

error: `#[panic_handler]` function required, but not found

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0432`.
error: Could not compile `sneka`.
abbec commented 5 years ago

Actually nevermind, PEBCAK, I had an unsaved file (the Cargo.toml of the binary...)

phil-opp commented 5 years ago

Ah, thanks for the update :).

That is kinda expected though

I thought you could import macros with normal use statements now?

abbec commented 5 years ago

Yeah, unless you use macros from the crate :)