Skip to content

Conversation

@bonzini
Copy link
Contributor

@bonzini bonzini commented Aug 12, 2025

Using cargo cbuild and cargo cinstall has various advantages:

  • it is able to generate a shared library (cdylib - this is important because if you have two dependencies that are Rust staticlibs, they final link will fail due to duplicate symbols)

  • it takes care of generating the .pc file and correctly includes the dependencies of the Rust standard library. This makes it possible to cross-compile not just libigvm, but also dump_igvm, and to easily link with the static libigvm.a after they've been installed into $(DESTDIR)/$(PREFIX).

Do not include the .h files on the command line; do not include
the library twice, once via $^ and once via -ligvm.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini bonzini requested a review from a team as a code owner August 12, 2025 17:11
@bonzini
Copy link
Contributor Author

bonzini commented Aug 12, 2025

@microsoft-github-policy-service agree company="Red Hat, Inc."

@bonzini bonzini force-pushed the cargo-c branch 2 times, most recently from ef1f374 to 202c9b6 Compare August 12, 2025 17:27
cargo-c is able to generate a shared library and takes care of creating the
.pc file as well.

The main change that is needed for the Makefile is that libraries are
placed in a subdirectory of the CARGO_TARGET_DIR.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The Rust runtime dependencies may vary depending on the target.  cargo-c
is able to place them in the .pc file, and also builds a .pc file that
can be used before installation.

This fixes cross compilation under Windows, which can be done with

   make -C igvm_c CARGO_BUILD_TARGET=x86_64-pc-windows-gnu EXTRA_PARAMS="--target x86_64-pc-windows-gnu" CC=x86_64-w64-mingw32-gcc

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This finally makes it possible to *install* a cross-compiled Windows build,
albeit with a manual "EXE=.exe" on the command line.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini
Copy link
Contributor Author

bonzini commented Aug 12, 2025

@chris-oo
Copy link
Member

Neat, thanks for the contribution. I've set it to automerge.

@chris-oo chris-oo enabled auto-merge (squash) August 12, 2025 19:34
@chris-oo chris-oo disabled auto-merge August 12, 2025 19:34
@chris-oo chris-oo changed the title switch igvm_c Makefile to cargo-c igvm_c: switch Makefile to cargo-c Aug 12, 2025
@chris-oo chris-oo enabled auto-merge (squash) August 12, 2025 19:35
@chris-oo chris-oo merged commit b5d7ed6 into microsoft:main Aug 12, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants