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

rustPlatform.importCargoLock: allow duplicated packages with git. #282798

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

junjihashimoto
Copy link
Member

@junjihashimoto junjihashimoto commented Jan 22, 2024

Description of changes

Fix these issues(#183344 and #30742).
This patch does the same thing of cargo-vendor --no-merge-sources.
It puts git sources to 'git-<sha>' directory.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@kirillrdy
Copy link
Member

greetings @junjihashimoto this should target staging branch due to mass rebuilds

https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#changes-causing-mass-rebuilds

beware of commit pitfall when changing target branch https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#rebasing-between-branches-ie-from-master-to-staging

@junjihashimoto junjihashimoto changed the base branch from master to staging January 22, 2024 07:49
@junjihashimoto
Copy link
Member Author

@kirillrdy Thx! Rebased to staging branch.

siddhantk232 added a commit to fastn-stack/fastn that referenced this pull request Jan 24, 2024
@siddhantk232
Copy link
Contributor

siddhantk232 commented Feb 27, 2024

LGTM. I am able to use this branch to build a rust binary which I couldn't build with nixpkgs-unstable.

@risicle
Copy link
Contributor

risicle commented Apr 14, 2024

Interestingly this doesn't solve my issue trying to built qdrant 1.8.4, which contains two "wal 0.1.2"s with different git revs https://github.com/qdrant/qdrant/blob/v1.8.4/Cargo.lock

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 22, 2024
Copy link
Member

@poelzi poelzi left a comment

Choose a reason for hiding this comment

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

tested with a sui flake that would not compile otherwise.
LGTM

@poelzi
Copy link
Member

poelzi commented Sep 14, 2024

@junjihashimoto can you rebase ?

@junjihashimoto
Copy link
Member Author

Sure!

@ofborg ofborg bot added 10.rebuild-darwin: 5001+ and removed 2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-darwin: 2501-5000 labels Sep 14, 2024
@poelzi poelzi requested a review from kirillrdy October 10, 2024 22:23
@poelzi
Copy link
Member

poelzi commented Oct 10, 2024

I had success with the last version but now it breaks while building postgresql.

❯ nix develop .
warning: Git tree '/data/home/poelzi/Projects/sui/sui' is dirty
error: builder for '/nix/store/qq3g9i45ngsmc56a0d9dvq3bvinxv1v7-postgresql-16.4.drv' failed with exit code 2;
       last 10 log lines:
       > ok 214       + oidjoins                                 1020 ms
       > ok 215       - fast_default                              686 ms
       > ok 216       - tablespace                               1526 ms
       > 1..216
       > # 3 of 216 tests failed.
       > # The differences that caused some tests to fail can be viewed in the file "/build/postgresql-16.4/src/test/regress/regression.diffs".
       > # A copy of the test summary that you see above is saved in the file "/build/postgresql-16.4/src/test/regress/regression.out".
       > make[1]: *** [GNUmakefile:118: check] Error 1
       > make[1]: Leaving directory '/build/postgresql-16.4/src/test/regress'
       > make: *** [GNUmakefile:69: check] Error 2
       For full logs, run 'nix log /nix/store/qq3g9i45ngsmc56a0d9dvq3bvinxv1v7-postgresql-16.4.drv'.

@getchoo getchoo mentioned this pull request Oct 11, 2024
13 tasks
@Daholli
Copy link
Contributor

Daholli commented Oct 18, 2024

Is there something we can help with here? Testing or anything

@schradert schradert mentioned this pull request Jan 6, 2025
13 tasks
@gepbird gepbird added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 25, 2025
Copy link
Contributor

@TomaSajt TomaSajt left a comment

Choose a reason for hiding this comment

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

There are packages that use two different crates from the same git repo with the same gitSha. I don't remember which packages, but I've seen them.
So, in those cases there would be key duplications in the source definitions. (Which, I think, would cause toml parsing errors)

Edit: I was wrong, sorry!
It looks like I don't even remember how the code worked... even though I wrote it :/

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 27, 2025
@junjihashimoto
Copy link
Member Author

Fixed the merge conflict.

@junjihashimoto
Copy link
Member Author

@TomaSajt Please remember the code as I don't think anyone else can review this PR but you.

@TomaSajt
Copy link
Contributor

TomaSajt commented Jan 27, 2025

Note: I haven't thoughly reviewed the importCargoLock part yet.

IMO the git sources should be in git/gitShaRev instead of git-gitShaRev.

And maybe when other registries become supported they should also get a registry/registryName subdir

Or is this just how cargo vendor --no-merge-sources works? Haven't checked it.

Though, we have to be careful with moving things, since some packages assume the vendor directory's structure when patching some dependencies.

So maybe, to keep breakages to a minimum, only the git stuff should get their own subdir, and the registry deps should stay in the original base directory, instead of in ./registry.

@junjihashimoto
Copy link
Member Author

Or is this just how cargo vendor --no-merge-sources works? Haven't checked it.

Yes.

So maybe, to keep breakages to a minimum, only the git stuff should get their own subdir, and the registry deps should stay in the original base directory, instead of in ./registry.

The original registry structure cannot stay as it does not allow multiple packages with different git-hashes for the same version of the same package.

@TomaSajt
Copy link
Contributor

TomaSajt commented Jan 27, 2025

The original registry structure cannot stay as it does not allow multiple packages with different git-hashes for the same version of the same package.

Sorry if I wasn't being clear: I meant the registry-based stuff only. The git based stuff should go to a different place, since that's what's clashing.

(For the record: I looked at the implementation of cargo-vendor --no-merged-sources and it uses git-{hash} and registry-{hash} names for its directories, where {hash} is some random hash calculated from the name of the source. Just mentioning this here, not recommending to do the same.)

@junjihashimoto
Copy link
Member Author

The registry-based stuff is registry-{hash} with cargo-vendor --no-merged-sources.
The following URL is a working example:
https://gist.github.com/junjihashimoto/b9fa01ba5983e98a1e21322eca541752#file-cargo-config-toml-L103

In this PR, the path is registry not registry-{hash}, but it doesn't seem to matter whether the base registry has a hash or not.

@TomaSajt
Copy link
Contributor

TomaSajt commented Jan 27, 2025

Yes, the name doesn't matter currently, since we only support crates-io.
I think in the future we should have subdirectories, like registry/ or registry-{hash}.

The problem is, that there are packages that edit files inside cargoDepsCopy (search for them and test them out), and they will fail to build, since the crate they're trying to edit has been moved from $cargoDepsCopy/foo-1.0.0 to $cargoDepsCopy/registry/foo-1.0.0

If we don't want to also fix all of these packages in this PR we may not move files inside registry.

I don't know if there are any derivations that try to edit a git-based dependency, but those will 100% be broken by this PR no matter what we do.

@TomaSajt
Copy link
Contributor

But, since there are so few of these packages, it shouldn't be too hard to fix them.

If you want to do the fixing yourself, I recommend not hardcoding $cargoDepsCopy/registry/some-package-*, but just using $cargoDepsCopy/*/some-package-*, so they won't depend on the exact naming.

ln -s "$crate" "$out/$gitdir/$package_name"
fi
else
ln -s "$crate" $out/$(basename "$crate" | cut -c 34-)
Copy link
Contributor

Choose a reason for hiding this comment

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

When is this branch reached?

Copy link
Member Author

@junjihashimoto junjihashimoto Jan 27, 2025

Choose a reason for hiding this comment

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

As long as the above mkCrate is running, it will never be reached, so it can be deleted.

Comment on lines 305 to 308
# This is to handle the case of referencing a package with a relative path.
if [ ! -e "$out/$gitdir/$package_name" ] ; then
ln -s "$crate" "$out/$gitdir/$package_name"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide an example when this happens?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for pointing that out. This might not be necessary.

@@ -31,34 +31,36 @@ def replace_key(
local_dep = table[key]
del local_dep["workspace"]

workspace_dep = workspace_manifest[section][key]

if section == "dependencies":
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you summarize what was fixed in this file?

Copy link
Member Author

Choose a reason for hiding this comment

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

There may be cases where there is no value for a key such as "dependencies".
I encountered this when building the sui package.

@TomaSajt
Copy link
Contributor

By the way: merging into a PR branch is not recommended. You should have rebased on top of the revision you want, instead of merging.

Since this PR doesn't depend on anything that's currently in staging, I think you should rebase onto the common merge base between master and staging.
(FYI the common merge base is currently rev fa9a43a8d9c6bc8672910d7d73da0e512b0df118)

This way it's easier to test the changes, because you don't have to rebuild everything that's in staging.

Here's a way you could do it:

  • undo merge with git reset HEAD~ --hard
  • run git rebase fa9a43a8d9c6bc8672910d7d73da0e512b0df118
  • fix conflict, just like the merge conflict
  • git add the fixed conflicting files and run git rebase --continue
  • when you're done and checked that the commits are correct, you can do git push --force

@@ -29,6 +30,7 @@ rustPlatform.buildRustPackage {
buildInputs =
[
openssl
zlib
Copy link
Member Author

Choose a reason for hiding this comment

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

It wasn't necessary on Linux, but it seems to be necessary on Darwin.

@junjihashimoto
Copy link
Member Author

@TomaSajt
Thank you! The code fixes and the rebase are done.

@junjihashimoto
Copy link
Member Author

@TomaSajt Please let me know if there's anything else blocking the approval or if you have any other concerns.

@TomaSajt
Copy link
Contributor

TomaSajt commented Feb 1, 2025

We should wait for the mass migration PRs to reach master, first.

After that, the packages that still use $cargoDepsCopy should be fixed manually (maybe in this PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.