hi, i wanna use the pe format (windows uses this) in my osdev projects kernel, and well i dont know how to do this in rust with cargo
if i do #[no_std], it still includes various windows function (i looked at the imports section via dumpbin), which i dont want, i want it to be like a C program compiled via msvc with the /NODEFAULTLIB flag, which does not include the dll imports
no_std still includes hundreds of kilobytes of support code just needed to display stack traces, and unfortunately it’s currently impossible to get rid of those without compiling your own copy of the standard library.
Not an expert at this, but my understanding is that no-std alone won't be enough. To make a kernel you also need a target triplet that isn't targeting userspace on an OS. I.e. something like x86_64-unknown-none. I have no idea how to choose PE vs ELF vs other formats here.
If you want to make user space programs for your custom OS you will probably need to make a custom target triplet, with custom a custom target specification file.
That is not true. The backtrace printing code is entirely in the panic handler of libstd. no_std has no builtin ability to produce backtraces. It does have the formatting machinery, but that doesn't import any external functions other than those provided by compiler-builtins (which all rust code depends on)
Compile with rustc main.rs -C link-arg=/entry:main -C panic=abort. There are no imports.
If using cargo then you can instead set the entry point linker argument using a build script or the RUSTFLAGS environment variable.
If you want to prevent the possibility of static libs bringing in imports then you can pass /NODEFAULTLIB to the linker the same way you do for setting the entry point.