google/fruit

Hermetic build broken. Need documentation/explicit dependency on boost for use with Bazel.

gorakhargosh opened this issue · 6 comments

Trying to use fruit with Bazel on Linux works with the same code, but fails on Mac OS X. Here's the target build rule:

cc_test(
    name = "fruit_test",
    srcs = ["fruit_test.cc"],
    visibility = ["//visibility:public"],
    defines = [
       "FRUIT_USES_BOOST=false",
    ],
    deps = [
        #"@boost//:unordered",
        # Tried this as well
        # "@com_github_google_fruit//extras/bazel_root/third_party/fruit",
        "@com_github_google_fruit//:fruit",
        "@com_github_google_googletest//:gtest_main",
        "@com_google_absl//absl/strings",
    ],
)

Here's how I include fruit in my WORKSPACE file:

git_repository(
    name = "com_github_google_fruit",
    commit = "45fa33d27da5a9b21471094f34e7f26c21e71f5b",
    remote = "https://github.com/google/fruit",
    shallow_since = "1589760897 -0700",
)

However, when I try to compile the example from the getting started wilki, I get the following error:

Use --sandbox_debug to see verbose messages from the sandbox wrapped_clang failed: error executing command
  (cd /private/var/tmp/_bazel_username/148f9f6ebca6e47e7d6d5ed427a82e62/sandbox/darwin-sandbox/4/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=10.15 \
    PATH=/Users/username/bin:/Users/username/go/bin:/Users/username/var/bin:/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/bin:/Users/username/.cargo/bin:/Users/username/opt/anaconda3/bin:/Users/username/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin:/usr/sbin:/sbin \
    XCODE_VERSION_OVERRIDE=11.5.0.11E608c \
  external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' -iquote external/com_github_google_fruit -iquote bazel-out/darwin-fastbuild/bin/external/com_github_google_fruit -isystem external/com_github_google_fruit/include -isystem bazel-out/darwin-fastbuild/bin/external/com_github_google_fruit/include -isystem external/com_github_google_fruit/configuration/bazel -isystem bazel-out/darwin-fastbuild/bin/external/com_github_google_fruit/configuration/bazel -MD -MF bazel-out/darwin-fastbuild/bin/external/com_github_google_fruit/_objs/fruit/binding_normalization.d '-frandom-seed=bazel-out/darwin-fastbuild/bin/external/com_github_google_fruit/_objs/fruit/binding_normalization.o' -isysroot __BAZEL_XCODE_SDKROOT__ -F__BAZEL_XCODE_SDKROOT__/System/Library/Frameworks -F__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/MacOSX.platform/Developer/Library/Frameworks '-mmacosx-version-min=10.15' -DBWUCK_BAZEL_BUILD '-DFRUIT_USES_BOOST=false' '-std=c++17' -Wall '-Werror=uninitialized' -Wextra -Wpedantic -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/com_github_google_fruit/src/binding_normalization.cpp -o bazel-out/darwin-fastbuild/bin/external/com_github_google_fruit/_objs/fruit/binding_normalization.o)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox
In file included from external/com_github_google_fruit/src/binding_normalization.cpp:26:
In file included from external/com_github_google_fruit/include/fruit/impl/data_structures/semistatic_graph.templates.h:29:
external/com_github_google_fruit/include/fruit/impl/util/hash_helpers.h:29:10: fatal error: 'boost/unordered_map.hpp' file not found
#include <boost/unordered_map.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Target //codelab/cc/external:fruit_test failed to build```

Could you please include an example/documentation for using fruit with bazel?

Thank you. :)

Additionally, perhaps the dependency on boost/unordered_map could be replaced with absl::flat_hash_map.

Alternatively, one could make FRUIT_USES_BOOST=0 the default and allow people to choose
whether they want to use Boost.

WDYT?

Sent a pull request to make boost optional. Would really appreciate if it was optional.

#119

Hi, to clarify: what's your use case?
Do you want Fruit to not use Boost for some reason? (if so, why?)
Or did you find some issues related to using Boost and you then tried to disable Boost as a workaround?

I'm ok giving people the option to turn off Boost when using bazel too, but it looks like that PR actually disables boost for everyone.
I don't think we should do that.

The default should be "boost on" since that gives the best performance (that's also the default for non-bazel builds, so it's consistent).
Then we could have a way to switch it off if desired.

Hi @poletti-marco thank you for responding!
I'm okay with using Boost as long as the whole thing compiles hermetically irrespective of the platform. I've been trying to determine why this fails on my OS X workstation but not on the Linux workstation—I believe the compiler is picking up the system version of boost to compile fruit on Linux, but because I don't have it installed on OS X, it fails.

The build as a result doesn't appear to be hermetic. Wouldn't one need to specify boost as an explicit dependency in BUILD files? https://github.com/google/fruit/blob/master/BUILD#L21

This is the only problem I'm currently facing.

Hi, just committed a fix in master: faa6922.
Could you please check if it works for you now?
(removing FRUIT_USES_BOOST=false from your BUILD rules, you shouldn't need that anymore)

I can reproduce the issue that you were referring to if I uninstall the boost headers from my system, and with the fix now it builds successfully.

Hi @poletti-marco this is awesome! Thank you for the fix. That works now. Cheers! :)