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

Support building/testing Fruit with bazel on Windows with MSVC #122

Open
yesudeep opened this issue Aug 9, 2020 · 25 comments
Open

Support building/testing Fruit with bazel on Windows with MSVC #122

yesudeep opened this issue Aug 9, 2020 · 25 comments

Comments

@yesudeep
Copy link

yesudeep commented Aug 9, 2020

C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /Iexternal/com_google_fruit /Ibazel-out/x64_windows-fastbuild/bin/external/com_google_fruit /Iexternal/boost /Ibazel-out/x64_windows-fastbuild/bin/external/boost /Iexternal/com_google_fruit/include /Ibazel-out/x64_windows-fastbuild/bin/external/com_google_fruit/include /Iexternal/com_google_fruit/configuration/bazel /Ibazel-out/x64_windows-fastbuild/bin/external/com_google_fruit/configuration/bazel /Iexternal/boost /Ibazel-out/x64_windows-fastbuild/bin/external/boost /Iexternal/boost/boost/unordered /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/unordered /Iexternal/boost/boost/assert /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/assert /Iexternal/boost/boost/config /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/config /Iexternal/boost/boost/version /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/version /Iexternal/boost/boost/container /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/container /Iexternal/boost/boost/core /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/core /Iexternal/boost/boost/intrusive /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/intrusive /Iexternal/boost/boost/cstdint /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/cstdint /Iexternal/boost/boost/limits /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/limits /Iexternal/boost/boost/noncopyable /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/noncopyable /Iexternal/boost/boost/static_assert /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/static_assert /Iexternal/boost/boost/move /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/move /Iexternal/boost/boost/detail /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/detail /Iexternal/boost/boost/functional /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/functional /Iexternal/boost/boost/container_hash /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/container_hash /Iexternal/boost/boost/integer /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/integer /Iexternal/boost/boost/type_traits /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/type_traits /Iexternal/boost/boost/mpl /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/mpl /Iexternal/boost/boost/preprocessor /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/preprocessor /Iexternal/boost/boost/iterator /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/iterator /Iexternal/boost/boost/utility /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/utility /Iexternal/boost/boost/swap /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/swap /Iexternal/boost/boost/throw_exception /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/throw_exception /Iexternal/boost/boost/current_function /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/current_function /Iexternal/boost/boost/exception /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/exception /Iexternal/boost/boost/smart_ptr /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/smart_ptr /Iexternal/boost/boost/align /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/align /Iexternal/boost/boost/predef /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/predef /Iexternal/boost/boost/scoped_array /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/scoped_array /Iexternal/boost/boost/checked_delete /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/checked_delete /Iexternal/boost/boost/scoped_ptr /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/scoped_ptr /Iexternal/boost/boost/shared_array /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/shared_array /Iexternal/boost/boost/shared_ptr /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/shared_ptr /Iexternal/boost/boost/tuple /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/tuple /Iexternal/boost/boost/ref /Ibazel-out/x64_windows-fastbuild/bin/external/boost/boost/ref /DBOOST_ALL_NO_LIB /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -DHAVE_BAZEL_BUILD /DHAVE_BAZEL_BUILD_WINDOWS /D_HAS_DEPRECATED_RESULT_OF=1 /std:c++17 /Fobazel-out/x64_windows-fastbuild/bin/external/com_google_fruit/_objs/fruit/demangle_type_name.obj /c external/com_google_fruit/src/demangle_type_name.cpp
Execution platform: @local_config_platform//:host
external/com_google_fruit/src/demangle_type_name.cpp(25): fatal error C1083: Cannot open include file: 'cxxabi.h': No such file or directory
@yesudeep
Copy link
Author

yesudeep commented Aug 9, 2020

I'm not sure but one may need to set FRUIT_HAS_CXA_DEMANGLE conditionally for MSVC.

#if defined(_MSC_VER)
#define FRUIT_HAS_CXA_DEMANGLE 0
#else 
#define FRUIT_HAS_CXA_DEMANGLE 1
#endif

perhaps?

@poletti-marco
Copy link
Contributor

Hi, thanks for the report.
Committed 94cefef that should fix this.
Please try again with the latest Fruit (from HEAD), and let me know if it works or if you're hitting other issues.

@yesudeep
Copy link
Author

yesudeep commented Aug 9, 2020

Hi!

I tried the latest commit and get this error message from Bazel instead:

❯ bazel test //third_party/cc/test:com_google_fruit_test
ERROR: C:/tmp/yhlvxsm5/external/com_google_fruit/BUILD:14:11: no such package '@com_google_fruit//third_party/fruit/configuration/bazel': BUILD file not found in directory 'third_party/fruit/configuration/bazel' of external repository @com_google_fruit. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_google_fruit//:fruit'
ERROR: Analysis of target '//third_party/cc/test:com_google_fruit_test' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.372s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)

Hmm, I notice that there isn't a WORKSPACE file in the root directory. Is that by design?

@yesudeep
Copy link
Author

yesudeep commented Aug 9, 2020

Thanks for this piece too btw:

https://github.com/google/fruit/blob/master/configuration/bazel/build_defs.bzl

It's amazing what can be done using Bazel.

@poletti-marco
Copy link
Contributor

I don't understand what's going on, that directory exists...

Can you post here the code you're using so that I can repro?
Particularly your WORKSPACE file and the relevant BUILD files.

Thanks

@yesudeep
Copy link
Author

yesudeep commented Aug 9, 2020

Please clone this repository. Would there need to be a WORKSPACE file in the root?

@poletti-marco
Copy link
Contributor

Thanks. I did some experiments, and this works:
https://github.com/google/fruit/blob/master/extras/bazel_usage_example/WORKSPACE

Fruit's WORKSPACE file (and the dir structure for bazel) is not at the root.

@yesudeep
Copy link
Author

yesudeep commented Aug 9, 2020

Hmm, interesting. I'm playing around with the repository to check whether this
can be simplified, but if you use a separate repository there are still problems (see below).
I'm not sure but could you explain why the WORKSPACE file is not placed at the root?
It's not what most Bazel packages do, so curious. :)

❯ bazel test ...
DEBUG: Rule 'com_google_fruit' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "6f3760672a0d2c772306e737d894a2ae2d8c5f58", shallow_since = "1597001458 -0700" and dropping ["branch"]
DEBUG: Repository com_google_fruit instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  C:/tmp/dlc2s26i/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
ERROR: C:/users/yesudeep/code/yesudeep/frooty/third_party/cc/test/BUILD.bazel:3:8: no such package '@com_google_fruit//': BUILD file not found in directory '' of external repository @com_google_fruit. Add a BUILD file to a directory to mark it as a package. and referenced by '//third_party/cc/test:com_google_fruit_test'
ERROR: Analysis of target '//third_party/cc/test:com_google_fruit_test' failed; build aborted: Analysis failed
INFO: Elapsed time: 3.136s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 4 targets configured)
FAILED: Build did NOT complete successfully (3 packages loaded, 4 targets configured)

@poletti-marco
Copy link
Contributor

poletti-marco commented Aug 9, 2020 via email

@yesudeep
Copy link
Author

yesudeep commented Aug 9, 2020

  1. That fetches the repository indeed. However, I think some includes are still missing:
 bazel build ...
DEBUG: Rule 'com_google_fruit' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "6f3760672a0d2c772306e737d894a2ae2d8c5f58", shallow_since = "1597001458 -0700" and dropping ["branch"]
DEBUG: Repository com_google_fruit instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /home/yesudeep/.cache/bazel/_bazel_yesudeep/767afc168b310823a7e0a8505c558670/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
INFO: Analyzed target //third_party/cc/test:com_google_fruit_test (5 packages loaded, 128 targets configured).
INFO: Found 1 target...
ERROR: /home/yesudeep/.cache/bazel/_bazel_yesudeep/767afc168b310823a7e0a8505c558670/external/com_google_fruit/third_party/fruit/BUILD:14:11: C++ compilation of rule '@com_google_fruit//third_party/fruit:fruit' failed (Exit 1) gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 172 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from external/com_google_fruit/third_party/fruit/src/demangle_type_name.cpp:19:
external/com_google_fruit/third_party/fruit/include/fruit/impl/fruit-config.h:20:10: fatal error: fruit/impl/fruit-config-base.h: No such file or directory
   20 | #include <fruit/impl/fruit-config-base.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Target //third_party/cc/test:com_google_fruit_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.883s, Critical Path: 0.42s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

I get this error both in the external test and while building using the repository-internal
example workspace.

  1. It's also interesting to note that using http_archive instead of git_repository results in the following error:
❯ bazel build ...
INFO: SHA256 (https://github.com/google/fruit/archive/master.tar.gz) = de920563b357de26e88f24444343d0901af8868138c3bbfe3cc68a149648b439
DEBUG: Rule 'com_google_fruit' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "de920563b357de26e88f24444343d0901af8868138c3bbfe3cc68a149648b439"
DEBUG: Repository com_google_fruit instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule http_archive defined at:
  /home/yesudeep/.cache/bazel/_bazel_yesudeep/767afc168b310823a7e0a8505c558670/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
ERROR: /home/yesudeep/code/yesudeep/frooty/third_party/cc/test/BUILD.bazel:3:8: no such package '@com_google_fruit//third_party/fruit': BUILD file not found in directory 'third_party/fruit' of external repository @com_google_fruit. Add a BUILD file to a directory to mark it as a package. and referenced by '//third_party/cc/test:com_google_fruit_test'
ERROR: Analysis of target '//third_party/cc/test:com_google_fruit_test' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.858s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 4 targets configured)

I used the following http_archive call:

http_archive(
    name = "com_google_fruit",
    strip_prefix = "fruit-master/extras/bazel_root",
    urls = ["https://github.com/google/fruit/archive/master.tar.gz"],
)

@poletti-marco
Copy link
Contributor

It looks like the "rules_cc" http_archive interferes with Fruit somehow.
After removing that and uncommenting the git_repository entry in your WORKSPACE it works.
The commit you're using from that repo is really old (~1y ago).
Do you need that one for some reason?

@poletti-marco
Copy link
Contributor

diff --git a/WORKSPACE b/WORKSPACE
index 8e8d063..92acdb9 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,11 +1,5 @@
 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-http_archive(
-    name = "rules_cc",
-    sha256 = "35f2fb4ea0b3e61ad64a369de284e4fbbdcdba71836a5555abb5e194cf119509",
-    strip_prefix = "rules_cc-624b5d59dfb45672d4239422fa1e3de1822ee110",
-    urls = ["https://github.com/bazelbuild/rules_cc/archive/624b5d59dfb45672d4239422fa1e3de1822ee110.tar.gz"],
-)
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
 
 http_archive(
     name = "com_google_googletest",
@@ -25,15 +19,9 @@ load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
 
 boost_deps()
 
-# git_repository(
-#     name = "com_google_fruit",
-#     branch = "master",
-#     remote = "https://github.com/google/fruit",
-#     strip_prefix = "extras/bazel_root",
-# )
-
-http_archive(
+git_repository(
     name = "com_google_fruit",
-    strip_prefix = "fruit-master/extras/bazel_root",
-    urls = ["https://github.com/google/fruit/archive/master.tar.gz"],
+    branch = "master",
+    remote = "https://github.com/google/fruit",
+    strip_prefix = "extras/bazel_root",
 )

@yesudeep
Copy link
Author

yesudeep commented Aug 10, 2020

Yep, made those changes but still get the following error. Were you able to compile the code in the repository without errors? It's weird, but I get this error when I'm building on Linux and Mac OS.

❯ bazel test ...
DEBUG: Rule 'com_github_nelhage_rules_boost' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "2613d04ab3d22dfc4543ea0a083d9adeaa0daf09", shallow_since = "1596677845 -0700" and dropping ["branch"]
DEBUG: Repository com_github_nelhage_rules_boost instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /home/yesudeep/.cache/bazel/_bazel_yesudeep/767afc168b310823a7e0a8505c558670/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
DEBUG: Rule 'com_google_fruit' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "6f3760672a0d2c772306e737d894a2ae2d8c5f58", shallow_since = "1597001458 -0700" and dropping ["branch"]
DEBUG: Repository com_google_fruit instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /home/yesudeep/.cache/bazel/_bazel_yesudeep/767afc168b310823a7e0a8505c558670/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
INFO: Analyzed target //third_party/cc/test:com_google_fruit_test (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
ERROR: /home/yesudeep/.cache/bazel/_bazel_yesudeep/767afc168b310823a7e0a8505c558670/external/com_google_fruit/third_party/fruit/BUILD:14:11: C++ compilation of rule '@com_google_fruit//third_party/fruit:fruit' failed (Exit 1) gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 172 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from external/com_google_fruit/third_party/fruit/include/fruit/impl/data_structures/memory_pool.defn.h:21,
                 from external/com_google_fruit/third_party/fruit/include/fruit/impl/data_structures/memory_pool.h:63,
                 from external/com_google_fruit/third_party/fruit/include/fruit/impl/data_structures/semistatic_graph.h:20,
                 from external/com_google_fruit/third_party/fruit/src/semistatic_graph.cpp:19:
external/com_google_fruit/third_party/fruit/include/fruit/impl/fruit-config.h:20:10: fatal error: fruit/impl/fruit-config-base.h: No such file or directory
   20 | #include <fruit/impl/fruit-config-base.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Target //third_party/cc/test:com_google_fruit_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.484s, Critical Path: 0.36s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
//third_party/cc/test:com_google_fruit_test                     FAILED TO BUILD

FAILED: Build did NOT complete successfully

@yesudeep
Copy link
Author

yesudeep commented Aug 10, 2020

Windows has its own error (using PowerShell):

Starting local Bazel server and connecting to it...
DEBUG: Rule 'com_github_nelhage_rules_boost' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "2613d04ab3d22dfc4543ea0a083d9adeaa0daf09", shallow_since = "1596677845 -0700" and dropping ["branch"]
DEBUG: Repository com_github_nelhage_rules_boost instantiated at:
Repository rule git_repository defined at:
  C:/tmp/dlc2s26i/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
DEBUG: Rule 'com_google_fruit' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "6f3760672a0d2c772306e737d894a2ae2d8c5f58", shallow_since = "1597001458 -0700" and dropping ["branch"]
DEBUG: Repository com_google_fruit instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  C:/tmp/dlc2s26i/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
ERROR: C:/users/yesudeep/code/yesudeep/frooty/third_party/cc/test/BUILD.bazel:3:8: error loading package '@com_google_fruit//third_party/fruit': C:\tmp\dlc2s26i\external\com_google_fruit\third_party\fruit\BUILD (The system cannot find the file specified) and referenced by '//third_party/cc/test:com_google_fruit_test'
ERROR: Analysis of target '//third_party/cc/test:com_google_fruit_test' failed; build aborted: Analysis failed
INFO: 0 processes.
FAILED: Build did NOT complete successfully (18 packages loaded, 18 targets configured)

@poletti-marco
Copy link
Contributor

Were you able to compile the code in the repository without errors?

Yes.

 ~/projects > git clone [email protected]:yesudeep/frooty.git
Cloning into 'frooty'...
remote: Enumerating objects: 44, done.
remote: Counting objects: 100% (44/44), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 44 (delta 16), reused 41 (delta 13), pack-reused 0
Receiving objects: 100% (44/44), 5.54 KiB | 5.54 MiB/s, done.
Resolving deltas: 100% (16/16), done.
 ~/projects > cd frooty/
 ~/projects/frooty > bazel test //third_party/cc/test/...
Starting local Bazel server and connecting to it...
DEBUG: Rule 'com_github_nelhage_rules_boost' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "2613d04ab3d22dfc4543ea0a083d9adeaa0daf09", shallow_since = "1596677845 -0700" and dropping ["branch"]
DEBUG: Repository com_github_nelhage_rules_boost instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  /home/marco/.cache/bazel/_bazel_marco/73ac435295cb66a2d5c58cb43eae5cdd/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
INFO: Analyzed target //third_party/cc/test:com_google_fruit_test (25 packages loaded, 2846 targets configured).
INFO: Found 1 test target...
Target //third_party/cc/test:com_google_fruit_test up-to-date:
  bazel-bin/third_party/cc/test/com_google_fruit_test
INFO: Elapsed time: 24.556s, Critical Path: 0.13s
INFO: 1 process: 1 linux-sandbox.
INFO: Build completed successfully, 2 total actions
//third_party/cc/test:com_google_fruit_test                              PASSED in 0.1s

INFO: Build completed successfully, 2 total actions

This was on Linux, with:

 ~/projects/frooty > bazel --version
bazel 3.4.1

Do you have a different version by any chance?
Do you have anything in ~/.bazelrc? (I don't)

@poletti-marco
Copy link
Contributor

My mistake, I have the Fruit binary package installed in my system and bazel was picking that up. Sigh.
After uninstalling that I can reproduce the issue, I'll look into it.

@yesudeep
Copy link
Author

Weird... I'm using Bazelisk on all these machines so Bazel should be up-to-date.

❯ bazel --version
bazel 3.4.1

Nothing in ~/.bazelrc on Mac OS or Linux (ClearLinux and Ubuntu), but on Windows I have:

startup --output_user_root=C:/tmp
startup --windows_enable_symlinks
build --enable_runfiles

You can view this video to see what I'm probably missing: https://youtu.be/yMdqBMEYDkw

@yesudeep
Copy link
Author

I have the Fruit binary package installed in my system and bazel was picking that up. Sigh.
After uninstalling that I can reproduce the issue, I'll look into it.

Oh, err. lol. Damn.

@poletti-marco
Copy link
Contributor

Yeah, sorry.
Ok, now fixed for real.
I checked that your example repo works.

Note: you'll need to run bazel clean --expunge first, otherwise bazel might still re-use an old cached version of "Fruit master".

@yesudeep
Copy link
Author

yesudeep commented Aug 10, 2020

Wonderful! It's fixed on Linux and Mac OS. Windows still complains, however. I'm not sure whether this has something to do with the lack of support for symlinks on Windows (which shouldn't be the case since git config core.symlinks evaluates to true and I'm using the appropriate bazelrc configuration to enable symlink support for Bazel). Hmm...

❯ bazel test ...
Starting local Bazel server and connecting to it...
DEBUG: Rule 'com_github_nelhage_rules_boost' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "2613d04ab3d22dfc4543ea0a083d9adeaa0daf09", shallow_since = "1596677845 -0700" and dropping ["branch"]
DEBUG: Repository com_github_nelhage_rules_boost instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  C:/tmp/dlc2s26i/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
DEBUG: Rule 'com_google_fruit' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "c6d389dab4bcdb61ed1a3d9d0500f8d6feca1ecf", shallow_since = "1597032616 -0700" and dropping ["branch"]
DEBUG: Repository com_google_fruit instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  C:/tmp/dlc2s26i/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
ERROR: C:/users/yesudeep/code/yesudeep/frooty/third_party/cc/test/BUILD.bazel:3:8: error loading package '@com_google_fruit//third_party/fruit': C:\tmp\dlc2s26i\external\com_google_fruit\third_party\fruit\BUILD (The system cannot find the file specified) and referenced by '//third_party/cc/test:com_google_fruit_test'
ERROR: Analysis of target '//third_party/cc/test:com_google_fruit_test' failed; build aborted: Analysis failed
INFO: Elapsed time: 6.451s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (18 packages loaded, 18 targets configured)
FAILED: Build did NOT complete successfully (18 packages loaded, 18 targets configured)

For the example in the fruit repository:

fruit/extras/bazel_usage_example on  master [!]
❯ bazel build ...
Starting local Bazel server and connecting to it...
DEBUG: Rule 'com_github_nelhage_rules_boost' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "2613d04ab3d22dfc4543ea0a083d9adeaa0daf09", shallow_since = "1596677845 -0700" and dropping ["branch"]
DEBUG: Repository com_github_nelhage_rules_boost instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  C:/tmp/k6wveeoa/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
DEBUG: Rule 'com_google_fruit' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "c6d389dab4bcdb61ed1a3d9d0500f8d6feca1ecf", shallow_since = "1597032616 -0700" and dropping ["branch"]
DEBUG: Repository com_google_fruit instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
  C:/tmp/k6wveeoa/external/bazel_tools/tools/build_defs/repo/git.bzl:195:33: in <toplevel>
ERROR: C:/users/yesudeep/code/src/fruit/extras/bazel_usage_example/BUILD:4:10: error loading package '@com_google_fruit//third_party/fruit': C:\tmp\k6wveeoa\external\com_google_fruit\third_party\fruit\BUILD (The system cannot find the file specified) and referenced by '//:hello_world'
ERROR: Analysis of target '//:hello_world' failed; build aborted: Analysis failed
INFO: Elapsed time: 6.295s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (13 packages loaded, 18 targets configured)

@yesudeep
Copy link
Author

Hmm. It's looking for the wrong file path:

C:\tmp\dlc2s26i\external\com_google_fruit\third_party\fruit\BUILD
which is a symlink to ../../../../BUILD, which doesn't exist indeed. Sigh.

com_google_fruit/third_party/fruit
❯ ls


    Directory: C:\tmp\dlc2s26i\external\com_google_fruit\third_party\fruit


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----l          8/9/2020   9:33 PM                configuration
d----l          8/9/2020   9:33 PM                examples
d----l          8/9/2020   9:33 PM                include
d----l          8/9/2020   9:33 PM                src
d----l          8/9/2020   9:33 PM                tests
-a---l          8/9/2020   9:33 PM              0 BUILD



com_google_fruit/third_party/fruit
❯ cat BUILD
cat : Could not find file 'C:\tmp\dlc2s26i\external\com_google_fruit\third_party\fruit\BUILD'.
At line:1 char:1
+ cat BUILD
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\tmp\dlc2s26i...rty\fruit\BUILD:String) [Get-Content], FileNot
   FoundException
    + FullyQualifiedErrorId : GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand

but the same file via WSL:

com_google_fruit/third_party/fruit on  master [!]
❯ ls -lah
total 0
drwxrwxrwx 1 yesudeep yesudeep 4.0K Aug  9 21:33 ./
drwxrwxrwx 1 yesudeep yesudeep 4.0K Aug  9 21:33 ../
lrwxrwxrwx 1 yesudeep yesudeep   17 Aug  9 21:33 BUILD -> ../../../../BUILD*
lrwxrwxrwx 1 yesudeep yesudeep   25 Aug  9 21:33 configuration -> ../../../../configuration/
lrwxrwxrwx 1 yesudeep yesudeep   20 Aug  9 21:33 examples -> ../../../../examples/
lrwxrwxrwx 1 yesudeep yesudeep   19 Aug  9 21:33 include -> ../../../../include/
lrwxrwxrwx 1 yesudeep yesudeep   15 Aug  9 21:33 src -> ../../../../src/
lrwxrwxrwx 1 yesudeep yesudeep   17 Aug  9 21:33 tests -> ../../../../tests/

com_google_fruit/third_party/fruit on  master [!]
❯ cat BUILD

package(default_visibility = ["//visibility:public"])
licenses(["notice"])

filegroup(
    name = "fruit_headers",
    srcs = glob([
        "include/**/*.h",
    ]) + [
        "//third_party/fruit/configuration/bazel:fruit-config-base",
    ],
)

cc_library(
    name = "fruit",
    srcs = glob([
        "src/*.cpp",
        "include/fruit/impl/**/*.h",
        ]),
    hdrs = glob(["include/fruit/*.h"]),
    includes = ["include", "configuration/bazel"],
    deps = [
        "@boost//:unordered",
        "//third_party/fruit/configuration/bazel:fruit-config-base",
    ],
    linkopts = ["-lm"],
)

@poletti-marco
Copy link
Contributor

I looked into this a bit, after running the command in step 2 of the solution here:
https://stackoverflow.com/questions/5917249/git-symlinks-in-windows

Then the symlinked files are found on Windows too.
It still fails though, I found a couple fixes for small issues but now I'm hitting some other issue that I don't understand.
Maybe there are some issues/limitations with Bazel on Windows itself?
I've only ever used it on Linux before.

While Fruit is supported on Windows (also with MSVC) and it's supported when building Bazel, the combination of the 2 doesn't seem to work.
I'll clarify that this is not currently supported in the wiki.
If we manage to make it work I can change that.
I'd definitely welcome pull requests in this direction, and I'll keep this issue open to track this.

@poletti-marco poletti-marco changed the title cxxabi.h missing for MSVC Support building/testing Fruit with bazel on Windows with MSVC Aug 16, 2020
@yesudeep
Copy link
Author

yesudeep commented Sep 18, 2021

So I got around to fruit + MSVC and decided to write a custom build file that works on all of these platforms:

  1. Windows+MSVC
  2. Mac OS
  3. FreeBSD
  4. Linux

Here's what is currently working for me using the build_file attribute for http_archive.

load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])  # Apache 2.0

config_setting(
    name = "platform_linux",
    constraint_values = [
        "@platforms//os:linux",
    ],
)

config_setting(
    name = "platform_freebsd",
    constraint_values = [
        "@platforms//os:freebsd",
    ],
)

config_setting(
    name = "platform_macos",
    constraint_values = [
        "@platforms//os:macos",
    ],
)

config_setting(
    name = "platform_windows",
    constraint_values = [
        "@platforms//os:windows",
    ],
)

genrule(
    name = "fruit_config_base",
    outs = ["include/fruit/impl/fruit-config-base.h"],
    cmd = """cat <<'EOF' >$@
#ifndef FRUIT_CONFIG_BASE_H
#define FRUIT_CONFIG_BASE_H

// All of the defines are in the cc_library build rule.

#endif // FRUIT_CONFIG_BASE_H
EOF
""",
)

GENERATED_HEADERS = [
  "include/fruit/impl/fruit-config-base.h",
]

cc_library(
    name = "fruit",
    srcs = glob([
        "src/**/*.cpp",
    ]),
    hdrs = GENERATED_HEADERS + glob([
        "include/fruit/**/*.h",
    ]),
    defines = select({
      ":platform_windows": [
          #"FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE=1",
          "FRUIT_HAS_ATTRIBUTE_DEPRECATED=1",
          #"FRUIT_HAS_BUILTIN_UNREACHABLE=1",
          #"FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG=1",
          "FRUIT_HAS_CONSTEXPR_TYPEID=1",
          #"FRUIT_HAS_CXA_DEMANGLE=1",
          "FRUIT_HAS_DECLSPEC_DEPRECATED=1",
          "FRUIT_HAS_FORCEINLINE=1",
          #"FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_HAS_TRIVIAL_COPY=1",
          "FRUIT_HAS_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_MAX_ALIGN_T=1",
          "FRUIT_HAS_MSVC_ASSUME=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE=1",
          "FRUIT_HAS_STD_MAX_ALIGN_T=1",
          "FRUIT_HAS_TYPEID=1",
          #"FRUIT_USES_BOOST=1",
      ],
      ":platform_freebsd": [
          "FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE=1",
          "FRUIT_HAS_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_BUILTIN_UNREACHABLE=1",
          #"FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG=1",
          "FRUIT_HAS_CONSTEXPR_TYPEID=1",
          "FRUIT_HAS_CXA_DEMANGLE=1",
          #"FRUIT_HAS_DECLSPEC_DEPRECATED=1",
          #"FRUIT_HAS_FORCEINLINE=1",
          "FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_HAS_TRIVIAL_COPY=1",
          "FRUIT_HAS_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_MAX_ALIGN_T=1",
          #"FRUIT_HAS_MSVC_ASSUME=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE=1",
          "FRUIT_HAS_STD_MAX_ALIGN_T=1",
          "FRUIT_HAS_TYPEID=1",
          #"FRUIT_USES_BOOST=1",
      ],
      ":platform_linux": [
          "FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE=1",
          "FRUIT_HAS_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_BUILTIN_UNREACHABLE=1",
          #"FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG=1",
          "FRUIT_HAS_CONSTEXPR_TYPEID=1",
          "FRUIT_HAS_CXA_DEMANGLE=1",
          #"FRUIT_HAS_DECLSPEC_DEPRECATED=1",
          #"FRUIT_HAS_FORCEINLINE=1",
          "FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_HAS_TRIVIAL_COPY=1",
          "FRUIT_HAS_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_MAX_ALIGN_T=1",
          #"FRUIT_HAS_MSVC_ASSUME=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE=1",
          "FRUIT_HAS_STD_MAX_ALIGN_T=1",
          "FRUIT_HAS_TYPEID=1",
          #"FRUIT_USES_BOOST=1",
      ],
      ":platform_macos": [
          "FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE=1",
          "FRUIT_HAS_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_BUILTIN_UNREACHABLE=1",
          #"FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG=1",
          "FRUIT_HAS_CONSTEXPR_TYPEID=1",
          "FRUIT_HAS_CXA_DEMANGLE=1",
          #"FRUIT_HAS_DECLSPEC_DEPRECATED=1",
          #"FRUIT_HAS_FORCEINLINE=1",
          "FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_HAS_TRIVIAL_COPY=1",
          "FRUIT_HAS_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_MAX_ALIGN_T=1",
          #"FRUIT_HAS_MSVC_ASSUME=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE=1",
          "FRUIT_HAS_STD_MAX_ALIGN_T=1",
          "FRUIT_HAS_TYPEID=1",
          #"FRUIT_USES_BOOST=1",
      ],
      "//conditions:default": [
          # Turn on everything by default to break stuff.
          "FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE=1",
          "FRUIT_HAS_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_BUILTIN_UNREACHABLE=1",
          "FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG=1",
          "FRUIT_HAS_CONSTEXPR_TYPEID=1",
          "FRUIT_HAS_CXA_DEMANGLE=1",
          "FRUIT_HAS_DECLSPEC_DEPRECATED=1",
          "FRUIT_HAS_FORCEINLINE=1",
          "FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED=1",
          "FRUIT_HAS_HAS_TRIVIAL_COPY=1",
          "FRUIT_HAS_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_MAX_ALIGN_T=1",
          "FRUIT_HAS_MSVC_ASSUME=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE=1",
          "FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE=1",
          "FRUIT_HAS_STD_MAX_ALIGN_T=1",
          "FRUIT_HAS_TYPEID=1",
          "FRUIT_USES_BOOST=1",
      ],
    }),
    includes = [
        "include",
    ],
    linkopts = select({
      ":platform_windows": [
      ],
      "//conditions:default": [
        "-lm",
      ],
    }),
    data = [
        ":fruit_config_base",
    ],
    deps = [
        # "@boost//:unordered",
    ],
)


It doesn't do a full blown job of detecting all platform features, but should be sufficient to get started using fruit.

HTH.

@poletti-marco
Copy link
Contributor

Hi, thanks for looking into this and sharing the code!

The linkopts change should be fine to check in roughly as is (maybe special casing windows instead of each of the other ones).

The defines bypass Fruit's feature detection logic though, hard coding properties of the compiler that can change with the compiler version or if using flags to select a non default compiler for that platform.
I'd rather fix the feature detection code instead.
What commands did you use / can I use to repro?
(on windows, i don't have a freebsd system but it seems close to Linux and Mac OS anyway)

@yesudeep
Copy link
Author

yesudeep commented Sep 23, 2021

Hey there @poletti-marco

  1. Yep makes sense. Updated the build file above.
  2. I just ran this command on each platform and used the values it generated on my machines:

cmake -DCMAKE_BUILD_TYPE=Release -DFRUIT_USES_BOOST=False .

I do believe this is a workaround not an actual fix. The feature detection logic is what should be
used ideally and I'll see whether I can get that to work as well. Do you think it would be a good idea to separate the feature detection into a separate repository called rules_cc_configure so that other projects can use it too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants