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

Emit with relative symlinks? #1250

Closed
j-baker opened this issue Aug 5, 2023 · 1 comment · Fixed by #1251
Closed

Emit with relative symlinks? #1250

j-baker opened this issue Aug 5, 2023 · 1 comment · Fixed by #1251

Comments

@j-baker
Copy link
Contributor

j-baker commented Aug 5, 2023

I'm using https://crane.dev to build a Cargo project with Nix. Crane has an elegant feature where it can precompile all dependencies in one build step (which is cached) so unless you change your dependencies, no recompile of dependencies is required. This drastically speeds up builds.

The approximate process by which it does this is:

cargo build
mv target $out

Unfortunately, cxx seems unique in our tech stack in that it creates absolute symlinks in its output, which end up like:

lrwxr-xr-x  1 root  wheel  189  1 Jan  1970 ./release/build/mycrate-461e0524ef218d12/out/cxxbridge/include/mycrate/src/lib.rs -> /private/tmp/nix-build-cargo-package-deps-0.0.1.drv-1/source/target/release/build/mycrate-461e0524ef218d12/out/cxxbridge/include/mycrate/src/lib.rs.h

Unfortunately, the tempdir is immediately deleted. I'm wondering if there's a reason other than simplicity that absolute symlinks are used here, and whether a PR might be accepted that adjusts them to being relative? At the moment I am resolving this problem by running symlinks -rc $PWD on the directory after the build has occurred, but this feels more fragile than fixing the source.

I think that this would also have the effect of meaning that cxx builds are not broken after a move of the project directory, but am not 100% on how cache invalidation works.

@dtolnay
Copy link
Owner

dtolnay commented Aug 5, 2023

I would be open to a PR that makes the symlinks relative.

j-baker added a commit to j-baker/cxx that referenced this issue Aug 5, 2023
Attempt to relativize symlinks. Fixes dtolnay#1250.

- Do not relativize where target or link are relative paths.
- Do not relativize where CARGO_TARGET_DIR is set, as this indicates
  that relativizing might not be helpful.
- Do not relativize where source or target contain `..`
dtolnay pushed a commit to j-baker/cxx that referenced this issue Aug 5, 2023
Attempt to relativize symlinks. Fixes dtolnay#1250.

- Do not relativize where target or link are relative paths.
- Do not relativize where CARGO_TARGET_DIR is set, as this indicates
  that relativizing might not be helpful.
- Do not relativize where source or target contain `..`
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 a pull request may close this issue.

2 participants