Skip to content

Update cargo builder to fetch registry dynamically. - #27964

Closed
kevincox wants to merge 1 commit into
NixOS:masterfrom
kevincox:cargo-live
Closed

kevincox wants to merge 1 commit into
NixOS:masterfrom
kevincox:cargo-live

Conversation

@kevincox

@kevincox kevincox commented Aug 5, 2017 •

Copy link
Copy Markdown
Contributor
Motivation for this change

See commit message

The biggest benifit is that we no longer have to update the registry
package. This means that just about any cargo package can be built by
nix. No longer does cargo update need to be feared because it will
update to packages newer then what is available in nixpkgs.

Things done

Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers.

  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

  • Rename deps attribute

Fixes #14469
Fixes #23282

@kevincox kevincox added 0.kind: enhancement Add something new or improve an existing system. 6.topic: developer experience nixpkgs development workflow 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 6.topic: user experience NixOS / Nixpkgs end user experience labels Aug 5, 2017
Comment thread pkgs/build-support/rust/default.nix Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

strace should be probably removed again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I usually use sysdig for those cases as I don't need to modify the environment.

The biggest benefit is that we no longer have to update the registry
package. This means that just about any cargo package can be built by
nix. No longer does `cargo update` need to be feared because it will
update to packages newer then what is available in nixpkgs.

This works very similarly to the old technique except instead of using
cargo's internal cache and stripping out as much as possible it uses the
new custom registry support to generate a minimal registry with
exactly what we need.

Like this existing method this will download crates multiple times for
different packages. This is a shame because the Cargo.lock hash hashes
inside of it but Nix doesn't really support this.

This also uses the new --frozen and --locked flags which is nice.

Currently cargo-local-registry only provides binaries for Linux and
macOS 64-bit. This can be solved by building it for the other
architectures and uploading it somewhere (like the NixOS cache).

This also has the downside that it requires a change to everyone's deps
hash. And if the old one is used because it was cached it will fail to
build as it will attempt to use the old version.
let
version = "0.1.4";
platform =
if stdenv.system == "x86_64-linux"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We will also need aarch64. Maybe we can work-around getting cargo build in bootstrap phase without this package and build cargo-local-registry from source.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are a lot of dependencies and other stuff to manage. I don't think I know enough about the rust setup to do it myself but if someone can take it on that would be great. I was focused here on showing that cargo-local-registry is probably the way forward.

However building might not actually be necessary if we can rely on the cached deps pacakge. This package is archetecture independant so once we have them we can just build cargo-local-registry from source. I don't know if there is a policy about relying on the cache for things like this.

@Mic92 Mic92 Aug 10, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can use this one for bootstrapping: #24991
I have not found yet find to the time to inspect it closer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason I prefer this approach is it doesn't require any preprocessing or extra files. It simply reads the Cargo.toml file. I do think that those are fixable but this is also a nice quick improvement on the current state.

@Mic92 Mic92 Aug 11, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But a solution for aarch64 must be found first. If upstream adds support for this architecture as well, I am ok with that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or we could just build our own boostrap binary 🤷‍. Once the bootstrap is in place we can just grab a couple of versions back.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Mic92 As far as i can tell there is currently no support for rust bootstrap for aarch64 either? There are aarch64 builds available on the official rust installer page. Adding a binaries for aarch64 to upstream cargo-local-registry would be easy tough.

@kevincox I was working on something similar but based on cargo-vendor. Not sure yet which one is better suited but according to the authore (which is the same for both) cargo-vendor is getting more attention at the moment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kevincox I forget to mention that cargo-vendor might be easier to bootstrap soon as it will soon have a tarball with vendored dependencies available. See: alexcrichton/cargo-vendor#51

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So I'm not an expert on the differences but it seems like cargo-local-registry is designed to "mirror" the required dependencies whereas cargo-vendor is supposed to the upstream project to vendor dependencies themselves. Either will probably work in practice but cargo-local-registry looks like a better fit for our use case.

And it seems like the bootstrapping issue shouldn't be a major concern as cargo can cross-compile easily. Someone just needs to but in some effort to bootstrap the first version.

That being said I'm happy for whatever solution works.

@ckauhaus

Copy link
Copy Markdown
Contributor

Might solve #23282

@kevincox

Copy link
Copy Markdown
Contributor Author

@ckauhaus It would, added to the description.

@ckauhaus

Copy link
Copy Markdown
Contributor

In its current form, this PR breaks all existing Rust packages in an unobvious way. Due to the transition from registry.index to local-registry, the required format of the deps derivation has changed. This means we need new depsSha256 checksums everywhere.

I'd personally prefer to rename this attribute (e.g., cargoDepsSha256) so that old Rust builds print a clear error message.

@bachp bachp mentioned this pull request Oct 9, 2017
2 of 17 tasks
@zimbatm

zimbatm commented Oct 9, 2017 •

Copy link
Copy Markdown
Member

Merged this into #30088

@kevincox

Copy link
Copy Markdown
Contributor Author

Thanks @zimbatm. I'll follow that change. For now I'll leave this open but it can basically be considered dead and I'll close it one #30088 gets merged.

@gleber

gleber commented Nov 18, 2017

Copy link
Copy Markdown
Contributor

@kevincox #30088 has been merged, please close this PR.

@kevincox kevincox closed this Nov 18, 2017
@kevincox
kevincox deleted the cargo-live branch September 20, 2023 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.kind: enhancement Add something new or improve an existing system. 6.topic: developer experience nixpkgs development workflow 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 6.topic: user experience NixOS / Nixpkgs end user experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants