Could you plz add another bazel example with `http_archive`?
Describe the bug
https://github.com/PJK/libcbor/blob/master/examples/bazel/WORKSPACE compiled,
However it failed to compile after replacing new_local_repository by http_archive.
To Reproduce
In https://github.com/PJK/libcbor/blob/master/examples/bazel/WORKSPACE, I replaced new_local_repository
new_local_repository(
name = "libcbor",
build_file = "//third_party:libcbor.BUILD",
path = "../../src",
)
by http_archive. (As a user, we need to use http_archive in the bazel)
http_archive(
name = "libcbor",
build_file = "//:libcbor.BUILD",
sha256 = "c83fc218414c5f3a2114e024255413521ddb40523f148c81d25a49c713d316dd",
strip_prefix = "libcbor-0.11.0",
urls = ["https://github.com/PJK/libcbor/archive/refs/tags/v0.11.0.zip"],
)
where, libcbor.BUILD is as same as https://github.com/PJK/libcbor/blob/master/examples/bazel/third_party/libcbor.BUILD
(I only updated the deps path + some typos in the srcs and hdrs)
cc_library(
name = "cbor",
srcs = glob([
"src/**/*.c",
]),
hdrs = glob([
"src/**/*.h",
]),
includes = [
"src",
"src/cbor",
"src/cbor/internal",
],
visibility = ["//visibility:public"],
deps = [
"@libcbor//examples/bazel/third_party/libcbor:config",
],
)
Then
-
bazel build :hellowork -
bazel build :testsfail
bazel build :tests
INFO: Analyzed target //src:tests (0 packages loaded, 0 targets configured).
ERROR: /tmp/bar/libcbor/examples/bazel/src/BUILD:20:8: Compiling src/hello_test.cc failed: (Exit 1): gcc failed: error executing CppCompile command (from target //src:tests) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++14' -MD -MF ... (remaining 60 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from external/googletest~/googletest/include/gtest/gtest-message.h:57,
from external/googletest~/googletest/include/gtest/gtest-assertion-result.h:46,
from external/googletest~/googletest/include/gtest/gtest.h:63,
from src/hello_test.cc:3:
external/googletest~/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
external/googletest~/googletest/include/gtest/internal/gtest-port.h:2107:10: error: 'strcasecmp' was not declared in this scope; did you mean 'StrCaseCmp'?
2107 | return strcasecmp(s1, s2);
| ^~~~~~~~~~
| StrCaseCmp
Target //src:tests failed to build
Expected behavior
bazel build: test succeed.
Could you plz provide an bazel example with http_archive?
Thank you so much.
Environment libcbor version and build configuration flags (or source package version if using a package manager).
I found out the problem is the
includes = [
"src",
"src/cbor",
"src/cbor/internal",
],
in the https://github.com/PJK/libcbor/blob/master/examples/bazel/third_party/libcbor.BUILD
There is a strings.h file under the src/cbor/strings.h too. It overwrites the c++'s default strings.h
How to fix?
includes = [
"src",
],
This fix the bug.
Looks reasonable, thank you, will fix as proposed (expect a few weeks delay, apologies).
Does https://github.com/PJK/libcbor/pull/340 address this? Please reopen if not