Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source forest creation fails for cc_test rules on Windows #2474

Closed
BittaBoesaBiba opened this issue Feb 2, 2017 · 5 comments
Closed

Source forest creation fails for cc_test rules on Windows #2474

BittaBoesaBiba opened this issue Feb 2, 2017 · 5 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) platform: windows type: bug
Milestone

Comments

@BittaBoesaBiba
Copy link

Description of the problem:

/_bazel_<user>/<hash>/execroot/<workspace_dir>/tools directory is not created when trying to build cc_test rules.

Error when testing hello-fail_test from bazel examples

Chris@Chris  /c/Users/Chris/Desktop/bazel-cpp-test
$ bazel test examples/cpp:hello-fail_test
INFO: Found 1 test target...
ERROR: Source forest creation failed: C:/Users/Chris/AppData/Local/Temp/_bazel_Chris/g-t8dlwH/execroot/bazel-cpp-test/tools (No such file or directory).
INFO: Elapsed time: 1,567s
ERROR: Couldn't start the build. Unable to run tests.

Tested multiple cc_test rules which all have the same issue.


Success when running hello-world

Chris@Chris  /c/Users/Chris/Desktop/bazel-cpp-test
$ bazel run examples/cpp:hello-world
INFO: Found 1 target...
Target //examples/cpp:hello-world up-to-date:
  C:/Users/Chris/AppData/Local/Temp/_bazel_Chris/g-t8dlwH/execroot/bazel-cpp-test/bazel-out/local-fastbuild/bin/examples/cpp/hello-world.exe
INFO: Elapsed time: 2,094s, Critical Path: 0,01s

INFO: Running command line: C:/Users/Chris/AppData/Local/Temp/_bazel_Chris/g-t8dlwH/execroot/bazel-cpp-test/bazel-out/local-fastbuild/bin/examples/cpp/hello-world.exe
Hello world

Success when changing hello-fail_test to cc_binary in the BUILD file

cc_binary(
    name = "hello-fail_test",
    srcs = ["hello-fail.cc"],
    deps = [":hello-lib"],
)
Chris@Chris  /c/Users/Chris/Desktop/bazel-cpp-test
$ bazel run examples/cpp:hello-fail_test
INFO: Found 1 target...
Target //examples/cpp:hello-fail_test up-to-date:
C:/Users/Chris/AppData/Local/Temp/_bazel_Chris/g-t8dlwH/execroot/bazel-cpp-test/bazel-out/local-fastbuild/bin/examples/cpp/hello-fail_test.exe
INFO: Elapsed time: 22,647s, Critical Path: 1,15s

INFO: Running command line: C:/Users/Chris/AppData/Local/Temp/_bazel_Chris/g-t8dlwH/execroot/bazel-cpp-test/bazel-out/local-fastbuild/bin/examples/cpp/hello-fail_test.exe
Hello barf
ERROR: Non-zero return code '1' from command: Process exited with status 1.

Success when setting up the build environment on elementary OS

chris@chris-VirtualBox:~/Documents/bazel-cpp-test$ bazel test examples/cpp:hello-fail_test
INFO: Found 1 test target...
FAIL: //examples/cpp:hello-fail_test (see /home/chris/.cache/bazel/_bazel_chris/c4de08e7abf1aab9db8a11ac19bf9e9d/execroot/bazel-cpp-test/bazel-out/local-fastbuild/testlogs/examples/cpp/hello-fail_test/test.log).
Target //examples/cpp:hello-fail_test up-to-date:
bazel-bin/examples/cpp/hello-fail_test
INFO: Elapsed time: 1.673s, Critical Path: 0.59s
//examples/cpp:hello-fail_test                                           FAILED in 0.0s
/home/chris/.cache/bazel/_bazel_chris/c4de08e7abf1aab9db8a11ac19bf9e9d/execroot/bazel-cpp-test/bazel-out/local-fastbuild/testlogs/examples/cpp/hello-fail_test/test.log

Executed 1 out of 1 test: 1 fails locally.

If possible, provide a minimal example to reproduce the problem:

Environment info

  • Operating System:
    Windows 10, 64 Bit
    Windows 7, 64 Bit
    elementary OS, 64 Bit, VirtualBox

  • Bazel version (output of bazel info release):
    release 0.4.4

  • on Windows 10, 64 Bit
    tested chocolatey package first (0.4.3),
    tested pre-build binaries 0.4.4, 0.4.3, 0.4.0, 0.4.1 and 0.3.2
    tested with and without --cpu=x64_windows_msvc

  • on Windows 7, 64 Bit
    tested pre-build binary 0.4.4, 0.4.3

Have you found anything relevant by searching the web? (e.g. GitHub issues, email threads in the bazel-discuss@googlegroups.com archive)

#1583

Anything else, information or logs or outputs that would be helpful?

(If they are large, please upload as attachment or provide link).
printenv.txt

@meteorcloudy meteorcloudy added platform: windows under investigation category: rules > C++ P2 We'll consider working on this in future. (Assignee optional) type: bug and removed under investigation labels Feb 3, 2017
@meteorcloudy
Copy link
Member

The reason it fails is because cc_test rules depend on //tools/defaults:crosstool, on Unix, bazel creates a dangling symlink pointing to <source_dir>/tools. But on Windows, symlink doesn't exist, so it fails.
If you create an empty tools folder under work workspace root, it should works,

Thanks for reporting, this is definitely a bug in Bazel we should fix.

@BittaBoesaBiba
Copy link
Author

Thanks a lot for the quick fix! Creating the tools folder at top-level solved the issue.
But unfortunately it revealed another one. I'm not sure if this is worth a new ticket:

Chris@Chris  /c/Users/Chris/Desktop/bazel-cpp-test
$ bazel test examples/cpp:hello-fail_test --verbose_failures
INFO: Found 1 test target...
ERROR: C:/Users/Chris/Desktop/bazel-cpp-test/examples/cpp/BUILD:3:1: Linking of rule '//examples/cpp:hello-lib' failed:
link_dynamic_library.sh failed: error executing command
cd C:/Users/Chris/AppData/Local/Temp/_bazel_Chris/g-t8dlwH/execroot/bazel-cpp-test
SET PATH=C:/tools/msys64/usr/bin
external/bazel_tools/tools/cpp/link_dynamic_library.sh no ignored ignored ignored C:/tools/msys64/usr/bin/gcc -shared
-o bazel-out/local-fastbuild/bin/examples/cpp/libhello-lib.so -Wl,-S -Wl,@bazel-out/local-fastbuild/bin/examples/cpp/lib
hello-lib.so-2.params: java.io.IOException: CreateProcess(): %1 ist keine zul▒ssige Win32-Anwendung.
.
Target //examples/cpp:hello-fail_test failed to build
INFO: Elapsed time: 4,032s, Critical Path: 0,03s

Executed 0 out of 1 test: 1 fails to build.

with %1 ist keine zul▒ssige Win32-Anwendung translating to %1 is not a valid win32 application.
The linker at least displays its version:

Chris@Chris  /usr/bin
$ ld --version
GNU ld (GNU Binutils) 2.25.1
Copyright (C) 2014 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

@meteorcloudy
Copy link
Member

We are using MSVC to build c++ on Windows, but it's not yet the default toolchain. Please add --cpu=x64_windows_msvc option.

@BittaBoesaBiba
Copy link
Author

Wonderful! That was just the hint I needed. Perfectly works. Have a great day @meteorcloudy!

@meteorcloudy
Copy link
Member

@BittaBoesaBiba Nice! Thanks, you too! :)

@dslomov dslomov added this to the 0.6 milestone Feb 14, 2017
@meteorcloudy meteorcloudy self-assigned this May 31, 2017
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    On Unix system, `ln -s foo bar` will create an dangling symlink bar -> foo
    even foo doesn't exist. The current implementation of createSymbolicLink for
    Windows fails in this situtation. And this lead to #2474.

    In this change, we create a dangling junction when the target doesn't exist
    which mimics the behavior on Unix.

    Fixed bazelbuild/bazel#2474

    Change-Id: I442ca3e2fb20b76c9b5bbfee903299fe51481f43
    PiperOrigin-RevId: 157694631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) platform: windows type: bug
Projects
None yet
Development

No branches or pull requests

3 participants