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:
parent
5baf86d975
commit
3c226c81cc
4 changed files with 484 additions and 304 deletions
723
Cargo.lock
generated
723
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -6,20 +6,19 @@ edition = "2021"
|
|||
[dependencies]
|
||||
libc = "0.2"
|
||||
fehler = "1.0"
|
||||
nix = { version = "0.25", features = ["ioctl"] }
|
||||
nix = { version = "0.26", features = ["ioctl"] }
|
||||
socket2 = "0.4"
|
||||
tokio = { version = "1.21", features = [] }
|
||||
tokio = { version = "1.28", features = [] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
libloading = "0.7"
|
||||
widestring = "1.0"
|
||||
windows = { version = "0.48", features = ["Win32_Foundation", "Win32_NetworkManagement_IpHelper"] }
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
anyhow = "1.0"
|
||||
bindgen = "0.61"
|
||||
hex-literal = "0.3"
|
||||
platforms = "3.0"
|
||||
bindgen = "0.65"
|
||||
reqwest = { version = "0.11", features = ["native-tls"] }
|
||||
sha2 = "0.10"
|
||||
tokio = { version = "1.21", features = ["rt"] }
|
||||
ssri = { version = "9.0", default-features = false }
|
||||
tokio = { version = "1.28", features = ["rt"] }
|
||||
zip = { version = "0.6", features = ["deflate"] }
|
||||
|
|
|
|||
33
tun/build.rs
33
tun/build.rs
|
|
@ -7,10 +7,11 @@ async fn main() -> anyhow::Result<()> {
|
|||
.await?
|
||||
.bytes()
|
||||
.await?;
|
||||
assert_content_hash(
|
||||
&buf,
|
||||
hex_literal::hex!("07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51"),
|
||||
);
|
||||
|
||||
ssri::IntegrityChecker::new("sha256-B8JWGF1u42UuCfpVwLZz4mJLVl4CxLkJHHnKfS8k71E=".parse()?)
|
||||
.chain(&buf)
|
||||
.result()?;
|
||||
|
||||
let mut archive = zip::ZipArchive::new(Cursor::new(buf))?;
|
||||
|
||||
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"))?;
|
||||
|
||||
let mut library = Vec::new();
|
||||
let platform = platforms::Platform::find(&std::env::var("TARGET")?).unwrap();
|
||||
let arch = match platform.target_arch {
|
||||
platforms::target::Arch::Arm => "arm",
|
||||
platforms::Arch::AArch64 => "arm64",
|
||||
platforms::Arch::X86 => "x86",
|
||||
platforms::Arch::X86_64 => "amd64",
|
||||
arch => panic!("{} is not a supported architecture", arch),
|
||||
let target = std::env::var("TARGET")?;
|
||||
let arch = match target.split("-").next() {
|
||||
Some("i686") => "x86",
|
||||
Some("x86_64") => "amd64",
|
||||
Some("aarch64") => "arm64",
|
||||
Some("thumbv7a") => "arm",
|
||||
Some(a) => panic!("{} is not a supported architecture", a),
|
||||
None => unreachable!(),
|
||||
};
|
||||
archive
|
||||
.by_name(&format!("wintun/bin/{}/wintun.dll", arch))?
|
||||
|
|
@ -68,12 +70,3 @@ async fn main() -> anyhow::Result<()> {
|
|||
fn main() {
|
||||
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[..]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use std::io::Result;
|
||||
use fehler::throws;
|
||||
use std::io::Error;
|
||||
use std::ptr;
|
||||
use widestring::{u16cstr, U16CString};
|
||||
|
||||
use windows::Win32::Foundation::GetLastError;
|
||||
mod queue;
|
||||
|
||||
pub use queue::TunQueue;
|
||||
|
|
@ -13,16 +14,20 @@ pub struct TunInterface {
|
|||
}
|
||||
|
||||
impl TunInterface {
|
||||
pub fn new() -> Result<TunInterface> {
|
||||
let name = U16CString::from(u16cstr!("ConradNet"));
|
||||
#[throws]
|
||||
pub fn new() -> TunInterface {
|
||||
let name = U16CString::from(u16cstr!("Burrow"));
|
||||
let wintun = sys::wintun::default();
|
||||
let handle =
|
||||
unsafe { wintun.WintunCreateAdapter(name.as_ptr(), name.as_ptr(), ptr::null()) };
|
||||
Ok(TunInterface {
|
||||
if handle.is_null() {
|
||||
unsafe { GetLastError() }.ok()?
|
||||
}
|
||||
TunInterface {
|
||||
wintun,
|
||||
handle,
|
||||
name: String::from("ConradNet"),
|
||||
})
|
||||
name: String::from("Burrow"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue