phil-opp / blog_os

Writing an OS in Rust
http://os.phil-opp.com
Apache License 2.0
14.27k stars 1.01k forks source link

%1 is not a valid Win32 application. (os error 193) #1224

Closed ShaKabosh closed 1 year ago

ShaKabosh commented 1 year ago

When executing cargo run, I get the following output:

warning: unused manifest key: target.cfg(target_os = "none").runner
   Compiling compiler_builtins v0.1.91
   Compiling core v0.0.0 (C:\Users\user\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core)
   Compiling bootloader v0.9.23
   Compiling rustc-std-workspace-core v1.99.0 (C:\Users\user\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\rustc-std-workspace-core)
   Compiling spin v0.5.2
   Compiling volatile v0.2.7
   Compiling lazy_static v1.4.0
   Compiling blog_os v0.1.0 (C:\Users\user\Documents\Code\Rust\blog_os)
    Finished dev [unoptimized + debuginfo] target(s) in 14.39s
     Running `target\x86_64-kernel\debug\blog_os`
error: could not execute process `target\x86_64-kernel\debug\blog_os` (never executed)

Caused by:
  %1 is not a valid Win32 application. (os error 193)

This is my Cargo.toml:

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

[dependencies]
bootloader = "0.9.23"
volatile = "0.2.6"
lazy_static = { version = "1.0", features = ["spin_no_std"] }
spin = "0.5.2"

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

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

Here is my x86_64-kernel.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"
}

Here is my .cargo/config.toml:

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

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

I do have the bootimage crate installed. How can I fix this? Any help would be much appreciated :)

ethindp commented 1 year ago

You're not building with the right toolchain. You need to build using the custom one provided by the blog. Or if you've modified it enough you can use x86_64-unknown-none (I think that's what it is).

ShaKabosh commented 1 year ago

The toolchain is the exact same as the one from Post 2. I have renamed the toolchain config, as allowed by the tutorial. The .cargo/config.toml has, as shown, been updated to reflect the different filename.

bjorn3 commented 1 year ago

You need to set the runner in .cargo/config.toml as indicated by https://os.phil-opp.com/minimal-rust-kernel/#using-cargo-run

ShaKabosh commented 1 year ago

That's an embarrassing mistake. I've updated it, tested it, and it works! Thanks for your help :)