crate: bumping gtk-rs versons is a semver-breaking change
The librsvg crate as published on crates.io (https://crates.io/crates/librsvg) has breaking changes between version 2.56 and 2.57. Some dependencies leak into the public API, for example the cairo crate. This causes problems if versions mismatch between the version of cairo depended on by librsvg and the application, like here:
error[E0308]: arguments to this method are incorrect
--> src/main.rs:115:22
|
115 | .render_document(c, &Rectangle::new(x, y, size, size))
| ^^^^^^^^^^^^^^^ - --------------------------------- expected `cairo::rectangle::Rectangle`, found `Rectangle`
| |
| expected `cairo::context::Context`, found `cairo::Context`
|
= note: `cairo::Context` and `cairo::context::Context` have similar names, but are actually distinct types
note: `cairo::Context` is defined in crate `cairo`
--> /usr/share/cargo/registry/cairo-rs-0.18.2/src/context.rs:64:1
|
64 | pub struct Context(ptr::NonNull<cairo_t>);
| ^^^^^^^^^^^^^^^^^^
note: `cairo::context::Context` is defined in crate `cairo`
--> /usr/share/cargo/registry/cairo-rs-0.17.10/src/context.rs:64:1
|
64 | pub struct Context(ptr::NonNull<cairo_t>);
| ^^^^^^^^^^^^^^^^^^
= note: perhaps two different versions of crate `cairo` are being used?
= note: `Rectangle` and `cairo::rectangle::Rectangle` have similar names, but are actually distinct types
note: `Rectangle` is defined in crate `cairo`
--> /usr/share/cargo/registry/cairo-rs-0.18.2/src/rectangle.rs:13:1
|
13 | pub struct Rectangle(ffi::cairo_rectangle_t);
| ^^^^^^^^^^^^^^^^^^^^
note: `cairo::rectangle::Rectangle` is defined in crate `cairo`
--> /usr/share/cargo/registry/cairo-rs-0.17.10/src/rectangle.rs:13:1
|
13 | pub struct Rectangle(ffi::cairo_rectangle_t);
| ^^^^^^^^^^^^^^^^^^^^
= note: perhaps two different versions of crate `cairo` are being used?
note: method defined here
--> /usr/share/cargo/registry/librsvg-2.56.0/src/api.rs:462:12
|
462 | pub fn render_document(
| ^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `tiny-dfr` (bin "tiny-dfr") due to previous error
(this is from the build log of tiny-dfr on Fedora 38)
Bumping dependencies that are part of the public API to SemVer-incompatible version (i.e. bumping gtk-rs dependencies from v0.17 to v0.18 as is the case here) is in itself a SemVer-breaking change, and as such, 2.57 technically should have been released as 3.0.0 to satisfy the API stability requirements of the cargo / crates ecosystem.
I understand that this is not in line with the more "GNOME style" versioning that librsvg uses (the C library also exports a stable API / ABI, as far as I can tell), but it also causes problems for applications that use the librsvg crate, which does not export a stable API.
I'm not sure what would be the best solution here - for now, I see two ways forward:
- bump major version of librsvg for every breaking gtk-rs release (maybe something like version 256.y.z -> version 257.0.0, to match the C library version scheme)
- avoid using symbols from gtk-rs in the public API (maybe by using "gtk-rs-version-agnostic" wrapper types that are implemented in librsvg itself)