-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support non-crates.io registries #3917
Comments
Wouldn't the simplest thing be to just allow the user to override |
The use case of This is also a feature where you don't want to override crates.io as crates may still depend on crates from crates.io. This is specifically targeted at situations such as private registries inside companies and such. |
I was thinking of |
Sounds reasonable to me! |
How would we set which crates instance to publish to? It would be a nightmare situation for me to accidentally publish company IP to the wrong instance. |
A good question! That's probably part of the design to consider :) (also a strong case for encoding it in cargo.toml) |
I can see this as covering three highly related features that would be useful individually, or in combination, for different use cases.
1 could be imagined as being similar to the current 2 would be just for what @stusmall mentioned, setting the registry to which 1 and 2 together I imagine would be mostly useful for smaller organisations, or small teams that are introducing Rust into a larger organisation, as it would allow them to standup a small internal registry for their private libraries while still pulling the majority from crates.io. 3 would allow a more restrictive organisation to force all third-party packages through a local mirror so they can do things like validate licenses; or – for a more optimistic reading – allow a network limited organisation to have a simple local caching mirror. This would probably make sense to be specified in |
There's a bunch of different use cases that I've been thinking about, some of this overlaps with what others have already said:
The relevant prior art that I'm familiar with is Ruby. I'm not advocating that we do exactly what Ruby does, because Ruby has their own historical reasons for doing what they do, but this is one way that this whole process works :) Applications that use gems as dependenciesBundler is Ruby's package manager that's mostly in charge of installing dependencies. Applications that use bundler have a Gemfile for specifying their dependencies written in Ruby. Bundler supports these use cases and differs from cargo in these ways:
Which could be an internal server that all gems should always be installed from instead. You can specify multiple global sources, and they're searched for gems in the source priority order. Or you can specify that certain gems come from certain sources by passing a
Bundler will search for child dependencies of gems coming from sources other than the global source by first looking in the source selected for the parent, but if the dependencies are not found there, it will fall back on global sources using the source priority order If the source URLs need authentication, you can either put them in plaintext in the source URL in the Gemfile, ( Libraries that are published (and may also use dependencies)Publishing gems is managed by rubygems. Bundler can hook into rubygems and manage some of this too, but rubygems predates bundler. Gems that are libraries have a Rubygems has a metadata value
Specifying a dependency in a gemspec file looks like:
Typically, libraries also have a
There's a way to have a library temporarily depend on a library from a custom source, by overriding a gem specified in gemspec with something specified in the Gemfile, where the |
In Maven you have the ability to specify multiple repositories and the username/password for connecting to those repositories. If you give people the ability to setup secured access to a repository you should also consider giving them a way to store the password hashed in a separate file that they can restrict access to for security. One other thing, which isn't directly related to this issue but is worth thinking about, is that currently cargo is just a "flat list" of libraries. This can make it difficult for users to find what they want as they can only look at search results. Many other formats provide additional ways to scope things. NPM for example now includes a scope option, Nuget recommends using dot-separated names as a scope and maven uses group id, name and version. This becomes especially useful in large organizations where different teams might have different scopes. I can already see some crates that would benefit from some organization such as the piston libraries. |
You mean crates.io, right?
I think rust-lang/crates.io#409 is the issue you're looking for. It's implemented for users right now but not organizations yet, so right now you can go to, for example, https://crates.io/users/carols10cents to see all the crates I've published. Once it's implemented for organizations, you'll be able to see all the crates that the piston team has published. |
Maybe I'm wrong, but it looks to me like that assumes the crate is coming from github which will not be the case for large organizations using cargo with a repository manager. |
What assumes the crate is coming from github? Ah, are you talking about how right now crates.io only allows authentication with a github account? Which is somewhat related to this, but more on the crates.io side, not cargo. |
Nevermind, I guess I misunderstood the code changes. |
Doing some more research, npm Enterprise is the same codebase as npmjs.com and supports a variety of configurations so that one instance can be both a proxy cache and a private registry host. The npm CLI can then be configured to either support installing ALL packages from a private registry or to only install private packages from the private registry and continue to use npmjs.com for public packages. Installing all packages from the private registry is done by setting the private registry as the default registry that the npm CLI looks in. For only installing private packages from the private registry, you log in with a registry and a scope, which tells the npm CLI to look in that registry for packages in that scope, and also that all packages in that scope should be published to that registry:
This creates a token that gets stored in an
Rather than having HTTP Basic Auth in urls like Rubygems, everything with npm looks token based. So you can generate a token for travis and store that in an env var, for example. Notable is that each time on each machine that you run The npm CLI treats scoped packages as private by default, so you cannot accidentally publish a scoped package to the public registry unless you have access to that scope in the public registry. The npm CLI has a bunch of relevant options, such as |
#3365 is related to this, potentially. |
From twitter: npm is now agnostic about which registry you used to generate the package-lock.json: |
I'd like to describe how the code is managed in the company I work for, so we could find a solution to cover our use case. We have global git server which serves repositories. There is a special repository for shared code that is visible to everyone. If someone pushes a breaking change, all builds break. (No semver :( ) I guess having a special server like crates.io wouldn't be possible. I'd love to have benefits of semver and cargo using our repository directly. What I envision is that when I do breaking change and bump the version, no compilation would break and then I could update projects to new APIs when appropriate. Also, I should mention that I use crates from crates.io too and I need local registry too. Anyone has different problems or see some obvious solution how to approach this? |
Closing this because rust-lang/rfcs#2141 has been accepted and there's now a tracking issue at rust-lang/rust#44931, which replaces this issue. |
I thought we had an issue for this already, but apparently not! This is intended to help track Cargo's support for custom registries, or registries other than crates.io. Note that this is distinct from mirrors which are intended to be implemented with source replacement.
Some features I think we'll need to support are:
Cargo.toml
.I don't have many thoughts about concrete syntax and such right now. We'll also need a server to actually support this (crates.io as-is isn't quite suitable). There's not a crates.io issue for this currently, but as the requirements here evolve over time I figure we can create one that's more targeted.
The text was updated successfully, but these errors were encountered: