• [gentoo-dev] [PATCH 4/5] cargo.eclass: Support separating crate names/v

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Fri Jun 16 14:10:01 2023
    Support specifying crate names and versions separated by forward slashes
    rather than hyphens. Since slashes are not valid in crate names, this
    makes splitting the tokens trivial and free of regular expressions. Effectively, the slash variant is roughly 180% faster:

    ```
    * CRATES with slashes
    real 952 it/s
    user 952 it/s
    * CRATES with hyphens
    real 339 it/s
    user 339 it/s
    ```

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/cargo.eclass | 24 +++++---
    eclass/tests/cargo-bench.sh | 111 +++++++++++++++++++-----------------
    2 files changed, 75 insertions(+), 60 deletions(-)

    diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
    index d97bb0df9348..54a1edd36c28 100644
    --- a/eclass/cargo.eclass
    +++ b/eclass/cargo.eclass
    @@ -59,12 +59,16 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
    # Bash string containing all crates that are to be downloaded.
    # It is used by cargo_crate_uris.
    #
    +# Ideally, crate names and versions should be separated by a forward
    +# slash. A legacy syntax using hyphen is also supported but it is much
    +# slower.
    +#
    # Example:
    # @CODE
    # CRATES="
    -# metal-1.2.3
    -# bar-4.5.6
    -# iron_oxide-0.0.1
    +# metal/1.2.3
    +# bar/4.5.6
    +# iron_oxide/0.0.1
    # "
    # inherit cargo
    # ...
    @@ -182,10 +186,16 @@ _cargo_set_crate_uris() {
    CARGO_CRATE_URIS=
    for crate in ${crates}; do
    local name version url
    - [[ $crate =~ $regex ]] || die "Could not parse name and version from c
  • From Denis Lisov@21:1/5 to mgorny@gentoo.org on Fri Jun 16 16:50:02 2023
    Hello Michał,

    On Fri, Jun 16, 2023 at 3:09 PM Michał Górny <mgorny@gentoo.org> wrote:
    Support specifying crate names and versions separated by forward slashes rather than hyphens. Since slashes are not valid in crate names, this
    makes splitting the tokens trivial and free of regular expressions. Effectively, the slash variant is roughly 180% faster:

    As a developer using Rust I want to note that Cargo has a concept of
    "package ID specification"[1] that usually uses pkgname@version
    syntax, but AFAIK there's no prior art for using pkgname/version in
    the ecosystem. Could it make sense to use pkgname@version for
    consistency?

    Regards,
    Denis Lisov.

    [1]: https://doc.rust-lang.org/cargo/reference/pkgid-spec.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?=@21:1/5 to Denis Lisov on Fri Jun 16 18:00:01 2023
    On Fri, 2023-06-16 at 17:48 +0300, Denis Lisov wrote:
    Hello Michał,

    On Fri, Jun 16, 2023 at 3:09 PM Michał Górny <mgorny@gentoo.org> wrote:
    Support specifying crate names and versions separated by forward slashes rather than hyphens. Since slashes are not valid in crate names, this makes splitting the tokens trivial and free of regular expressions. Effectively, the slash variant is roughly 180% faster:

    As a developer using Rust I want to note that Cargo has a concept of
    "package ID specification"[1] that usually uses pkgname@version
    syntax, but AFAIK there's no prior art for using pkgname/version in
    the ecosystem. Could it make sense to use pkgname@version for
    consistency?


    I suppose so. The only reason I've used slash is because that could be
    used directly in URL.

    --
    Best regards,
    Michał Górny

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam James@21:1/5 to mgorny@gentoo.org on Fri Jun 16 20:10:01 2023
    Michał Górny <mgorny@gentoo.org> writes:

    On Fri, 2023-06-16 at 17:48 +0300, Denis Lisov wrote:
    Hello Michał,

    On Fri, Jun 16, 2023 at 3:09 PM Michał Górny <mgorny@gentoo.org> wrote: >> > Support specifying crate names and versions separated by forward slashes >> > rather than hyphens. Since slashes are not valid in crate names, this
    makes splitting the tokens trivial and free of regular expressions.
    Effectively, the slash variant is roughly 180% faster:

    As a developer using Rust I want to note that Cargo has a concept of
    "package ID specification"[1] that usually uses pkgname@version
    syntax, but AFAIK there's no prior art for using pkgname/version in
    the ecosystem. Could it make sense to use pkgname@version for
    consistency?


    I suppose so. The only reason I've used slash is because that could be
    used directly in URL.

    I think we should do it (@ delimiter) - it looks more natural in a Rust/cargo context.

    Thanks for the suggestion!

    --=-=-Content-Type: application/pgp-signature; name="signature.asc"

    -----BEGIN PGP SIGNATURE-----

    iOUEARYKAI0WIQQlpruI3Zt2TGtVQcJzhAn1IN+RkAUCZIyk0F8UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0MjVB NkJCODhERDlCNzY0QzZCNTU0MUMyNzM4NDA5RjUyMERGOTE5MA8cc2FtQGdlbnRv by5vcmcACgkQc4QJ9SDfkZAMhwEA7k5j4cj8erpLdz7bqd2HePkIYL0Tlfzcav57 CpaFV+oA/R0WZRxvV8OC30st3U8jPjER9ZOiIZccAE2Id4pK9KcO
    =lytJ
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)