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

Replace symlinks in the output of cargo build scripts #3067

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

havasd
Copy link
Contributor

@havasd havasd commented Dec 9, 2024

#2948 breaks building of rdkafka with cmake because of dangling symlinks.

When building with latest version we get the following error:

ERROR: /home/wincent/.cache/bazel/_bazel_wincent/394c4c1d21c5490d4a70260a2cfccaf5/external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/BUILD.bazel:68:19: error while validating output tree artifact external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/_bs.out_dir: child lib/cmake/RdKafka/FindLZ4.cmake is a dangling symbolic link
ERROR: /home/wincent/.cache/bazel/_bazel_wincent/394c4c1d21c5490d4a70260a2cfccaf5/external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/BUILD.bazel:68:19: Running Cargo build script rdkafka-sys failed: not all outputs were created or valid
Target @@rules_rust~~crate~crates__rdkafka-0.37.0//:rdkafka failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/wincent/.cache/bazel/_bazel_wincent/394c4c1d21c5490d4a70260a2cfccaf5/external/rules_rust~~crate~crates__rdkafka-sys-4.8.0-2.3.0/BUILD.bazel:18:13 Compiling Rust rlib rdkafka_sys v4.8.0+2.3.0 (7 files) failed: not all outputs were created or valid

Fixes #3099

Copy link

google-cla bot commented Dec 9, 2024

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.

@havasd havasd force-pushed the cargo_build_symlink branch 2 times, most recently from 502fa0b to 1d10ca0 Compare December 10, 2024 22:20
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... Do you know what the symlink is pointing at which is missing? In generally we want to preserve symlinks if possible - is it a symlink to an absolute path? Or a relative path inside in the outdir? Or a relative path inside the sandbox?

@havasd
Copy link
Contributor Author

havasd commented Dec 11, 2024

Hmm... Do you know what the symlink is pointing at which is missing? In generally we want to preserve symlinks if possible - is it a symlink to an absolute path? Or a relative path inside in the outdir? Or a relative path inside the sandbox?

It was an absolute path symlink. Essentially when cmake installs the header files as is. So if they were symlinks it will keep them symlinks. It means that due to the linked change now we symlink the runfiles instead of copying therefore nearly all of the native code dependencies will have absolute path symlinks to the sandbox.

I can try to make some change so that relative symlinks in the outdir is preserved.

@havasd havasd force-pushed the cargo_build_symlink branch from 1d10ca0 to 5b3d833 Compare December 11, 2024 09:30
@illicitonion
Copy link
Collaborator

Yeah, I think inlining absolute symlinks feels a lot more reasonable - it's still not obviously the correct semantics, but it's probably reasonable to do. Thanks!

@havasd havasd force-pushed the cargo_build_symlink branch from 5b3d833 to ba87b4a Compare December 14, 2024 13:10
@havasd
Copy link
Contributor Author

havasd commented Dec 14, 2024

I have changed it to skip resolving relative symlinks.

Could you please clarify what would be the correct semantics? It feels to me that when the entire source tree of a dependency which needs to be built is symlinked into the sandbox we must resolve them. Otherwise the symlinks will point to the sandbox

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! One last piece - can you add a couple of tests to https://github.com/bazelbuild/rules_rust/tree/0.55.6/test/cargo_build_script? I'm imagining:

  1. A cargo_build_script which writes a tempfile to /tmp/ with some contents, symlinks to it in $OUT_DIR, then a rust_test which include!s the $OUT_DIR path and sees the contents is correct, and which lstats with $OUT_DIR path and checks it's a file not a symlink
  2. The same test, but which writes another file into $OUT_DIR with some contents, creates a relative symlink pointing at the other file in $OUT_DIR, and which does the same checks but checks it's a symlink not a file

@havasd
Copy link
Contributor Author

havasd commented Dec 14, 2024

I have added tests

EDIT: I tried to make testing the symlink existence work but it doesn't seem to me that we could properly validate from rust_test. We need to include it as a data dependency in order ot be able to make it accessible but depending on the setup there is a variety of ways how these files are made available. Some configurations include them as symlink some uses copy etc...

Therefore, I had to skip testing the symlink existence

@havasd havasd force-pushed the cargo_build_symlink branch 17 times, most recently from 10df54a to 0b18c0d Compare December 16, 2024 07:20
@havasd havasd force-pushed the cargo_build_symlink branch 2 times, most recently from c3f6b84 to 8f39cc1 Compare December 16, 2024 21:58
@havasd

This comment was marked as outdated.

@havasd havasd force-pushed the cargo_build_symlink branch 2 times, most recently from 5ef45f0 to 1263d13 Compare December 17, 2024 22:12
@illicitonion
Copy link
Collaborator

@UebelAndre You have a lot more context than I do here - can you weigh in on this vs #3111 vs something else?

@havasd havasd force-pushed the cargo_build_symlink branch from 1263d13 to b14a4c9 Compare December 18, 2024 15:06
@havasd havasd force-pushed the cargo_build_symlink branch 2 times, most recently from a978e00 to 653841d Compare December 31, 2024 19:20
@havasd
Copy link
Contributor Author

havasd commented Dec 31, 2024

@UebelAndre if you have some time could you please review this PR?

@UebelAndre
Copy link
Collaborator

I can take a look this week!

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits but this otherwise seems good to me! Thank you for your patience with me!

cargo/cargo_build_script_runner/bin.rs Outdated Show resolved Hide resolved
cargo/cargo_build_script_runner/bin.rs Outdated Show resolved Hide resolved
@havasd havasd force-pushed the cargo_build_symlink branch 2 times, most recently from 0b14ad8 to 4159baa Compare January 3, 2025 16:39
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI seems to have flaked so this will need one more push. But if you also have time to look into https://github.com/bazelbuild/rules_rust/pull/3067/files#r1902089155 that'd be sweet!

@havasd havasd force-pushed the cargo_build_symlink branch 2 times, most recently from 44f4bc5 to c3ccf85 Compare January 3, 2025 20:56
After bazelbuild#2948 we symlink the source files in sandbox for most external repositories.
When a native build system is involved (e.x.: cmake) it is possible that the installed
files will be symlinks especially when header files are installed.

This will be placed in the output dir of cargo build scripts and when copied back to
the repository cache they become dangling symlinks with references to the sandbox.

As a fix we replace symlinks with a copy of them in the output directory.
@havasd havasd force-pushed the cargo_build_symlink branch from c3ccf85 to 53a8311 Compare January 3, 2025 21:03
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you so much!

@UebelAndre UebelAndre added this pull request to the merge queue Jan 3, 2025
Merged via the queue into bazelbuild:main with commit 1d0fe8a Jan 3, 2025
3 checks passed
@spags-lacework
Copy link

Thanks for fixing this. Do you know when you will do include this in a new version of rules_rust?

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

Successfully merging this pull request may close these issues.

rdkafka-sys has dangling symbolic link with rules rust 0.54.1 and higher
4 participants