rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

On Windows, crate() deps appear not to propagate dependent libraries correctly

Open korDen opened this issue 3 years ago • 9 comments

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'

korDen avatar Feb 27 '22 23:02 korDen

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

dae avatar Feb 28 '22 00:02 dae

I tried using that particular commit as well as HEAD and both fail with the error above :(

korDen avatar Feb 28 '22 02:02 korDen

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 avatar Feb 28 '22 03:02 dae

@dae interesting, can you share the generated BUILD file that's defining the cargo_build_script target?

UebelAndre avatar Feb 28 '22 18:02 UebelAndre

https://github.com/ankitects/anki/commit/e0cad1090178b98d9bf96f235f447b5979532d26

dae avatar Mar 01 '22 02:03 dae

ankitects/anki@e0cad10

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?

UebelAndre avatar Mar 01 '22 19:03 UebelAndre

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.

dae avatar Mar 02 '22 03:03 dae

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).

UebelAndre avatar Mar 02 '22 03:03 UebelAndre

@korDen Is this still happening on v0.6.0 or above?

UebelAndre avatar Jul 04 '22 16:07 UebelAndre