Use fewer dependencies in Windows build script

This removes the dependencies on the platform crate as well as the
sha256 crate, opting for the sri crate instead to check file integrity.
This commit is contained in:
Conrad Kramer 2023-05-29 05:24:24 -04:00
parent 5baf86d975
commit 3c226c81cc
4 changed files with 484 additions and 304 deletions

723
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,20 +6,19 @@ edition = "2021"
[dependencies] [dependencies]
libc = "0.2" libc = "0.2"
fehler = "1.0" fehler = "1.0"
nix = { version = "0.25", features = ["ioctl"] } nix = { version = "0.26", features = ["ioctl"] }
socket2 = "0.4" socket2 = "0.4"
tokio = { version = "1.21", features = [] } tokio = { version = "1.28", features = [] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
libloading = "0.7" libloading = "0.7"
widestring = "1.0" widestring = "1.0"
windows = { version = "0.48", features = ["Win32_Foundation", "Win32_NetworkManagement_IpHelper"] }
[target.'cfg(windows)'.build-dependencies] [target.'cfg(windows)'.build-dependencies]
anyhow = "1.0" anyhow = "1.0"
bindgen = "0.61" bindgen = "0.65"
hex-literal = "0.3"
platforms = "3.0"
reqwest = { version = "0.11", features = ["native-tls"] } reqwest = { version = "0.11", features = ["native-tls"] }
sha2 = "0.10" ssri = { version = "9.0", default-features = false }
tokio = { version = "1.21", features = ["rt"] } tokio = { version = "1.28", features = ["rt"] }
zip = { version = "0.6", features = ["deflate"] } zip = { version = "0.6", features = ["deflate"] }

View file

@ -7,10 +7,11 @@ async fn main() -> anyhow::Result<()> {
.await? .await?
.bytes() .bytes()
.await?; .await?;
assert_content_hash(
&buf, ssri::IntegrityChecker::new("sha256-B8JWGF1u42UuCfpVwLZz4mJLVl4CxLkJHHnKfS8k71E=".parse()?)
hex_literal::hex!("07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51"), .chain(&buf)
); .result()?;
let mut archive = zip::ZipArchive::new(Cursor::new(buf))?; let mut archive = zip::ZipArchive::new(Cursor::new(buf))?;
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?); let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
@ -46,13 +47,14 @@ async fn main() -> anyhow::Result<()> {
bindings.write_to_file(out_dir.join("wintun.rs"))?; bindings.write_to_file(out_dir.join("wintun.rs"))?;
let mut library = Vec::new(); let mut library = Vec::new();
let platform = platforms::Platform::find(&std::env::var("TARGET")?).unwrap(); let target = std::env::var("TARGET")?;
let arch = match platform.target_arch { let arch = match target.split("-").next() {
platforms::target::Arch::Arm => "arm", Some("i686") => "x86",
platforms::Arch::AArch64 => "arm64", Some("x86_64") => "amd64",
platforms::Arch::X86 => "x86", Some("aarch64") => "arm64",
platforms::Arch::X86_64 => "amd64", Some("thumbv7a") => "arm",
arch => panic!("{} is not a supported architecture", arch), Some(a) => panic!("{} is not a supported architecture", a),
None => unreachable!(),
}; };
archive archive
.by_name(&format!("wintun/bin/{}/wintun.dll", arch))? .by_name(&format!("wintun/bin/{}/wintun.dll", arch))?
@ -68,12 +70,3 @@ async fn main() -> anyhow::Result<()> {
fn main() { fn main() {
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
} }
#[cfg(windows)]
fn assert_content_hash(content: &[u8], hash: [u8; 32]) {
use sha2::digest::Update;
use sha2::Digest;
let computed = sha2::Sha256::new().chain(content).finalize();
assert_eq!(computed.as_slice(), &hash[..]);
}

View file

@ -1,7 +1,8 @@
use std::io::Result; use fehler::throws;
use std::io::Error;
use std::ptr; use std::ptr;
use widestring::{u16cstr, U16CString}; use widestring::{u16cstr, U16CString};
use windows::Win32::Foundation::GetLastError;
mod queue; mod queue;
pub use queue::TunQueue; pub use queue::TunQueue;
@ -13,16 +14,20 @@ pub struct TunInterface {
} }
impl TunInterface { impl TunInterface {
pub fn new() -> Result<TunInterface> { #[throws]
let name = U16CString::from(u16cstr!("ConradNet")); pub fn new() -> TunInterface {
let name = U16CString::from(u16cstr!("Burrow"));
let wintun = sys::wintun::default(); let wintun = sys::wintun::default();
let handle = let handle =
unsafe { wintun.WintunCreateAdapter(name.as_ptr(), name.as_ptr(), ptr::null()) }; unsafe { wintun.WintunCreateAdapter(name.as_ptr(), name.as_ptr(), ptr::null()) };
Ok(TunInterface { if handle.is_null() {
unsafe { GetLastError() }.ok()?
}
TunInterface {
wintun, wintun,
handle, handle,
name: String::from("ConradNet"), name: String::from("Burrow"),
}) }
} }
pub fn name(&self) -> String { pub fn name(&self) -> String {