-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for windows plugins #4
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::{path::PathBuf, str::FromStr, env::var}; | ||
use anyhow::{anyhow, Result}; | ||
|
||
fn out_dir() -> Result<PathBuf> { | ||
Ok(PathBuf::from( | ||
var("OUT_DIR").map_err(|e| anyhow!("OUT_DIR not set: {e}"))?, | ||
)) | ||
} | ||
fn main() -> Result<()> { | ||
#[cfg(windows)] | ||
{ | ||
let out_dir = out_dir()?; | ||
let def_file = PathBuf::from_str("src/qemu_plugin_api.def")?; | ||
let def_file_str = def_file.to_string_lossy(); | ||
let lib_file = out_dir.join("qemu_plugin_api.lib"); | ||
let lib_file_str = lib_file.to_string_lossy(); | ||
let ch = std::process::Command::new("dlltool") | ||
.args([ | ||
"--input-def", | ||
&def_file_str, | ||
"--output-delaylib", | ||
&lib_file_str, | ||
"--dllname", | ||
"qemu.exe", | ||
]) | ||
.spawn()? | ||
.wait()?; | ||
if !ch.success() { | ||
return Err(anyhow!("dlltool failed")); | ||
} | ||
println!("cargo:rustc-link-search={}", out_dir.display()); | ||
println!("cargo:rustc-link-lib=qemu_plugin_api"); | ||
} | ||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
#!/usr/bin/env -S cargo +nightly -Z script | ||
#!/usr/bin/env -S cargo +nightly-gnu -Z script | ||
|
||
//! ```cargo | ||
//! [package] | ||
//! edition = "2021" | ||
//! [dependencies] | ||
//! anyhow = "*" | ||
//! bindgen = "*" | ||
//! cargo_metadata = "*" | ||
//! reqwest = { version = "*", features = ["blocking"] } | ||
//! tar = "*" | ||
//! xz2 = "*" | ||
//![lints.rust] | ||
//!non_snake_case = "allow" | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, to suppress warnings. It seems that this generate-bindings.rs script is intended to run standalone, but it compiles everything under src/ directory anyway. I wonder if there's a way to stop it doing that. |
||
//! ``` | ||
|
||
use anyhow::{anyhow, Result}; | ||
|
@@ -25,7 +29,7 @@ use tar::Archive; | |
use xz2::read::XzDecoder; | ||
|
||
const QEMU_SRC_URL_BASE: &str = "https://download.qemu.org/"; | ||
const QEMU_VERSION: &str = "8.1.3"; | ||
const QEMU_VERSION: &str = "8.2.0"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should really be done in a normal upgrade. Probably before this PR. |
||
|
||
fn qemu_src_url() -> String { | ||
format!("{}qemu-{}.tar.xz", QEMU_SRC_URL_BASE, QEMU_VERSION) | ||
|
@@ -70,6 +74,14 @@ fn extract_txz(archive: &Path, destination: &Path) -> Result<()> { | |
})?; | ||
Ok(()) | ||
} | ||
fn generate_windows_delaylink_library(qemu_plugin_symbols: &Path, out_dir: &Path) -> Result<()> { | ||
let def_file = out_dir.join("qemu_plugin_api.def"); | ||
let all_commands = std::fs::read_to_string(qemu_plugin_symbols)?; | ||
let all_commands = all_commands.replace(|x| "{};".contains(x), ""); | ||
std::fs::write(&def_file, format!("EXPORTS\n{all_commands}"))?; | ||
|
||
Ok(()) | ||
} | ||
tocklime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fn generate_bindings(qemu_plugin_header: &Path, destination: &Path) -> Result<()> { | ||
let rust_bindings = builder() | ||
|
@@ -139,6 +151,11 @@ fn main() -> Result<()> { | |
)?; | ||
} | ||
|
||
generate_windows_delaylink_library( | ||
&src_dir.join("plugins").join("qemu-plugins.symbols"), | ||
&out_dir, | ||
)?; | ||
|
||
generate_bindings( | ||
&src_dir | ||
.join("include") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to stop it complaining about the generated code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL, nice!