#Unresolved import

47 messages · Page 1 of 1 (latest)

soft yacht
#

I am trying to import something into my subcrate in a Cargo workspace:

#![no_std]

use uart_16550::SerialPort;

but I am getting the following error:

unresolved import `uart_16550::SerialPort`
no `SerialPort` in the root

My Cargo.toml in the subcrate:

[package]
name = "serial"
version = "0.1.0"
edition = "2021"

[lib]
name = "serial"

[dependencies]
spin = "0.9.8"
uart_16550 = "0.2.19"

[dependencies.lazy_static]
version = "1.0"
features = ["spin_no_std"]

Any other information you need to know?

soft yacht
#

im targeting x84_64 on qemu

tender pewter
#

Also, is there a reason you’re not using the latest version of uart_16550? ferrisThink

tender pewter
soft yacht
soft yacht
# tender pewter what’s the exact command you use to build it?

cargo build --target=x86_64-os_rust.json
x86_64-os_rust.json:

{
    "llvm-target": "x86_64-unknown-none",
    "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
    "arch": "x86_64",
    "target-endian": "little",
    "target-pointer-width": "64",
    "target-c-int-width": "32",
    "os": "none",
    "executables": true,
    "linker-flavor": "ld.lld",
    "linker": "rust-lld",
    "panic-strategy": "abort",
    "disable-redzone": true,
    "features": "-mmx,-sse,+soft-float"
}
#

I’m developing on an M2

#

and using Rust Nightly

tender pewter
#

I had to run cargo +nightly build -Z build-std=core --target=x86_64-os_rust.json to get it to work for me

soft yacht
# tender pewter no `-Zbuild-std`?

no, but that doesn’t solve the problem for me
this is my .cargo/config.toml:

[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-arg=-nostartfiles"]

[target.'cfg(target_os = "windows")']
rustflags = ["-C", "link-args=/ENTRY:_start /SUBSYSTEM:console"]

[target.'cfg(target_os = "macos")']
rustflags = ["-C", "link-args=-e __start -static -nostartfiles"]

[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]

[build]
target = "x86_64-os_rust.json"

[target.'cfg(target_os = "none")']
runner = "bootimage runner"
tender pewter
#

Hmm… not able to reproduce this at all

soft yacht
#

hm

#

if you have qemu installed, run cargo run

tender pewter
#

the compiler segfaults 🥲

soft yacht
#

ok...

#

what os are you on?

tender pewter
#

I’ll try updating my rustc first lol

#

(but x86_64 linux)

soft yacht
#

huh, everything works fine on the master-branch. But there are no differences that should impact this crate

soft yacht
#

Ok, I managed to identify the problem, but don’t know how to solve it @tender pewter:
My project structure is the following:

root_crate
└── crates
    ├── test_macros
    └── serial

root_crate depends on test_macros and serial
test_macros depends on serial
If I remove that dependency from test_macro everything works

tender pewter
soft yacht
tender pewter
#

Well that would do it

#

Remove the test_macros dependency on serial

#

in all likelihood you don’t need it

#

Where do you use it?

tender pewter
#

in your case, serial cannot be compiled for the host

#

But in general, the set of crates depended on by the proc macro is entirely disjoint from the set of crates depended on by other stuff

#

If there is overlap, it is usually a sign that you misunderstand how proc macros work

soft yacht
#

the host being my own Computer, so Aarch64/M2?

tender pewter
#

Yes

#

Specifically, just because a proc macro generates code that depends on a crate X, does not mean the proc macro must itself depend on that crate X

#

You just have to use the proc macro in crates that depend on that crate X

soft yacht
tender pewter
#

As in, what happens if you just remove the dependency

soft yacht
#
#[proc_macro_attribute]
pub fn test(_attr: TokenStream, item: TokenStream) -> TokenStream {
    serial_println!("test");
    item
}
tender pewter
soft yacht
#

I’m stupid

#

This is my first time working with proc_macros

tender pewter
#

Right

soft yacht
#

thanks :)