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

Add version_suffix_components setting #352

Merged
merged 2 commits into from
Nov 12, 2023

Conversation

kpcyrd
Copy link
Contributor

@kpcyrd kpcyrd commented Nov 11, 2023

Related to #345 (this patch is based on my comment there) and rustls/rustls-ffi/pull/274.

This adds a setting to disable automatic semver SONAMEs and to pick an arbitrary number of components from the version string for the SONAME.

This feature allows two additional use-cases for library developers to pick from:

.so.0, .so.1, .so.2, ...

For a C-style breaking-change counter use a config like this:

[package.metadata.capi.library]
name = "imagequant"
version = "0.0.0"
version_suffix_components = 1

Increase the major version for every time the ABI is broken:

[package.metadata.capi.library]
name = "imagequant"
version = "1.0.0"
version_suffix_components = 1

This pattern is already supported, but one has to start at .so.1 because it's currently not possible to configure .so.0.

Doing this does not interfer with pkg-config metadata:

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: imagequant
Description: Convert 24/32-bit images to 8-bit palette with alpha channel.
Version: 4.0.4
Libs: -L${libdir} -limagequant
Cflags: -I${includedir}
Libs.private:  -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc

Opt-out of a stable ABI

To read the version from [package.version] but opt-out of a stable ABI:

[package.metadata.capi.library]
name = "rustls"
version_suffix_components = 3
rustflags = "-Cmetadata=rustls-ffi"

"Why not do static linking at this point?" - doing it like this has 3 effects:

  • Binary code is available from a single shared object in the dynamic linking ecosystem and does not need to be duplicated into every consuming executable
  • Binary code can be centrally security patched by downstream instead of having to replace embedded copies in every consuming executable
  • For every new upstream release, all consuming executables need to be rebuilt because the SONAME is always going to change, intentionally preventing the new binary code to be loaded by an executable that assumes the ABI of a previous version

Another way of opting out of a stable ABI is "use 0.1.0 and only ever bump the minor version". cargo-c default settings would then make sure every release is in it's own libfoo.so.0.1, libfoo.so.0.2 SONAME namespace, until comfortable with making ABI compatible 0.X.{patch} releases that still provide the first two effects, but do not require a rebuild of consuming executables.


I originally named this setting suffix_components but I'm indecisive which name is better.

As far as I can tell this is the last feature needed to close #345 as completed.

cc: @lu-zero @cpu @kornelski @kyrias

@kyrias
Copy link

kyrias commented Nov 11, 2023

Haven't looked at the code, but the specification in the description sounds great. 👍

src/build.rs Outdated
Some(1) => format!("{major}"),
Some(2) => format!("{major}.{minor}"),
Some(3) => format!("{major}.{minor}.{patch}"),
Some(num) => anyhow::bail!("Unexpected number of suffix components: {num}"),
Copy link
Owner

Choose a reason for hiding this comment

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

If you want to go the extra mile, you should put the validation when parsing the value instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done!

Copy link
Owner

@lu-zero lu-zero left a comment

Choose a reason for hiding this comment

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

Overall it looks good, there is only a nit I'd like to have addressed, if you do not have time I can do that myself later though.

Thank you a lot for the patch :)

Copy link
Owner

@lu-zero lu-zero left a comment

Choose a reason for hiding this comment

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

Thank you a lot!

@lu-zero lu-zero merged commit dcc2df6 into lu-zero:master Nov 12, 2023
14 checks passed
@kpcyrd kpcyrd deleted the version-suffix-components branch November 12, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More granular SONAME versioning
3 participants