Extract/validate packaging tool versions at compile time #241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We store the versions of the packaging tools used by the buildpack (such as pip, setuptools and wheel) in requirements files in the repo, so that Dependabot can update them.
Whilst we can easily include the contents of those files at compile time using
include_str!
, the buildpack actually needs the version substring rather than the whole requirement specifier (the1.2.3
fromfoo==1.2.3
).Until now the extraction/validation of this version substring has been performed at runtime, which required using
.expect()
to ignore the "technically fallible but never going to fail for users in practice" result.Now, we use a
const fn
so this extraction/validation can be performed at compile time, allowing us to define these pinned versions as actualconst
s. In addition to compile time checks being preferable to those at runtime, this change will allow us to simplify/remove thePackagingToolVersions
struct in future PRs in favour of referencing Rust constants.The features we can use in
const fn
s are limited - we can't use:str
, includingsplit
Option
orResult
, includingexpect
orunwrap*
As such, we convert to bytes and use a while/match pattern to iterate through the string - similar to some of the Rust stdlib
const fn
implementations:https://github.com/rust-lang/rust/blob/6a2cd0d50c9b7e1243d948641758c76d1f22e25e/library/core/src/slice/ascii.rs#L127-L139
The minimum Rust version has also been bumped, since
str::trim_ascii
only became aconst fn
in Rust 1.80.GUS-W-16436670.