Skip to content

Commit

Permalink
Don't trigger rerun if build artifacts change for wireguard-go-rs on …
Browse files Browse the repository at this point in the history
…Windows

This speeds up the build considerably by not always triggering a
rebuild. Replacing the artifacts and expecting a rebuild does not
seem to be a legitimate use case anyway
  • Loading branch information
dlon committed Jan 14, 2025
1 parent 213a597 commit 00670af
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions wireguard-go-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,16 @@ fn build_desktop_lib(target_os: Os) -> anyhow::Result<()> {

let dll_path = target_dir.join("libwg.dll");

println!("cargo::rerun-if-changed={}", dll_path.display());
println!(
"cargo::rerun-if-changed={}",
target_dir.join("libwg.lib").display()
);

go_build
.args(["build", "-v"])
.arg("-o")
.arg(&dll_path)
.args(["--tags", "daita"]);
// Build dynamic lib
go_build.args(["-buildmode", "c-shared"]);

go_build.env("GOOS", "windows");

generate_windows_lib(target_arch, target_dir)?;

println!("cargo::rustc-link-search={}", target_dir.to_str().unwrap());
println!("cargo::rustc-link-lib=dylib=libwg");
.args(["--tags", "daita"])
// Build DLL
.args(["-buildmode", "c-shared"])
// Needed for linking against maybenot-ffi
.env("CGO_LDFLAGS", format!("-L{}", target_dir.to_str().unwrap()))
.env("GOOS", "windows");

// Build using zig
match target_arch {
Expand All @@ -154,7 +144,10 @@ fn build_desktop_lib(target_os: Os) -> anyhow::Result<()> {
}
}

go_build.env("CGO_LDFLAGS", format!("-L{}", target_dir.to_str().unwrap()));
generate_windows_lib(target_arch, target_dir)?;

println!("cargo::rustc-link-search={}", target_dir.to_str().unwrap());
println!("cargo::rustc-link-lib=dylib=libwg");
}
Os::Linux => {
let out_file = format!("{out_dir}/libwg.a");
Expand Down Expand Up @@ -253,13 +246,14 @@ fn build_shared_maybenot_lib(out_dir: impl AsRef<Path>) -> anyhow::Result<()> {

let artifacts_dir = tmp_build_dir.join(target_triple).join(profile);

// Copy library to actual target dir
for (src, dest) in [
// Copy library to desired target dir
for (src_filename, dest_filename) in [
("maybenot_ffi.dll", "maybenot.dll"),
("maybenot_ffi.dll.lib", "maybenot.lib"),
] {
fs::copy(artifacts_dir.join(src), out_dir.as_ref().join(dest))
.with_context(|| format!("Failed to copy {src}"))?;
let dest = out_dir.as_ref().join(dest_filename);
fs::copy(artifacts_dir.join(src_filename), &dest)
.with_context(|| format!("Failed to copy {src_filename}"))?;
}

Ok(())
Expand Down

0 comments on commit 00670af

Please sign in to comment.