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

Can't find jni.h if target not declared at the root of workspace #5497

Closed
jirkadanek opened this issue Jun 29, 2018 · 4 comments
Closed

Can't find jni.h if target not declared at the root of workspace #5497

jirkadanek opened this issue Jun 29, 2018 · 4 comments
Assignees
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: linux stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug

Comments

@jirkadanek
Copy link

Description of the problem:

I am having a problem I first saw described at https://stackoverflow.com/questions/49824574/cant-find-jni-h-if-target-not-declared-at-the-root-of-workspace.

If I want to build a cc_library which depends on jni.h, I either have to put the target in a BUILD file in the directory of the top level project WORKSPACE, or use workaround from the SO question.

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

git clone [email protected]:mhlopko/bazel-jni-example.git
bazel build // ... # this passes just fine

mkdir nested
mv BUILD *.cc *.h *.java nested/
bazel build //...
............
WARNING: /home/jdanek/Work/repos/bazel-jni-example/nested/BUILD:3:12: in srcs attribute of cc_library rule //nested:main-jni-lib: please do not import '@local_jdk//:include/jni.h' directly. You should either move the file to this package or depend on an appropriate rule there
WARNING: /home/jdanek/Work/repos/bazel-jni-example/nested/BUILD:3:12: in srcs attribute of cc_library rule //nested:main-jni-lib: please do not import '@local_jdk//:include/linux/jni_md.h' directly. You should either move the file to this package or depend on an appropriate rule there
INFO: Analysed 3 targets (14 packages loaded).
INFO: Found 3 targets...
ERROR: /home/jdanek/Work/repos/bazel-jni-example/nested/BUILD:1:1: C++ compilation of rule '//nested:main-jni-lib' failed (Exit 1)
nested/Main.cc:1:10: fatal error: jni.h: No such file or directory
 #include <jni.h>
          ^~~~~~~
compilation terminated.
INFO: Elapsed time: 3.842s, Critical Path: 0.26s
FAILED: Build did NOT complete successfully

What operating system are you running Bazel on?

Linux, NixOS 18.03, x86_64

What's the output of bazel info release?

release 0.12.0- (@non-git)

(whoops) but same thing happens with clensing all with bazel clean, bazel shutdown, upgrading, and

$ bazel info release
release 0.15.0- (@non-git)

$ bazel build //...
DEBUG: /home/jdanek/.cache/bazel/_bazel_jdanek/0ce7434c4d8b52d94187c164d9bd419c/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:115:5: 
Auto-Configuration Warning: Cannot find gcov or GCOV; either correct your path or set the GCOV environment variable
WARNING: /home/jdanek/Work/repos/bazel-jni-example/nested/BUILD:3:12: in srcs attribute of cc_library rule //nested:main-jni-lib: please do not import '@local_jdk//:include/jni.h' directly. You should either move the file to this package or depend on an appropriate rule there
WARNING: /home/jdanek/Work/repos/bazel-jni-example/nested/BUILD:3:12: in srcs attribute of cc_library rule //nested:main-jni-lib: please do not import '@local_jdk//:include/linux/jni_md.h' directly. You should either move the file to this package or depend on an appropriate rule there
INFO: Analysed 3 targets (15 packages loaded).
INFO: Found 3 targets...
ERROR: /home/jdanek/Work/repos/bazel-jni-example/nested/BUILD:1:1: C++ compilation of rule '//nested:main-jni-lib' failed (Exit 1)
nested/Main.cc:1:10: fatal error: jni.h: No such file or directory
 #include <jni.h>
          ^~~~~~~
compilation terminated.
INFO: Elapsed time: 8.032s, Critical Path: 1.95s
INFO: 1 process: 1 worker.
FAILED: Build did NOT complete successfully

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

From checkout of nixpkgs with applied NixOS/nixpkgs#42735

nix-env -i bazel -f nixpkgs

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

It's from 0.15.0 zipped source release from github

Have you found anything relevant by searching the web?

https://stackoverflow.com/questions/49824574/cant-find-jni-h-if-target-not-declared-at-the-root-of-workspace

@lfpino
Copy link
Contributor

lfpino commented Jul 4, 2018

Assigning to @mhlopko for triage.

@hlopko
Copy link
Member

hlopko commented Jul 4, 2018

The principled fix would be to change header targets in https://source.bazel.build/bazel/+/6b8c7ca48e9e48a9906c031346dc4a924b7ef559:src/main/tools/jdk.BUILD into cc_imports. For that we would need to add incldues attribute to cc_import. And we don't want to do it before #4570 is fixed and cc_import is migrated to Skylark.

In the meantime, the workaround is to change includes attribute in main-jni-lib from includes = [ "external/local_jdk/include", "external/local_jdk/include/linux" ], to includes = [ "../external/local_jdk/include", "../external/local_jdk/include/linux" ],

Dekujeme do Brna :)

@hlopko hlopko assigned oquenchil and unassigned hlopko Jul 4, 2018
@hlopko hlopko added team-Rules-CPP Issues for C++ rules and removed category: rules > C++ labels Oct 11, 2018
@c-mita c-mita added the P3 We're not considering working on this, but happy to review a PR. (No assignee) label Nov 23, 2020
@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 2+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Apr 12, 2023
@github-actions
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: linux stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

5 participants