Skip to content

Commit a49697f

Browse files
Fix linking of libwg for debug binaries
1 parent 4e928b3 commit a49697f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

wireguard-go-rs/build-wireguard-go.sh

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ ANDROID="false"
1414
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1515
BUILD_DIR="$SCRIPT_DIR/../build"
1616

17-
# TODO: Any bad consequences by blindly overriding this ??
18-
CARGO_TARGET_DIR="$BUILD_DIR/tmp/"
19-
export CARGO_TARGET_DIR
20-
2117
while [[ "$#" -gt 0 ]]; do
2218
case $1 in
2319
--android) ANDROID="true";;
@@ -91,13 +87,15 @@ function build_unix {
9187
pushd libwg
9288
if [[ "$DAITA" == "true" ]]; then
9389
pushd wireguard-go
94-
make libmaybenot.a LIBDEST="$BUILD_DIR/lib/$TARGET"
90+
CARGO_TARGET_DIR="$BUILD_DIR/tmp/" make libmaybenot.a LIBDEST="$BUILD_DIR/lib/$TARGET"
9591
popd
9692
# TODO: This artifact needs to be available in target/<release | debug>
9793
CGO_LDFLAGS="-L$BUILD_DIR/lib/$TARGET" go build -v --tags daita -o "$BUILD_DIR/lib/$TARGET/libwg.so" -buildmode c-shared
9894
else
9995
go build -v -o "$BUILD_DIR/lib/$TARGET/libwg.so" -buildmode c-shared
10096
fi
97+
# Copy libwg to `OUT_DIR` so that we may refer to it via `OUT_DIR` in `build.rs`, which might be handy.
98+
cp "$BUILD_DIR/lib/$TARGET/libwg.so" "$OUT_DIR/libwg.so"
10199
popd
102100
}
103101

wireguard-go-rs/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ fn main() {
4747
declare_libs_dir("../build/lib");
4848

4949
println!("cargo::rerun-if-changed=libwg");
50+
51+
// Add `OUT_DIR` to the library search path to facilitate linking of libwg for debug artifacts,
52+
// such as test binaries.
53+
if cfg!(debug_assertions) {
54+
println!("cargo::rustc-link-search={out_dir}");
55+
}
5056
}
5157

5258
/// Tell linker to check `base`/$TARGET for shared libraries.

0 commit comments

Comments
 (0)