rules_foreign_cc icon indicating copy to clipboard operation
rules_foreign_cc copied to clipboard

bazel project will rebuild external repository ignoring cache actions

Open sky92zwq opened this issue 2 years ago • 1 comments

bazel let me to find helps here

Description of the bug:

In WSL, I imported a cmake project (poco) into a bazel project by rules_foreign_cc Every time When I start a new shell and bazel build it will rebuild from the beginning , wasting time.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

After building, I will export LD_LIBRARY_PATH at current shell, run my binary. And then, I change some codes , add some logs, and start building, it will rebuild poco again. WORKSPACE :

workspace(name = "xxxx")
  
  load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
  load("//bazel/external:repositories.bzl", "build_all_content")
  BUILD_ALL_CONTENT = build_all_content()
  
  
  http_archive(
      name = "rules_foreign_cc",
      url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.8.0.tar.gz",
      sha256 = "6041f1374ff32ba711564374ad8e007aef77f71561a7ce784123b9b4b88614fc",
      strip_prefix = "rules_foreign_cc-0.8.0",
      build_file = "//bazel/external:foreign_cc.BUILD",
  )
  load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
  
  rules_foreign_cc_dependencies()
  
  
  
  http_archive(
      name = "com_github_poco",
      url = "https://github.com/pocoproject/poco/archive/refs/tags/poco-1.12.4-release.tar.gz",
      sha256 = "71ef96c35fced367d6da74da294510ad2c912563f12cd716ab02b6ed10a733ef",
      strip_prefix = "poco-poco-1.12.4-release",
      # build_file = "//bazel/external:Poco.BUILD",
      build_file_content = BUILD_ALL_CONTENT,
  )

foreign_cc.BUILD:

licenses(["notice"])  # Apache 2

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



load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

cmake(
    name = "poco",
    cache_entries = {
        "CMAKE_C_FLAGS": "-fPIC",
        "CMAKE_CXX_FLAGS" : "-std=c++0x",
        "ENABLE_XML" : "ON",
        "ENABLE_JSON" : "ON",
        "ENABLE_NET" : "ON",
        "ENABLE_NETSSL" : "OFF",
        "ENABLE_CRYPTO" : "OFF",
        "ENABLE_JWT" : "OFF",
        "ENABLE_DATA" : "OFF",
        "ENABLE_DATA_SQLITE" : "OFF",
        "ENABLE_DATA_MYSQL" : "OFF",
        "ENABLE_DATA_POSTGRESQL" : "OFF",
        "ENABLE_DATA_ODBC" : "OFF",
        "ENABLE_MONGODB" : "OFF",
        "ENABLE_REDIS" : "OFF",
        "ENABLE_PDF" : "OFF",
        "ENABLE_UTIL" : "ON",
        "ENABLE_ZIP" : "OFF",
        "ENABLE_SEVENZIP" : "OFF",
        "ENABLE_APACHECONNECTOR" : "OFF",
        "ENABLE_CPPPARSER" : "OFF",
        "ENABLE_ENCODINGS" : "OFF",
        "ENABLE_ENCODINGS_COMPILER" : "OFF",
        "ENABLE_PAGECOMPILER" : "OFF",
        "ENABLE_PAGECOMPILER_FILE2PAGE" : "OFF",
        "ENABLE_POCODOC" : "OFF",
        "ENABLE_TESTS" : "OFF",
        "ENABLE_LONG_RUNNING_TESTS" : "OFF",
        "POCO_UNBUNDLED" : "OFF",
    },
    lib_source = "@com_github_poco//:all",
    out_shared_libs = select({
        "//conditions:default": ["libPocoFoundation.so", "libPocoNet.so", "libPocoJSON.so", "libPocoXML.so", "libPocoUtil.so",],
    }),
)

build_all function:

def build_all_content(exclude = []):
    return """filegroup(name = "all", srcs = glob(["**"], exclude={}), visibility = ["//visibility:public"])""".format(repr(exclude))

my main BUILD:

cc_binary(
    name = "xxxx",
    srcs = ["main.cc",],
    deps = ["//src/xx:xxx",
            "@rules_foreign_cc//:poco"],
    visibility = ["//visibility:public"],
)

Which operating system are you running Bazel on?

WSL(windows 10)

What is the output of bazel info release?

none

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

sudo apt install bazel version is 6.2.1

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

none

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

None

Any other information, logs, or outputs that you want to share?

None

sky92zwq avatar Jun 26 '23 08:06 sky92zwq

I'd suggest you start by following the steps outlined here: https://bazel.build/basics/hermeticity#troubleshooting-nonhermeticity. Most likely cause is a change in your environment to e.g. PATH.

jsharpe avatar Jul 11 '23 21:07 jsharpe