blog_os icon indicating copy to clipboard operation
blog_os copied to clipboard

error: could not compile `x86_64`

Open GraydenH opened this issue 2 years ago • 6 comments

Hi, I tried to follow the "Testing" post but ran into errors after adding the x86_64 crate

error: cannot find macro `asm` in this scope
  --> C:\Users\grayd\.cargo\registry\src\github.com-1ecc6299db9ec823\x86_64-0.13.2\src\instructions\interrupts.rs:18:9
   |
18 |         asm!("sti", options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: could not compile `x86_64` due to 42 previous errors
warning: build failed, waiting for other jobs to finish...
Error: Bootloader build failed.
Stderr:

cargo.toml

[package]
name = "os"
version = "0.1.0"
authors = ["Grayden Hormes <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bootloader = "0.9.8"
volatile = "0.2.6"
spin = "0.5.2"
x86_64 = "0.14.2"

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

[package.metadata.bootimage]
test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"]

main.rs

#![no_std]
#![no_main]

#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]

use core::panic::PanicInfo;

mod vga_buffer;

#[no_mangle]
pub extern "C" fn _start() -> ! {
    println!("Hello World{}", "!");

    #[cfg(test)]
    test_main();

    loop {}
}

/// This function is called on panic.
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    println!("{}", info);
    loop {}
}

#[cfg(test)]
fn test_runner(tests: &[&dyn Fn()]) {
    println!("Running {} tests", tests.len());
    for test in tests {
        test();
    }
    /// new
    exit_qemu(QemuExitCode::Success);
}

#[test_case]
fn trivial_assertion() {
    print!("trivial assertion... ");
    assert_eq!(1, 1);
    println!("[ok]");
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum QemuExitCode {
    Success = 0x10,
    Failed = 0x11,
}

pub fn exit_qemu(exit_code: QemuExitCode) {
    use x86_64::instructions::port::Port;

    unsafe {
        let mut port = Port::new(0xf4);
        port.write(exit_code as u32);
    }
}

I tried with x86_64 = "0.14.9" and updated my nightly from 1.5.0 to 1.6.2 but no changes.

GraydenH avatar Apr 08 '22 17:04 GraydenH

In the output you posted, note that it is using x86_64 v0.13.2 ([...]x86_64-0.13.2[...]) which is a very old version. Use the latest version of x86_64 (version 0.14.9) which should correct this issue. Also, make sure that your nightly is at least version 1.59.0. You can also try running cargo clean before building again.

toothbrush7777777 avatar Apr 14 '22 13:04 toothbrush7777777

I'm getting the same error, tried everything I could but nothing fixes it

HipyCas avatar Apr 24 '22 14:04 HipyCas

Try running cargo tree and post the output.

toothbrush7777777 avatar Apr 25 '22 09:04 toothbrush7777777

Same problem but I find it was already fixed.
try to update bootloader to at least 0.9.20
see:
https://github.com/phil-opp/blog_os/issues/1066

fairjm avatar May 01 '22 09:05 fairjm

As @fairjm says, uploading bootloader to the latest version fixes the problem. Thanks everyone for your help!

HipyCas avatar May 01 '22 18:05 HipyCas

I had the same issue as above but it only occurred in my windows environment and not in my WSL environment even after following the steps outlined above.

I ended up running rustup update and that appears to have fixed the issue in my windows environment

byoboo avatar Jul 06 '22 22:07 byoboo

Looks like this issue is solved.

phil-opp avatar Aug 19 '22 15:08 phil-opp