-
Notifications
You must be signed in to change notification settings - Fork 471
[email protected] #4644
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
[email protected] #4644
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
@bazel-io skip_check unstable_url |
Hello @Attempt3035, modules you maintain (cjson) have been updated in this PR. |
243f466
to
bfa582a
Compare
Fixed |
bfa582a
to
d479261
Compare
Using:
But not:
Any idea on how to include with angle brackets without the cjson prefix? includes = ["."] attribute is refused by CI:
|
You'll need to add includes = ["cjson"] Includes basically strips that prefix from the include path |
Right, I had to add:
to pass the CI. Which then means including as <cjson/cJSON.h>. |
Hmm, that should be able to add directly without the cjson folder prefix. Are you sure the compiler isn't picking up a system install of cjson? (as angled brackets look for system install before project dependency install) |
Oh, you might need to add "cjson/" as the strip prefix |
From my experiment: includes = [.] => -isystem external/cjson+ includes = ["cjson"] => -isystem external/cjson+/cjson
If putting cjson for both the includes and strip_include_prefix then I get the following error: Error in fail: header 'cJSON.h' is not under the specified strip prefix 'cjson' |
Without moving the cJSON.h to an include directory I don't see much we can do (cjson/ prefix is an acceptable tradeoff) |
Just to clarify, the goal is to be able to import cjson as #include "cjson.h" OR #include <cjson.h> ? In which case yes just the strip prefix cjson/ should be all we need, not the includes
Yes, sorry I wasn't clear with this, using includes exposes the files in that folder directly, strip prefix just strips the leading path of the header files. Nearly equivalent, but as you saw there's slight differences with how Basel works with system style imports between these two methods. Either way we can't do both at the same time |
The goal is to do: #include <cJSON.h> (and also #include "cJSON.h" if wanted) There is no cjson folder and cJSON.h/c are directly at the root directory.
I also though strip_include_prefix = "." would work but it looks not. |
d479261
to
f8bd8f3
Compare
Fixed by adding a patch to move all headers to an include directory. |
50182c4
to
af54a9c
Compare
Actually copying all headers because some tests are including directly as #include "../cJSON_Utils.h" |
Ahh, sorry I misunderstood part of the problem. Just adding: As you mentioned earlier did indeed work for me, as the compiler now indeed falls back to searching included folders if failing system libs (allows adding via both #include <cJSON.h> and #include "cJSON.h", tested on MacOS with Clang) does it solve it for you? (It should be functionally equivalent to the copy to include + includes=["include"] method) - That way we can avoid duplicating headers to another folder. |
Indeed just adding But the BCR presubmit was failing when running the test module: https://buildkite.com/bazel/bcr-presubmit/builds/14237#0196f4de-6bff-4deb-ab0c-da0751b7ec4c
|
Got it. Let's use a genrule to do the file copy, so that we don't need to maintain copy patches (as when the lib is updated we'd have to re-make the patches every time we bump the source version) Try: cc_library(
name = "cjson",
srcs = ["cJSON.c"],
hdrs = [":copy_headers"],
includes = ["include"],
copts = CJSON_COPTS + [
"-DCJSON_EXPORT_SYMBOLS",
"-DCJSON_API_VISIBILITY",
],
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": ["-lm"], # Link math library on non-Windows
}),
visibility = ["//visibility:public"],
)
genrule(
name = "copy_headers",
srcs = ["cJSON.h"],
outs = ["include/cJSON.h"],
cmd = "mkdir -p $(@D) && cp $(SRCS) $(@D)/cJSON.h",
) Works and passes all tests on my computer, it should work for windows too but if the BCR windows builds fail lmk and we can add a windows specific copy command |
3706171
to
206a64f
Compare
My bad, try having the genrule as a dep and the header referenced directly: cc_library(
name = "cjson",
srcs = ["cJSON.c"],
hdrs = ["include/cJSON.h"],
deps = [":copy_headers"],
includes = ["include"],
copts = CJSON_COPTS + [
"-DCJSON_EXPORT_SYMBOLS",
"-DCJSON_API_VISIBILITY",
],
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": ["-lm"], # Link math library on non-Windows
}),
visibility = ["//visibility:public"],
)
genrule(
name = "copy_headers",
srcs = ["cJSON.h"],
outs = ["include/cJSON.h"],
cmd = "mkdir -p $(@D) && cp $(SRCS) $(@D)/cJSON.h",
) If that doesn't fix it, the cmd might be silently failing or misplacing the file on windows |
206a64f
to
adc5182
Compare
Right! I removed the mkdir as it is automatically done by Bazel. We could also have used the copy_file rule from skylib but it would add a dependency: https://github.com/bazelbuild/bazel-skylib/blob/main/rules/private/copy_file_private.bzl
|
@Attempt3035 All tests are passing so ready to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect! Thanks for this!! 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @bazelbuild/bcr-maintainers, all modules in this PR have been approved by their maintainers. This PR will be merged if all presubmit checks pass.
Allow to be added as a system include using angle brackets.