From 684e62e9039d4c8b1a80edc219519d353d64adbb Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 12 Mar 2020 00:50:45 +1300 Subject: [PATCH] Fix Rust static library linking for Windows builds The library renaming step is necessary because the naming convention used by rustc does not match the naming convention for libtool/MinGW. --- configure.ac | 1 + src/Makefile.am | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 9958a3783..66bb96316 100644 --- a/configure.ac +++ b/configure.ac @@ -821,6 +821,7 @@ fi RUST_LIBS="" case $host in *mingw*) + RUST_LIBS="$RUST_LIBS -luserenv" ;; *) RUST_LIBS="$RUST_LIBS -ldl" diff --git a/src/Makefile.am b/src/Makefile.am index 81acc739e..8dfd66524 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,11 +38,7 @@ LIBBITCOIN_COMMON=libbitcoin_common.a LIBBITCOIN_CLI=libbitcoin_cli.a LIBBITCOIN_UTIL=libbitcoin_util.a LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a -if TARGET_WINDOWS -LIBRUSTZCASH=$(top_builddir)/target/$(RUST_TARGET)/release/rustzcash.lib -else LIBRUSTZCASH=$(top_builddir)/target/$(RUST_TARGET)/release/librustzcash.a -endif LIBSECP256K1=secp256k1/libsecp256k1.la LIBUNIVALUE=univalue/libunivalue.la LIBZCASH=libzcash.a @@ -85,7 +81,19 @@ endif cargo-build: $(CARGO_CONFIGURED) $(RUST_ENV_VARS) $(CARGO) build $(RUST_BUILD_OPTS) --manifest-path $(top_srcdir)/Cargo.toml +if TARGET_WINDOWS +LIBRUSTZCASH_WIN=$(top_builddir)/target/$(RUST_TARGET)/release/rustzcash.lib + +$(LIBRUSTZCASH_WIN): cargo-build + +# This ensures that the Rust library is correctly linked in by libtool. +# See https://github.com/rust-lang/rust/issues/69904 for the underlying cause. +$(LIBRUSTZCASH): $(LIBRUSTZCASH_WIN) + $(AM_V_at)cp $< $@ + +else $(LIBRUSTZCASH): cargo-build +endif $(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*) $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)