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

No way to [patch] out multiple versions of a crate #6169

Closed
erickt opened this issue Oct 12, 2018 · 6 comments · Fixed by #7263
Closed

No way to [patch] out multiple versions of a crate #6169

erickt opened this issue Oct 12, 2018 · 6 comments · Fixed by #7263
Labels
A-patch Area: [patch] table override C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@erickt
Copy link
Contributor

erickt commented Oct 12, 2018

Fuchsia is using cargo-vendor to collect our dependencies, and we're using [patch] to remove a few indirect dependencies that we know we don't need, like winapi (see here). Unfortunately, because our dependency graph is a little large, it turns out our graph depends on both winapi 0.2.8 and 0.3.6, but [patch] only allows us to only patch out one version. It would be great if we could do this for all versions.

@est31
Copy link
Member

est31 commented Oct 13, 2018

I've pointed this out back in the RFC's thread and it got a positive response by @alexcrichton but I can't recall it being picked up in the RFC's text afterwards. It seems to have gotten lost somewhere in the process :). Partly my fault for not pointing it out when I read the RFC's text.

@alexcrichton alexcrichton added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` A-patch Area: [patch] table override labels Oct 15, 2018
@aep
Copy link

aep commented Oct 19, 2018

@erickt generally patching dependencies for portability is pretty difficult with cargo right now (i mostly port stuff to embedded targets, which means can easily span half the dependency graph).

Is that something you'd be interested in fixing? possibly outside of cargo, since that seems a little burdened with feature requests already.

i'm thinking of a thing that does a generell "replace crate a with crate b" unchecked

@alexcrichton
Copy link
Member

A strawman of supporting this would possibly look like:

[patch.crates-io]
my-crate = { git = 'https://github.com/myuser/my-crate', branch = 'v1' }
my-crate2 = { git = 'https://github.com/myuser/my-crate', branch = 'v2', package = 'my-crate' }

... or ...

[patch.crates-io]
my-crate = [
    { git = 'https://github.com/myuser/my-crate', branch = 'v1' },
    { git = 'https://github.com/myuser/my-crate', branch = 'v2' },
]

@Hoverbear
Copy link

At the moment this is blocking TiKV from adopting [patch]. :(

@alexcrichton
Copy link
Member

Sat down to write a patch and turns out this already works!

#[cargo_test]                                                                                           
fn multipatch() {                                                                                       
    Package::new("a", "1.0.0").publish();                                                               
    Package::new("a", "2.0.0").publish();                                                               
    let p = project()                                                                                   
        .file(                                                                                          
            "Cargo.toml",                                                                               
            r#"                                                                                         
                [package]                                                                               
                name = "foo"                                                                            
                version = "0.0.1"                                                                       
                                                                                                        
                [dependencies]                                                                          
                a1 = { version = "1", package = "a" }                                                   
                a2 = { version = "2", package = "a" }                                                   
                                                                                                        
                [patch.crates-io]                                                                       
                b1 = { path = "a1", package = "a" }                                                     
                b2 = { path = "a2", package = "a" }                                                     
            "#,                                                                                         
        )                                                                                               
        .file("src/lib.rs", "pub fn foo() { a1::f1(); a2::f2(); }")                                     
        .file(                                                                                          
            "a1/Cargo.toml",                                                                            
            r#"                                                                                         
                [package]                                                                               
                name = "a"                                                                              
                version = "1.0.0"                                                                       
            "#,                                                                                         
        )                                                                                               
        .file("a1/src/lib.rs", "pub fn f1() {}")                                                        
        .file(                                                                                          
            "a2/Cargo.toml",                                                                            
            r#"                                                                                         
                [package]                                                                               
                name = "a"                                                                              
                version = "2.0.0"                                                                       
            "#,                                                                                         
        )                                                                                               
        .file("a2/src/lib.rs", "pub fn f2() {}")                                                        
        .build();                                                                                       
                                                                                                        
    p.cargo("build").run();                                                                             
}                                                                                                            

bors added a commit that referenced this issue Aug 27, 2019
Document that `package` can be used in `[patch]`

This works to `[patch]` multiple versions of a crate, and turns out this
has worked since the inception of `package`!

Closes #6169
@bors bors closed this as completed in 2a391a7 Aug 27, 2019
@jonhoo
Copy link
Contributor

jonhoo commented Jun 20, 2020

I know there is now a well-defined workaround, but is there merit to the idea of [patch] also using a package specifier rather than just a name? So that you could write

[patch.crates-io]
'my-crate:1' = { git = 'https://github.com/myuser/my-crate', branch = 'v1' }
'my-crate:2' = { git = 'https://github.com/myuser/my-crate', branch = 'v2' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patch Area: [patch] table override C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants