-
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
Building diesel fails using resolver = "2"
#9450
Comments
I'm using diesel from the |
@toxeus Can you add some information which commit you used before the bump. The linked commit cannot be related to this, as it does not change any code that is related to this issue. |
@weiznich sure! It was diesel-rs/diesel@426b813. So there are about 300 commits to bisect through 😅 |
Git bisect points to diesel-rs/diesel@35d68ba. As another observation: This problem does only happen if First a truncated dependency tree, to show the original dependencies for the 1.4.x release series:
As you can see |
As you guessed I don't understand the details of the dependencies of the involved crates, but if |
@Eh2406 That would all be fine if diesel actually had the option to opt into this feature (which we cannot simply do because we want to support a minimal rust version that is older than this feature). Our problem here is that any downstream crate can request to use the new If I understand #8088 correctly it is even worse by making this the default in the 2021 edition. This essentially breaks the promise bound to editions: You cannot use the edition of your choice anymore as a newer edition requires you to update code in a old edition. That all written: I totally understand the motivation behind this feature, but the current implementation is just not up to the standards described in RFC-1122 Other than that: As the old behaviour work, but the new one doesn't: What's the canonical way to make code generation in a proc macro depended on some feature flag and use the crate containing the generated code, both on host and target side? |
I'm sorry you're having a frustrating experience with this. Unfortunately it is not possible for individual dependencies to use different resolver behavior, as the unification process is global across the crate graph. For diesel, it looks like something like the following should allow it to work the same on both 1 and 2 resolvers: diff --git a/diesel_migrations/Cargo.toml b/diesel_migrations/Cargo.toml
index 3c08a4c23..f026a258f 100644
--- a/diesel_migrations/Cargo.toml
+++ b/diesel_migrations/Cargo.toml
@@ -19,6 +19,6 @@ cfg-if = "0.1.0"
[features]
default = []
-sqlite = []
-postgres = []
-mysql = []
+sqlite = ["migrations_macros/sqlite"]
+postgres = ["migrations_macros/postgres"]
+mysql = ["migrations_macros/mysql"]
diff --git a/diesel_migrations/migrations_internals/Cargo.toml b/diesel_migrations/migrations_internals/Cargo.toml
index b85aeda0f..5342017a1 100644
--- a/diesel_migrations/migrations_internals/Cargo.toml
+++ b/diesel_migrations/migrations_internals/Cargo.toml
@@ -15,3 +15,6 @@ tempdir = "0.3.4"
[features]
default = []
+sqlite = ["diesel/sqlite"]
+postgres = ["diesel/postgres"]
+mysql = ["diesel/mysql"]
diff --git a/diesel_migrations/migrations_macros/Cargo.toml b/diesel_migrations/migrations_macros/Cargo.toml
index 8141bf665..9cb94aa8c 100644
--- a/diesel_migrations/migrations_macros/Cargo.toml
+++ b/diesel_migrations/migrations_macros/Cargo.toml
@@ -20,3 +20,6 @@ proc-macro = true
[features]
default = []
+sqlite = ["migrations_internals/sqlite"]
+postgres = ["migrations_internals/postgres"]
+mysql = ["migrations_internals/mysql"] Essentially, I realize this is difficult to diagnose and fix, and is more work than before. I'll think about what kind of tooling would be possible to help the process better. During this, I did recognize that there is a bug in |
@ehuss Thanks for the suggestion how to fix this, it's nice to see that is possible to fix this issue on our side, but I believe that this should not have happened at all in that way.
Just to clarify that: Adding a new feature which needs to be correctly set to make a crate build does require a breaking change in the corresponding crate. This may not be possible/wanted due to multiple reasons. Essentially this is just moving the burden for this breaking change/major version bump from On top of that using the suggested fix will result in a degraded usability of our crate, as user now need to pass a matching set of feature flags to two different crates. (For diesel_migrations the real fix is to remove the built time dependency on diesel, as this essentially was not needed, but that will likely not be possible for other's with similar problems)
That's exactly the point why I believe that this is essentially a breaking change. For some reasons (like usability, backward compatibility, …) it may not possible to support both the behaviour of the new and the old resolver in the same crate. All other features I'm aware of that where introduced via a new key in a
Having better tooling here is definitively not wrong, but this does not solve the non-locality problem of this feature. I also totally understand why this feature was implemented and how it solves the targeted problem. I just want to raise my concerns that this feature, as it is currently implemented breaks, at least as far as I can tell, the rules specified by RFC-1122, by breaking unrelated third party code. If you don't think that's the case I would be curios to hear the reasoning here. It would likely already help if cargo would emit bold warning if it hits an error in some dependency crate, that does not explicitly opt into this feature but that is built with |
The time line for this feature is still being discussed, leaving it a separate option in 2021 is definitely being considered. How pane full it is for libraries to more accurately describe there features is definitely a concerned. So thank you for the feedback. There are lots of users that have no way to build there projects with the existing behavior. Furthermore if a root crate wants to set |
Thanks for that response 👍 I believe something actionable here would be to improve the messages emitted by cargo/rustc on potential errors. At least for the diesel case it would already really help if cargo could point out that there is a difference between using the old and the new resolver. Maybe additionally a hint about setting a dev-dependency with the required feature flags could be edited? To prevent this from showing up as false positive this work could be done only if there was an error in some dependency crate. |
As this feature is now included in the official blog post about the 2021 edition I decided to open a thread in the internals forum about this issue. I must say that I'm a bit confused as the statements made by @Eh2406 are quite contrary to that written in the blog post. I mean in the end this boils down to "let's break that use case in favor of another use case". I hoped that we had left that point of language design behind us with the release of rust 1.0, but it seems like this is not the case. I believe it's fine to break things, but that would imply that rust's stability guarantee is not valid anymore. I cannot see that this was decided by the rust core team via any RFC anywhere. Generally I'm disappointed on the communication around this feature. To address a few other comments made here in that thread:
I cannot see how this is a justification for this change. I mean there are many things that are not possible due to language restrictions and at least for some of them fixing them would require a breaking change. There are quite a few examples in rust already where it is not possible to improve a specific feature due to language stability constraints. (See for example the discussion around unwinding through ffi boundaries or the design of
I likely would react differently to this if cargo would emit a notice that adding diesel with specific features as dev-dependency would fix that problem, as this would make it clear that this is caused by setting |
To be fair, it's not a change in the language but to the build-system. I'm unaware that the build-system is also covered by rust's stability guarantee.
I agree that this is highly desirable but I also can understand that it's plausible that lack of such a diagnostic, for a complex setup as |
@toxeus Cargo is covered by Rust's stability guarantee. This is absolutely a breaking change, but that's why it's 1) opt-in, and 2) not being done by default until a new edition. That's how we normally handle changes that would otherwise be breaking. We absolutely appreciate that because the new resolver applies to entire dependency trees, the migration story isn't as simple as that. That's part of what makes things like this even more difficult for Cargo than for Rust. Even changes to |
@joshtriplett thanks for the clarification! |
Change diesel compatibility messages Diesel 1.4.8 fixes the critical behaviour. This commit changes the corresponding messages for `cargo fix` and normal builds to prompt the user to just update the diesel version to fix the corresponding compilation errors. As discussed in rust-lang/rust#88903 (comment) Fixes rust-lang/rust#88903 Fixes rust-lang#9450
Problem
Building diesel with
resolver = "2"
enabled fails, while builds using the old resolver succeed. It's unclear from the documentation if something in diesel needs to be changed or if this is a bug in the new resolver. See diesel-rs/diesel#2753 for the initial report.I believe that this is an issue in cargo rather than in diesel for the following reason:
Building with
resolver = "2"
issues the following rustc invocation:which misses all specified and default features for diesel.
Building without
resolver = "2"
issues the following rustc invocation:which contains the specified feature flags.
Steps
cargo check
Notes
Output of
cargo version
:The text was updated successfully, but these errors were encountered: