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

Fix precompiled lib symlinks missing in runfiles of cc_shared_library #19378

Closed
wants to merge 2 commits into from

Conversation

Flamefire
Copy link
Contributor

26d882f was intended to remove unnecessary files from runfiles However it also removes (some?) required symlinks from runfiles. E.g. libtensorflow_cc.so.2.13.0 is present in the runfiles but libtensorflow_cc.so.2 is not leading to failures as programs are linked to the latter. See tensorflow/tensorflow#60326

Use the same logic used in other places preferring resolved_symlink_dynamic_library over dynamic_library.

26d882f was intended to remove unnecessary files from runfiles
However it also removes (some?) required symlinks from runfiles.
E.g. libtensorflow_cc.so.2.13.0 is present in the runfiles but
`libtensorflow_cc.so.2` is not leading to failures as programs are
linked to the latter.

Use the same logic used in other places preferring
`resolved_symlink_dynamic_library` over `dynamic_library`.
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Aug 31, 2023
@iancha1992 iancha1992 added the team-Rules-CPP Issues for C++ rules label Sep 1, 2023
@Flamefire
Copy link
Contributor Author

Flamefire commented Sep 1, 2023

It looks like //src/main/starlark/tests/builtins_bzl:cc_builtin_tests is failing on CI but can't see what exactly fails and I can't find how to run this test locally. However that might as well be an issue with the test which 26d882f seems to have changed to only testing actually created files against a list of "expected" files while the issue intended to be fixed here is to add an expected file which was not created before. That might explain the failure

I'd argue that is an oversight in the test as right now the test would pass when NO files were being created at all which likely isn't the intention.

@oquenchil
Copy link
Contributor

It looks like //src/main/starlark/tests/builtins_bzl:cc_builtin_tests is failing on CI but can't see what exactly fails and I can't find how to run this test locally. However that might as well be an issue with the test which 26d882f seems to have changed to only testing actually created files against a list of "expected" files while the issue intended to be fixed here is to add an expected file which was not created before. That might explain the failure

I'd argue that is an oversight in the test as right now the test would pass when NO files were being created at all which likely isn't the intention.

Yes, please modify the test to account for these new files.

Just run:

bazel test //src/main/starlark/tests/builtins_bzl:cc_builtin_tests

The test to modify is here

Allow the new files `libdirect_so_file.so` & `renamed_so_file_copy.so` in runfiles.
Add a test for expected files in runfiles as the other test (part) may pass when runfiles is empty
@Flamefire
Copy link
Contributor Author

I ran the test on my machine and printed the expected and actual files, i.e. target[DefaultInfo].default_runfiles.files.to_list() and expected_basenames via

        all_files = target[DefaultInfo].default_runfiles.files.to_list()
        env.expect.where(
            detail = runfile.path + " not found in expected basenames:\n"
                    + "\n".join(expected_basenames)
                    + "\n All files:\n"
                    + "\n".join([f.path for f in all_files])
        ).that_bool(found_basename).equals(True)

bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/libdirect_so_file.so not found in expected basenames:

libfoo_so.so
libbar_so.so
libdiff_pkg_so.so
libprivate_lib_so.so
Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary_Slibfoo_Uso.so
Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary_Slibbar_Uso.so
Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary3_Slibdiff_Upkg_Uso.so
Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/renamed_so_file_copy.so
Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/libdirect_so_file.so
 All files:
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/libfoo_so.so
bazel-out/k8-fastbuild/bin/_solib_k8/_Usrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/libfoo_so.so
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/libbar_so.so
bazel-out/k8-fastbuild/bin/_solib_k8/_Usrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/libbar_so.so
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3/libdiff_pkg_so.so
bazel-out/k8-fastbuild/bin/_solib_k8/_Usrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary3/libdiff_pkg_so.so
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/libprivate_lib_so.so
bazel-out/k8-fastbuild/bin/_solib_k8/_Usrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/libprivate_lib_so.so
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/renamed_so_file_copy.so
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/libdirect_so_file.so
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/python_test
src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/python_test.py
bazel-out/k8-fastbuild/bin/external/bazel_tools/tools/python/py3wrapper.sh

Given this I'd expect the first failure in renamed_so_file_copy.so and am surprised by the first failure of libdirect_so_file.so

Anyway what this PR changes is replacing

bazel-out/k8-fastbuild/bin/_solib_k8/_U_S_Ssrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary_Cfoo___Usrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/renamed_so_file_copy.so
bazel-out/k8-fastbuild/bin/_solib_k8/_U_S_Ssrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary_Cprebuilt___Usrc_Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/libdirect_so_file.so

by

bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/libdirect_so_file.so
bazel-out/k8-fastbuild/bin/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/renamed_so_file_copy.so

I adapted the test accordingly and enhanced it to not only check for superflous files but also for missing files.

I see renamed_so_file_copy.so listed in srcs at

which is similar to the situation in TF where the missing lib is also listed in srcs: https://github.com/tensorflow/tensorflow/blob/be88ba0aefb1b778c2c0d0d896a342a70579740c/tensorflow/tensorflow.bzl#L2415-L2420

So I'd say this is indeed a valid fix and the enhanced test covers it. But as I don't know the intention behind using those mangled paths in _solib_k8 please double check and if this turns out to be the wrong approach please coordinate with the TF team on how that build can be fixed

@oquenchil oquenchil added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Sep 11, 2023
@Pavank1992
Copy link
Contributor

Hi @Flamefire, it seems there is a failure on buildkite, could you please take a look and fix the error: https://buildkite.com/bazel/google-bazel-presubmit/builds/71675#018ab151-4f5a-4b35-9f1e-521a873e023b

@Flamefire
Copy link
Contributor Author

Hi @Flamefire, it seems there is a failure on buildkite, could you please take a look and fix the error: https://buildkite.com/bazel/google-bazel-presubmit/builds/71675#018ab151-4f5a-4b35-9f1e-521a873e023b

@Pavank1992 From the linked log I cannot see why that test on that system failed.
I ran bazel test --flaky_test_attempts=1 //src/test/py/bazel:bzlmod_query_test locally and it passed.

@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Sep 22, 2023
@Flamefire Flamefire deleted the fix-lib-symlink branch September 22, 2023 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-CPP Issues for C++ rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants