microsoft / openvmm

Home of OpenVMM and OpenHCL.
http://openvmm.dev/
MIT License
1.56k stars 80 forks source link

Support building `vmfirmwareigvm_dll` on non-Windows platforms #314

Open daprilik opened 1 week ago

daprilik commented 1 week ago

With the currently documented set of required dependencies + implemented flowey build logic, the vmfirmwareigvm_dll can only be compiled on Windows platforms.

It seems likely that, given the right set of dependencies / environment variables, it should be possible to get it compiling on other platforms (notably, via WSL2).


Alternatively, Roman suggested rewriting vmfirmwareigvm_dll to instead be a standalone tool which simply crafts a DLL file "out of thin air", using something like the object crate to build a PE executable from scratch. See https://github.com/microsoft/openvmm/pull/291#discussion_r1840799986

This is certainly an option as well, though it comes with its own set of tradeoffs and complexity spirals.

~Notably: we would need to "precompile" the resources.rc file + patch it during the build (unless we wanted to try and rewrite a subset of rc.exe functionality, which seems... unwise).~ EDIT: Roman pointed out that x86_64-w64-mingw32-windres exists for this purpose.

romank-msft commented 1 week ago

No need to re-write rc.exe, there is x86_64-w64-mingw32-windres on Linux to compile an .rc file into the .res one

romank-msft commented 1 week ago

While waiting for the build, took a gander at https://docs.rs/embed-resource/latest/embed_resource/, and that says

It is possible to embed resources in Windows executables built on non-Windows hosts. There are two ways to do this:

When targetting -pc-windows-gnu, -w64-mingw32-windres is attempted by default, for *-pc-windows-msvc it’s llvm-rc, this can be overriden by setting RC$TARGET, RC${TARGET//-/_}, or RC environment variables.

When compiling with LLVM-RC, an external C compiler is used to preprocess the resource, preloaded with configuration from cc.

llvm-rc seems to be able to handle our resource script:

llvm-rc /home/krom/src/hvlite-ms/oss/openhcl/vmfirmwareigvm_dll/resources.rc

ll ./oss/openhcl/vmfirmwareigvm_dll/resources.res
-rw-r--r-- 1 krom krom 20M Nov 13 12:08 ./oss/openhcl/vmfirmwareigvm_dll/resources.res

so hopefully no "bit-banging" with use object might be needed for the dll. Hopefully, setting the env var RC=llvm-rc (after installing LLVM) will be enough to build on Linux when someone gets to this.