summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorcyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-08-25 13:12:43 +0800
committercyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-08-25 13:23:02 +0800
commitbcb690563c91596fc1127c5f57791fdc92a04ede (patch)
tree74b5c134851cd5705d9ecff17fdb6ea13e196d79 /build.rs
parent552d982c8fcb5101847c46cc5ca34babda1d7ad7 (diff)
Fix build script on Windows
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs62
1 files changed, 29 insertions, 33 deletions
diff --git a/build.rs b/build.rs
index 0f64ea4..e844eeb 100644
--- a/build.rs
+++ b/build.rs
@@ -1,54 +1,50 @@
fn main() {
#[cfg(target_os = "windows")]
- download_winpcap_sdk()
+ download_windows_pcap_sdk()
}
#[cfg(target_os = "windows")]
-fn download_winpcap_sdk() {
+fn download_windows_pcap_sdk() {
+ use std::{
+ env, fs,
+ io::{self, Write},
+ };
+
use http_req::request;
- use std::env;
- use std::fs::File;
- use std::io::prelude::*;
+ use zip::ZipArchive;
println!("cargo:rerun-if-changed=build.rs");
let out_dir = env::var("OUT_DIR").unwrap();
- let mut reader = Vec::new();
- let _res = request::get(
- "https://nmap.org/npcap/dist/npcap-sdk-1.05.zip",
- &mut reader,
- )
- .unwrap();
-
- let mut pcapzip = File::create(format!("{}{}", out_dir, "/npcap.zip")).unwrap();
- pcapzip.write_all(reader.as_slice()).unwrap();
- pcapzip.flush().unwrap();
-
- pcapzip = File::open(format!("{}{}", out_dir, "/npcap.zip")).unwrap();
-
+ let mut pcap_zip = Vec::new();
+ let res = request::get("https://npcap.com/dist/npcap-sdk-1.13.zip", &mut pcap_zip).unwrap();
+ eprintln!("{:?}", res);
+
+ let lib_dir = if cfg!(target_arch = "aarch64") {
+ "Lib/ARM64"
+ } else if cfg!(target_arch = "x86_64") {
+ "Lib/x64"
+ } else if cfg!(target_arch = "x86") {
+ "Lib"
+ } else {
+ panic!("Unsupported target!")
+ };
let lib_name = "Packet.lib";
- #[cfg(target_arch = "x86_64")]
- let lib_dir = "Lib/x64";
- #[cfg(target_arch = "x86")]
- let lib_dir = "Lib";
-
let lib_path = format!("{}/{}", lib_dir, lib_name);
- let mut zip_archive = zip::ZipArchive::new(pcapzip).unwrap();
- let mut pcaplib = match zip_archive.by_name(lib_path.as_str()) {
- Ok(pcaplib) => pcaplib,
+
+ let mut archive = ZipArchive::new(io::Cursor::new(pcap_zip)).unwrap();
+ let mut pcap_lib = match archive.by_name(&lib_path) {
+ Ok(lib) => lib,
Err(err) => {
panic!("{}", err);
}
};
- let mut pcaplib_bytes = Vec::new();
- pcaplib.read_to_end(&mut pcaplib_bytes).unwrap();
-
- std::fs::create_dir_all(format!("{}/{}", out_dir, lib_dir)).unwrap();
- let mut pcaplib_file = File::create(format!("{}/{}", out_dir, lib_path)).unwrap();
- pcaplib_file.write_all(pcaplib_bytes.as_slice()).unwrap();
- pcaplib_file.flush().unwrap();
+ fs::create_dir_all(format!("{}/{}", out_dir, lib_dir)).unwrap();
+ let mut pcap_lib_file = fs::File::create(format!("{}/{}", out_dir, lib_path)).unwrap();
+ io::copy(&mut pcap_lib, &mut pcap_lib_file).unwrap();
+ pcap_lib_file.flush().unwrap();
println!("cargo:rustc-link-search=native={}/{}", out_dir, lib_dir);
}