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

this rule is missing dependency declarations for the following files included by 'external/com_google_protobuf/src/google/protobuf/util/internal/json_escaping.cc' #5164

Closed
chenkan0104 opened this issue May 5, 2018 · 15 comments
Assignees

Comments

@chenkan0104
Copy link

Description of the problem / feature request:

build protobuf with custom CROSSTOOL under Ubuntu 16.04 failed:

INFO: Analysed target //:test (13 packages loaded).
INFO: Found 1 target...
ERROR: /root/.cache/bazel/_bazel_root/c918eecf970df2081a6c5f6b4dde7b37/external/com_google_protobuf/BUILD:64:1: undeclared inclusion(s) in rule '@com_google_protobuf//:protobuf_lite':
this rule is missing dependency declarations for the following files included by 'external/com_google_protobuf/src/google/protobuf/stubs/int128.cc':
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/x86intrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/ia32intrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/mmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/xmmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/mm_malloc.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/emmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/pmmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/tmmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/ammintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/smmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/popcntintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/wmmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/immintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avxintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx2intrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512fintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512erintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512pfintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512cdintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512vlintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512bwintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512dqintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512vlbwintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512vldqintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512ifmaintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512ifmavlintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512vbmiintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/avx512vbmivlintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/shaintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/lzcntintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/bmiintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/bmi2intrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/fmaintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/f16cintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/rtmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/xtestintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/mm3dnow.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/prfchwintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/fma4intrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/xopintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/lwpintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/tbmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/rdseedintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/fxsrintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/xsaveintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/xsaveoptintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/adxintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/clwbintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/pcommitintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/clflushoptintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/xsavesintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/xsavecintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/mwaitxintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h'
Target //:test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 118.406s, Critical Path: 10.82s
INFO: 84 processes, local.
FAILED: Build did NOT complete successfully

This is my build command:

bazel build //:test --crosstool_top=//external:toolchain \
    --cpu=aarch64 --host_cpu=k8 -c opt

And my WORKSPACE:

workspace(name = "test_proj")

# set up toolchain
git_repository(
  name = "bazel_build_toolchains",
  remote = "***",
  commit = "***",
)
load("@bazel_build_toolchains//:toolchain_deps.bzl", "toolchain_deps")
toolchain_deps()

http_archive(
    name = "com_google_protobuf",
    strip_prefix = "protobuf-3.5.1",
    sha256 = "c28dba8782da2cfea1e11c61d335958c31a9c1bc553063546af9cbe98f204092",
    urls = [
      "https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-cpp-3.5.1.tar.gz",
    ],
)

my BUILD looks like this:

# Bazel (http://bazel.io/) BUILD file for test_proj

licenses(["notice"])

COPTS = [
    "-std=c++11",
]
LINK_OPTS = []

load(
    "@com_google_protobuf//:protobuf.bzl",
    "cc_proto_library",
)

cc_proto_library(
    name = "serialization",
    srcs = glob([
        "proto/*.proto",
    ]),
    include = "proto",
    protoc = "@com_google_protobuf//:protoc",
    default_runtime = "@com_google_protobuf//:protobuf",
    deps = [
        "@com_google_protobuf//:cc_wkt_protos"
    ],
    visibility = ["//visibility:public"],
)

# ci test
cc_binary(
    name = "test",
    srcs = glob([
        "test/main.cc",
    ]),
    defines = [
    ],
    stamp = 1,
    copts = COPTS,
    linkopts = LINK_OPTS,
    deps = [
        ":serialization",
    ],
)

This is my main.cc:

int main() {
  return 0;
}

At last the CROSSTOOL:

major_version: "local"
minor_version: ""
default_target_cpu: "aarch64"

default_toolchain {
  cpu: "aarch64"
  toolchain_identifier: "gcc_5_4_1_aarch64"
}

default_toolchain {
  cpu: "k8"
  toolchain_identifier: "local"
}

toolchain {
  abi_version: "gcc"
  abi_libc_version: "glibc_2.21"
  builtin_sysroot: ""
  compiler: "gcc"
  host_system_name: "k8"
  needsPic: true
  supports_gold_linker: false
  supports_incremental_linker: false
  supports_fission: false
  supports_interface_shared_objects: false
  supports_normalizing_ar: true
  supports_start_end_lib: false
  supports_thin_archives: true
  target_libc: "glibc_2.21"
  target_cpu: "aarch64"
  target_system_name: "aarch64"
  toolchain_identifier: "gcc_5_4_1_aarch64"

  tool_path { name: "ar" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-ar" }
  tool_path { name: "compat-ld" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-ld" }
  tool_path { name: "cpp" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-gcc" }
  tool_path { name: "dwp" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-dwp" }
  tool_path { name: "gcc" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-gcc" }
  tool_path { name: "gcov" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-gcov" }
  tool_path { name: "ld" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-ld" }
  tool_path { name: "nm" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-nm" }
  tool_path { name: "objcopy" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-objcopy" }
  objcopy_embed_flag: "-I"
  objcopy_embed_flag: "binary"
  tool_path { name: "objdump" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-objdump" }
  tool_path { name: "strip" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-strip" }

  compiler_flag: "--sysroot=external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc"
  # compiler_flag: "-mfloat-abi=hard"

  compiler_flag: "-nostdinc"
  compiler_flag: "-isystem"
  compiler_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/lib/gcc/aarch64-linux-gnu/5.4.1/include"
  compiler_flag: "-isystem"
  compiler_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc/usr/include"
  compiler_flag: "-isystem"
  compiler_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/lib/gcc/aarch64-linux-gnu/5.4.1/include-fixed"
  cxx_flag: "-isystem"
  cxx_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/include/c++/5.4.1/aarch64-linux-gnu"
  cxx_flag: "-isystem"
  cxx_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/include/c++/5.4.1"
  cxx_flag: "-std=c++11"

  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//include)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//aarch64-linux-gnu/libc/usr/include)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//lib/gcc/aarch64-linux-gnu/5.4.1/include)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//lib/gcc/aarch64-linux-gnu/5.4.1/include-fixed)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//aarch64-linux-gnu/include)%/c++/5.4.1/aarch64-linux-gnu"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//aarch64-linux-gnu/include)%/c++/5.4.1"

  linker_flag: "--sysroot=external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc"
  linker_flag: "-lstdc++"
  # linker_flag: "-lm"
  # linker_flag: "-lpthread"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/lib"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/lib64"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc/lib"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc/usr/lib"
  linker_flag: "-Bexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/bin"
  # linker_flag: "-Wl,--dynamic-linker=/lib/ld-linux-aarch64.so.1"
  # linker_flag: "-print-sysroot"
  # linker_flag: "-Wl,-verbose"

  # Anticipated future default.
  # This makes GCC and Clang do what we want when called through symlinks.
  unfiltered_cxx_flag: "-no-canonical-prefixes"
  linker_flag: "-no-canonical-prefixes"

  # Make C++ compilation deterministic. Use linkstamping instead of these
  # compiler symbols.
  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""

  # Security hardening on by default.
  # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
  # We need to undef it before redefining it as some distributions now have
  # it enabled by default.
  compiler_flag: "-U_FORTIFY_SOURCE"
  compiler_flag: "-fstack-protector"
  compiler_flag: "-fPIE"
  linker_flag: "-pie"
  linker_flag: "-Wl,-z,relro,-z,now"

  # Enable coloring even if there's no attached terminal. Bazel removes the
  # escape sequences if --nocolor is specified.
  compiler_flag: "-fdiagnostics-color=always"

  # All warnings are enabled. Maybe enable -Werror as well?
  compiler_flag: "-Wall"
  # Enable a few more warnings that aren't part of -Wall.
  compiler_flag: "-Wunused-but-set-parameter"
  # But disable some that are problematic.
  compiler_flag: "-Wno-free-nonheap-object" # has false positives

  # Keep stack frames for debugging, even in opt mode.
  compiler_flag: "-fno-omit-frame-pointer"

  # Stamp the binary with a unique identifier.
  linker_flag: "-Wl,--build-id=md5"
  linker_flag: "-Wl,--hash-style=gnu"

  compilation_mode_flags {
    mode: DBG
    # Enable debug symbols.
    compiler_flag: "-g"

    # Keep stack frames for debugging.
    # compiler_flag: "-fno-omit-frame-pointer"
  }
  compilation_mode_flags {
    mode: OPT
    # No debug symbols.
    # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
    # even generally? However, that can't happen here, as it requires special
    # handling in Bazel.
    compiler_flag: "-g0"

    # Conservative choice for -O
    # -O3 can increase binary size and even slow down the resulting binaries.
    # Profile first and / or use FDO if you need better performance than this.
    compiler_flag: "-O2"

    # Disable assertions
    compiler_flag: "-DNDEBUG"

    # Removal of unused code and data at link time (can this increase binary size in some cases?).
    compiler_flag: "-ffunction-sections"
    compiler_flag: "-fdata-sections"
    linker_flag: "-Wl,--gc-sections"

    # statically link everything
    # linker_flag: "-static"
    # strip all symbols
    linker_flag: "-s"
  }
}

toolchain {
  toolchain_identifier: "local"
  abi_libc_version: "local"
  abi_version: "local"
  builtin_sysroot: ""
  compiler: "compiler"
  compiler_flag: "-U_FORTIFY_SOURCE"
  compiler_flag: "-D_FORTIFY_SOURCE=2"
  compiler_flag: "-fstack-protector"
  compiler_flag: "-Wall"
  compiler_flag: "-Wl,-z,-relro,-z,now"
  compiler_flag: "-B/usr/bin"
  compiler_flag: "-B/usr/bin"
  compiler_flag: "-Wunused-but-set-parameter"
  compiler_flag: "-Wno-free-nonheap-object"
  compiler_flag: "-fno-omit-frame-pointer"
  cxx_builtin_include_directory: "/usr/include/c++/4.8"
  cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu/c++/4.8"
  cxx_builtin_include_directory: "/usr/include/c++/4.8/backward"
  cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/4.8/include"
  cxx_builtin_include_directory: "/usr/local/include"
  cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed"
  cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu"
  cxx_builtin_include_directory: "/usr/include"
  cxx_flag: "-std=c++0x"
  host_system_name: "local"
  linker_flag: "-lstdc++"
  linker_flag: "-lm"
  linker_flag: "-Wl,-no-as-needed"
  linker_flag: "-B/usr/bin"
  linker_flag: "-B/usr/bin"
  linker_flag: "-pass-exit-codes"
  needsPic: true
  objcopy_embed_flag: "-I"
  objcopy_embed_flag: "binary"
  supports_fission: false
  supports_gold_linker: false
  supports_incremental_linker: false
  supports_interface_shared_objects: false
  supports_normalizing_ar: false
  supports_start_end_lib: false
  supports_thin_archives: false
  target_cpu: "k8"
  target_libc: "local"
  target_system_name: "local"
  unfiltered_cxx_flag: "-fno-canonical-system-headers"
  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
  tool_path {name: "ar" path: "/usr/bin/ar" }
  tool_path {name: "cpp" path: "/usr/bin/cpp" }
  tool_path {name: "dwp" path: "/usr/bin/dwp" }
  tool_path {name: "gcc" path: "/usr/bin/gcc" }
  tool_path {name: "gcov" path: "/usr/bin/gcov" }
  tool_path {name: "ld" path: "/usr/bin/ld" }
  tool_path {name: "nm" path: "/usr/bin/nm" }
  tool_path {name: "objcopy" path: "/usr/bin/objcopy" }
  tool_path {name: "objdump" path: "/usr/bin/objdump" }
  tool_path {name: "strip" path: "/usr/bin/strip" }

  compilation_mode_flags {
    mode: DBG
    compiler_flag: "-g"
  }
  compilation_mode_flags {
    mode: OPT
    compiler_flag: "-g0"
    compiler_flag: "-O2"
    compiler_flag: "-DNDEBUG"
    compiler_flag: "-ffunction-sections"
    compiler_flag: "-fdata-sections"
    linker_flag: "-Wl,--gc-sections"
  }
  linking_mode_flags { mode: DYNAMIC }
}

sorry that I have to screen some code for copyright reasons.

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

I'm using docker to build my project: docker pull chenkan1994/bazel-build:latest
Build with all the files I posted above should reproduce this bug.

What operating system are you running Bazel on?

Ubuntu 16.04

What's the output of bazel info release?

release 0.13.0

Have you found anything relevant by searching the web?

Replace these lines with your answer.

@tejal29
Copy link

tejal29 commented May 10, 2018

I am seeing a similar error

[0 / 7] [-----] BazelWorkspaceStatusAction stable-status.txt
ERROR: /tmpfs/tmp/bazel/external/com_google_protobuf/BUILD:101:1: undeclared inclusion(s) in rule '@com_google_protobuf//:protobuf':
this rule is missing dependency declarations for the following files included by 'external/com_google_protobuf/src/google/protobuf/wrappers.pb.cc':
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdint.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/x86intrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/ia32intrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/mmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/xmmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/mm_malloc.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/emmintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/immintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/fxsrintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include/adxintrin.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h'
  '/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h'
Target //docgen/scripts/docgen:docgen failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.490s, Critical Path: 0.34s
FAILED: Build did NOT complete successfully

The protobuf dependency we are pulling in is:

  name = "github.com/golang/protobuf"
  version = "1.1.0"

@slyrz
Copy link

slyrz commented May 12, 2018

Getting the same error with my custom CROSSTOOL which worked with bazel up to version 0.12.
A workaround is to declare the /usr/lib/gcc/x86_64-linux-gnu/.../include directory as another cxx_builtin_include_directory in the toolchain. Would be nice to know if this is a bug or intended behaviour.

@chenkan0104
Copy link
Author

@damienmg please help ;-)

@chenkan0104
Copy link
Author

well, I seem to have found the solution:
the local part in my CROSSTOOL file is wrong cause I use paths of gcc 4.8 in cxx_builtin_include_directory section, which would not exist in Ubuntu 16.04.
Here is my new CROSSTOOL file:

major_version: "local"
minor_version: ""
default_target_cpu: "same_as_host"

default_toolchain {
  cpu: "aarch64"
  toolchain_identifier: "gcc_5_4_1_aarch64"
}

default_toolchain {
  cpu: "k8"
  toolchain_identifier: "local_linux"
}

default_toolchain {
  cpu: "local"
  toolchain_identifier: "local_linux"
}

toolchain {
  abi_version: "gcc"
  abi_libc_version: "glibc_2.21"
  builtin_sysroot: ""
  compiler: "gcc"
  host_system_name: "k8"
  needsPic: true
  supports_gold_linker: false
  supports_incremental_linker: false
  supports_fission: false
  supports_interface_shared_objects: false
  supports_normalizing_ar: true
  supports_start_end_lib: false
  supports_thin_archives: true
  target_libc: "glibc_2.21"
  target_cpu: "aarch64"
  target_system_name: "aarch64"
  toolchain_identifier: "gcc_5_4_1_aarch64"

  tool_path { name: "ar" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-ar" }
  tool_path { name: "compat-ld" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-ld" }
  tool_path { name: "cpp" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-gcc" }
  tool_path { name: "dwp" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-dwp" }
  tool_path { name: "gcc" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-gcc" }
  tool_path { name: "gcov" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-gcov" }
  tool_path { name: "ld" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-ld" }
  tool_path { name: "nm" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-nm" }
  tool_path { name: "objcopy" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-objcopy" }
  objcopy_embed_flag: "-I"
  objcopy_embed_flag: "binary"
  tool_path { name: "objdump" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-objdump" }
  tool_path { name: "strip" path: "gcc-5.4.1-aarch64/aarch64-linux-gnu-strip" }

  compiler_flag: "--sysroot=external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc"
  # compiler_flag: "-mfloat-abi=hard"

  compiler_flag: "-nostdinc"
  compiler_flag: "-isystem"
  compiler_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/lib/gcc/aarch64-linux-gnu/5.4.1/include"
  compiler_flag: "-isystem"
  compiler_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc/usr/include"
  compiler_flag: "-isystem"
  compiler_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/lib/gcc/aarch64-linux-gnu/5.4.1/include-fixed"
  cxx_flag: "-isystem"
  cxx_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/include/c++/5.4.1/aarch64-linux-gnu"
  cxx_flag: "-isystem"
  cxx_flag: "external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/include/c++/5.4.1"
  cxx_flag: "-std=c++11"

  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//include)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//aarch64-linux-gnu/libc/usr/include)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//lib/gcc/aarch64-linux-gnu/5.4.1/include)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//lib/gcc/aarch64-linux-gnu/5.4.1/include-fixed)%"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//aarch64-linux-gnu/include)%/c++/5.4.1/aarch64-linux-gnu"
  cxx_builtin_include_directory: "%package(@org_linaro_releases_gcc_5_4_1_aarch64//aarch64-linux-gnu/include)%/c++/5.4.1"

  linker_flag: "--sysroot=external/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc"
  linker_flag: "-lstdc++"
  # linker_flag: "-lm"
  # linker_flag: "-lpthread"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/lib"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/lib64"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc/lib"
  linker_flag: "-Lexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/libc/usr/lib"
  linker_flag: "-Bexternal/org_linaro_releases_gcc_5_4_1_aarch64/aarch64-linux-gnu/bin"
  # linker_flag: "-Wl,--dynamic-linker=/lib/ld-linux-aarch64.so.1"
  # linker_flag: "-print-sysroot"
  # linker_flag: "-Wl,-verbose"

  # Anticipated future default.
  # This makes GCC and Clang do what we want when called through symlinks.
  unfiltered_cxx_flag: "-no-canonical-prefixes"
  linker_flag: "-no-canonical-prefixes"

  # Make C++ compilation deterministic. Use linkstamping instead of these
  # compiler symbols.
  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""

  # Security hardening on by default.
  # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
  # We need to undef it before redefining it as some distributions now have
  # it enabled by default.
  compiler_flag: "-U_FORTIFY_SOURCE"
  compiler_flag: "-fstack-protector"
  compiler_flag: "-fPIE"
  linker_flag: "-pie"
  linker_flag: "-Wl,-z,relro,-z,now"

  # Enable coloring even if there's no attached terminal. Bazel removes the
  # escape sequences if --nocolor is specified.
  compiler_flag: "-fdiagnostics-color=always"

  # All warnings are enabled. Maybe enable -Werror as well?
  compiler_flag: "-Wall"
  # Enable a few more warnings that aren't part of -Wall.
  compiler_flag: "-Wunused-but-set-parameter"
  # But disable some that are problematic.
  compiler_flag: "-Wno-free-nonheap-object" # has false positives

  # Keep stack frames for debugging, even in opt mode.
  compiler_flag: "-fno-omit-frame-pointer"

  # Stamp the binary with a unique identifier.
  linker_flag: "-Wl,--build-id=md5"
  linker_flag: "-Wl,--hash-style=gnu"

  compilation_mode_flags {
    mode: DBG
    # Enable debug symbols.
    compiler_flag: "-g"

    # Keep stack frames for debugging.
    # compiler_flag: "-fno-omit-frame-pointer"
  }
  compilation_mode_flags {
    mode: OPT
    # No debug symbols.
    # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
    # even generally? However, that can't happen here, as it requires special
    # handling in Bazel.
    compiler_flag: "-g0"

    # Conservative choice for -O
    # -O3 can increase binary size and even slow down the resulting binaries.
    # Profile first and / or use FDO if you need better performance than this.
    compiler_flag: "-O2"

    # Disable assertions
    compiler_flag: "-DNDEBUG"

    # Removal of unused code and data at link time (can this increase binary size in some cases?).
    compiler_flag: "-ffunction-sections"
    compiler_flag: "-fdata-sections"
    linker_flag: "-Wl,--gc-sections"

    # statically link everything
    # linker_flag: "-static"
    # strip all symbols
    linker_flag: "-s"
  }
}

toolchain {
  abi_version: "local"
  abi_libc_version: "local"
  builtin_sysroot: ""
  compiler: "compiler"
  host_system_name: "local"
  needsPic: true
  supports_gold_linker: false
  supports_incremental_linker: false
  supports_fission: false
  supports_interface_shared_objects: false
  supports_normalizing_ar: false
  supports_start_end_lib: false
  target_libc: "local"
  target_cpu: "local"
  target_system_name: "local"
  toolchain_identifier: "local_linux"

  tool_path { name: "ar" path: "/usr/bin/ar" }
  tool_path { name: "compat-ld" path: "/usr/bin/ld" }
  tool_path { name: "cpp" path: "/usr/bin/cpp" }
  tool_path { name: "dwp" path: "/usr/bin/dwp" }
  tool_path { name: "gcc" path: "/usr/bin/gcc" }
  cxx_flag: "-std=c++0x"
  linker_flag: "-lstdc++"
  linker_flag: "-B/usr/bin/"

  # TODO(bazel-team): In theory, the path here ought to exactly match the path
  # used by gcc. That works because bazel currently doesn't track files at
  # absolute locations and has no remote execution, yet. However, this will need
  # to be fixed, maybe with auto-detection?
  cxx_builtin_include_directory: "/usr/lib/gcc/"
  cxx_builtin_include_directory: "/usr/local/include"
  cxx_builtin_include_directory: "/usr/include"
  tool_path { name: "gcov" path: "/usr/bin/gcov" }

  # C(++) compiles invoke the compiler (as that is the one knowing where
  # to find libraries), but we provide LD so other rules can invoke the linker.
  tool_path { name: "ld" path: "/usr/bin/ld" }

  tool_path { name: "nm" path: "/usr/bin/nm" }
  tool_path { name: "objcopy" path: "/usr/bin/objcopy" }
  objcopy_embed_flag: "-I"
  objcopy_embed_flag: "binary"
  tool_path { name: "objdump" path: "/usr/bin/objdump" }
  tool_path { name: "strip" path: "/usr/bin/strip" }

  # Anticipated future default.
  unfiltered_cxx_flag: "-no-canonical-prefixes"
  unfiltered_cxx_flag: "-fno-canonical-system-headers"

  # Make C++ compilation deterministic. Use linkstamping instead of these
  # compiler symbols.
  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""

  # Security hardening on by default.
  # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
  # We need to undef it before redefining it as some distributions now have
  # it enabled by default.
  compiler_flag: "-U_FORTIFY_SOURCE"
  compiler_flag: "-D_FORTIFY_SOURCE=1"
  compiler_flag: "-fstack-protector"
  linker_flag: "-Wl,-z,relro,-z,now"

  # Enable coloring even if there's no attached terminal. Bazel removes the
  # escape sequences if --nocolor is specified. This isn't supported by gcc
  # on Ubuntu 14.04.
  # compiler_flag: "-fcolor-diagnostics"

  # All warnings are enabled. Maybe enable -Werror as well?
  compiler_flag: "-Wall"
  # Enable a few more warnings that aren't part of -Wall.
  compiler_flag: "-Wunused-but-set-parameter"
  # But disable some that are problematic.
  compiler_flag: "-Wno-free-nonheap-object" # has false positives

  # Keep stack frames for debugging, even in opt mode.
  compiler_flag: "-fno-omit-frame-pointer"

  # Anticipated future default.
  linker_flag: "-no-canonical-prefixes"
  # Have gcc return the exit code from ld.
  linker_flag: "-pass-exit-codes"
  # Gold linker only? Can we enable this by default?
  # linker_flag: "-Wl,--warn-execstack"
  # linker_flag: "-Wl,--detect-odr-violations"

  compilation_mode_flags {
    mode: DBG
    # Enable debug symbols.
    compiler_flag: "-g"
  }
  compilation_mode_flags {
    mode: OPT

    # No debug symbols.
    # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
    # even generally? However, that can't happen here, as it requires special
    # handling in Bazel.
    compiler_flag: "-g0"

    # Conservative choice for -O
    # -O3 can increase binary size and even slow down the resulting binaries.
    # Profile first and / or use FDO if you need better performance than this.
    compiler_flag: "-O2"

    # Disable assertions
    compiler_flag: "-DNDEBUG"

    # Removal of unused code and data at link time (can this increase binary size in some cases?).
    compiler_flag: "-ffunction-sections"
    compiler_flag: "-fdata-sections"
    linker_flag: "-Wl,--gc-sections"
  }
  linking_mode_flags { mode: DYNAMIC }
}

But now there is a new problem:

ERROR: cc_toolchain_suite '@bazel_build_toolchains//tools/arm_compiler:toolchain' does not contain a toolchain for CPU 'local' and compiler 'compiler'

And if I modify target_cpu to k8 in my CROSSTOOL file local part, this problem will disapear.
But I think this solution is not very elegant...
So is there anybody knows why k8 is necessary for target_cpu, and what is the best solution here.

@hlopko
Copy link
Member

hlopko commented May 23, 2018 via email

@chenkan0104
Copy link
Author

@mhlopko ok, here it is

filegroup(
    name = "toolchain_fg",
    srcs = [
        ":cc-compiler-aarch64",
        ":cc-compiler-k8",
        ":aarch64_linux_all_files",
        "@org_linaro_releases_gcc_5_4_1_aarch64//:compiler_components",
    ],
)

filegroup(
    name = "srcs",
    srcs = glob(["**"]) + [
        "//tools/arm_compiler/gcc-5.4.1-aarch64:srcs",
    ],
    # visibility = ["//visibility:public"],
)

cc_toolchain_suite(
    name = "toolchain",
    # target_cpu | compiler
    toolchains = {
        "aarch64|gcc": "cc-compiler-aarch64",
        "k8|compiler": "cc-compiler-k8",
    },
)

filegroup(
    name = "aarch64_linux_all_files",
    srcs = [
        "//tools/arm_compiler/gcc-5.4.1-aarch64:tool-wrappers",
        "@org_linaro_releases_gcc_5_4_1_aarch64//:compiler_pieces",
    ],
)

filegroup(
    name = "aarch64_linux_linker_files",
    srcs = [
        "//tools/arm_compiler/gcc-5.4.1-aarch64:ar",
        "//tools/arm_compiler/gcc-5.4.1-aarch64:gcc",
        "//tools/arm_compiler/gcc-5.4.1-aarch64:ld",
        "@org_linaro_releases_gcc_5_4_1_aarch64//:compiler_pieces",
    ],
)

filegroup(
    name = "aarch64_linux_compiler_files",
    srcs = [
        "//tools/arm_compiler/gcc-5.4.1-aarch64:as",
        "//tools/arm_compiler/gcc-5.4.1-aarch64:gcc",
        "//tools/arm_compiler/gcc-5.4.1-aarch64:ld",
        "@org_linaro_releases_gcc_5_4_1_aarch64//:compiler_pieces",
    ],
)

filegroup(
    name = "empty",
    srcs = [],
)

cc_toolchain(
    name = "cc-compiler-aarch64",
    all_files = ":aarch64_linux_all_files",
    compiler_files = ":aarch64_linux_compiler_files",
    cpu = "aarch64",
    dwp_files = ":empty",
    dynamic_runtime_libs = [":empty"],
    linker_files = ":aarch64_linux_linker_files",
    objcopy_files = "//tools/arm_compiler/gcc-5.4.1-aarch64:objcopy",
    static_runtime_libs = [":empty"],
    strip_files = "//tools/arm_compiler/gcc-5.4.1-aarch64:strip",
    supports_param_files = 1,
    visibility = ["//visibility:public"],
)

cc_toolchain(
    name = "cc-compiler-k8",
    all_files = ":empty",
    compiler_files = ":empty",
    cpu = "local",
    dwp_files = ":empty",
    dynamic_runtime_libs = [":empty"],
    linker_files = ":empty",
    objcopy_files = ":empty",
    static_runtime_libs = [":empty"],
    strip_files = ":empty",
    supports_param_files = 1,
    visibility = ["//visibility:public"],
)

@chenkan0104
Copy link
Author

@mhlopko so the problem is all targets in cc-compiler-k8 are empty?

@chenkan0104
Copy link
Author

OK, I think I've figured it out, toolchain in CROSSTOOL must match cc_toolchain_suite() right?

SOrry for the trouble, I'll close this issue.

@BruceDai003
Copy link

I met the same problem. But I don't understand how you solved it. It seems that you deleted gcc 4.8 part. But it seems that the CROSSTOOL code you pasted as a solution does not match what you've pasted in your first post, a lot of code has been changed. I can't match two files.
I'm new to bazel. Searched my files, only found one occurance of cxx_builtin_include_directory:

toolchain {
  toolchain_identifier: "local_windows"
  host_system_name: "local"
  target_system_name: "local"

  abi_version: "local"
  abi_libc_version: "local"
  target_cpu: "x64_windows"
  compiler: "msvc-cl"
  target_libc: "msvcrt"

%{cxx_builtin_include_directory}

  tool_path {
    name: "ar"
    path: "%{msvc_lib_path}"
  }
  tool_path {
    name: "ml"
    path: "%{msvc_ml_path}"
  }
  tool_path {
    name: "cpp"
    path: "%{msvc_cl_path}"
  }
  tool_path {
    name: "gcc"
    path: "%{msvc_cl_path}"
  }
  tool_path {
    name: "gcov"
    path: "wrapper/bin/msvc_nop.bat"
  }
  tool_path {
    name: "ld"
    path: "%{msvc_link_path}"
  }

in a CROSSTOOL.tpl file, didn't find any gcc version stuff.
Also, I don't knwo what this CROSSTOOL file is for, and the '.tpl' means what?

@smolkaj
Copy link

smolkaj commented Dec 1, 2022

We see a similar issue in p4lang/p4c#3748 (comment), but we're not using a custom CROSSTOOL. Any ideas?

@oakad
Copy link

oakad commented May 26, 2023

Because this ticket often comes in google search for a bunch of a similar issues, I decided to add this potentially helpful comment.

Basically, each time compiler version changes within a particular toolchain (including default toolchain, as in: compiler was upgraded on the host machine) it is desirable to clean up the bazel build cache in ~/.cache/bazel/ and rebuild the projects. Most of the times this simple action will make the funny "this rule is missing dependency declarations" errors go away.

@hypdeb
Copy link

hypdeb commented Sep 30, 2024

@oakad Do you know if there's an issue open somewhere to fix that? Having to clear caches in Bazel is allegedly not something one should ever have to do.

@fmeum
Copy link
Collaborator

fmeum commented Sep 30, 2024

@oakad Do you know if there's an issue open somewhere to fix that? Having to clear caches in Bazel is allegedly not something one should ever have to do.

It's not necessary to clear the cache, but you have to explicitly rerun the repo rules that detect non-hermetic host configuration via bazel fetch --configure --force. Maybe we should suggest that step in the error message.

@oakad
Copy link

oakad commented Oct 2, 2024

Every time I tried to use bazel fetch on its own it somehow broke on me. :-)

@oakad
Copy link

oakad commented Nov 6, 2024

@fmeum Can confirm that fetch solution seems to work. But, it's not something which is easy to remember so adding it to the error message will be most helpful.

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

No branches or pull requests

10 participants