On Windows, crate() deps appear not to propagate dependent libraries correctly
There is a crate called 'windows-sys' that I believe exports a windows.lib library. When I try to depend on that crate, I get a linker error saying that windows.lib is missing:
BUILD:
rust_binary(
name = "vrst-test",
srcs = ["src/main.rs"],
deps = [crate("windows-sys")]
)
main.rs:
use windows_sys:: {
};
fn main() {
}
cargo build works but bazel build vrst-test doesn't:
error: linking with `C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/HostX64/x64/link.exe` failed: exit code: 1181
|
= note: "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/HostX64/x64/link.exe" "/NOLOGO" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.vrst_test.17c86f4f-cgu.0.rcgu.o" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.vrst_test.17c86f4f-cgu.1.rcgu.o" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.vrst_test.17c86f4f-cgu.2.rcgu.o" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.vrst_test.17c86f4f-cgu.3.rcgu.o" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.vrst_test.17c86f4f-cgu.4.rcgu.o" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.vrst_test.17c86f4f-cgu.5.rcgu.o" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.vrst_test.17c86f4f-cgu.6.rcgu.o" "bazel-out/x64_windows-fastbuild/bin/vrst-test\\vrst_test.3410wvoxrw1rkamh.rcgu.o" "/LIBPATH:bazel-out/x64_windows-fastbuild/bin/external/rust_windows_x86_64/toolchain_for_x86_64-pc-windows-msvc_impl/lib/rustlib/x86_64-pc-windows-msvc/lib" "/LIBPATH:bazel-out/x64_windows-fastbuild/bin/external/crates__windows_sys__0_33_0" "/LIBPATH:C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\crates__windows_sys__0_33_0\\libwindows_sys-55969548.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-ca7b0c28ec762872.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-1b050a71ed5c4477.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-ba9f9c006950f110.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-4e228cbffbe5e3cd.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-d3d7c65121bb0d35.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-2cedaf2947cb8622.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-7d6cff0c7b8f0c2b.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-63bdfcda4a65748c.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-c331c9d260094b22.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-34d0a2dd4a5dbc91.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-e7b8421abede5598.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-08b052fa5e861ac2.rlib" "C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-18761c3bc8f2e6ea.rlib" "windows.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Denis\\_bazel_Denis\\iakn3uvv\\execroot\\vrst\\bazel-out\\x64_windows-fastbuild\\bin\\external\\rust_windows_x86_64\\toolchain_for_x86_64-pc-windows-msvc_impl\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:bazel-out/x64_windows-fastbuild/bin/vrst-test/vrst-test.exe" "/OPT:REF,NOICF" "/DEBUG" "/nologo" "/SUBSYSTEM:CONSOLE" "advapi32.lib" "ws2_32.lib" "userenv.lib" "/MACHINE:X64" "/DEFAULTLIB:msvcrt.lib" "/DEBUG:FASTLINK" "/INCREMENTAL:NO"
= note: LINK : fatal error LNK1181: cannot open input file 'windows.lib'
I ran into the same issue (latest tokio pulls this crate in), but it's fixed after updating to the latest rules_rust, presumably by https://github.com/bazelbuild/rules_rust/commit/c435cf4478fc6e097edc5dba0e71de6608ab77d8
I tried using that particular commit as well as HEAD and both fail with the error above :(
My apologies, I glossed over the fact that you're using crates_universe; I'm using cargo-raze here. There's a similar report at https://github.com/abrisco/cargo-bazel/issues/173.
@dae interesting, can you share the generated BUILD file that's defining the cargo_build_script target?
https://github.com/ankitects/anki/commit/e0cad1090178b98d9bf96f235f447b5979532d26
Surprised to hear crate_universe has this issues since it's backed by cargo-raze. Just as a sanity check, are you sure you have windows targets building tokio 1.17.0? Or specifically any rust_binary or rust_test targets?
If that was addressed at me, fairly sure; the build was failing on Windows with the error in the top post until I updated rules_rust. There's a rust_test in //rslib if you want to try it.
If that was addressed at me, fairly sure; the build was failing on Windows with the error in the top post until I updated rules_rust. There's a rust_test in //rslib if you want to try it.
It was addressed at you, my bad for the confusion 😅. And since posting that the issue in cargo-bazel appears to be fixed in all cases except locally vendored crates (which I don't think most users would be using).
@korDen Is this still happening on v0.6.0 or above?