Bug 273280 - Mk/Uses/cargo.mk: Invalid ${WRKDIR}/.cargo/config.toml is generated
Summary: Mk/Uses/cargo.mk: Invalid ${WRKDIR}/.cargo/config.toml is generated
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Ports Framework (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: FreeBSD Rust Team
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-22 06:49 UTC by Yuri Victorovich
Modified: 2023-10-09 14:38 UTC (History)
2 users (show)

See Also:


Attachments
Makefile (14.93 KB, text/plain)
2023-08-22 06:49 UTC, Yuri Victorovich
no flags Details
v0 (931 bytes, patch)
2023-09-26 13:30 UTC, Mikael Urankar
no flags Details | Diff
v1 (1.52 KB, patch)
2023-10-05 10:39 UTC, Mikael Urankar
tobik: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2023-08-22 06:49:16 UTC
Created attachment 244277 [details]
Makefile

The build fails with the attached Makefile that has CARGO_CRATES generated with 'make cargo-crates':
> ===>   Updating Cargo.lock
> error: failed to load manifest for workspace member `/usr/ports/security/solana/work/solana-1.16.9/account-decoder`
> 
> Caused by:
>   failed to parse manifest at `/usr/ports/security/solana/work/solana-1.16.9/account-decoder/Cargo.toml`
> 
> Caused by:
>   could not load Cargo configuration
> 
> Caused by:
>   could not parse TOML configuration in `/usr/ports/security/solana/work/.cargo/config.toml`
> 
> Caused by:
>   could not parse input as TOML
> 
> Caused by:
>   TOML parse error at line 8, column 1
>     |
>   8 | ntapi = { path = '/usr/ports/security/solana/work/ntapi-97ede981a1777883ff86d142b75024b023f04fad' }
>     | ^
>   duplicate key `ntapi` in table `patch.crates-io`
> *** Error code 101


Additionally, after the duplicate is removed, the build fails again due to missing dependencies:
> ===>   Updating Cargo.lock
> error: no matching package found
> searched package name: `ntapi`
> perhaps you meant:      caps, clap, hidapi, ...
> location searched: registry `crates-io`
> required by package `mio v0.7.14`
>     ... which satisfies dependency `mio = "^0.7.6"` of package `tokio v1.14.1`
>     ... which satisfies dependency `tokio = "^1.13.0"` of package `quinn v0.9.4`
>     ... which satisfies dependency `quinn = "^0.9.4"` of package `solana-client v1.16.9 (/usr/ports/security/solana/work/solana-1.16.9/client)`
>     ... which satisfies path dependency `solana-client` of package `solana-accounts-cluster-bench v1.16.9 (/usr/ports/security/solana/work/solana-1.16.9/accounts-cluster-bench)`
> *** Error code 101


rust-1.71.0
FreeBSD 13.2
Comment 1 Mikael Urankar freebsd_committer freebsd_triage 2023-09-26 13:29:40 UTC
(In reply to Yuri Victorovich from comment #0)
This problem arise if there are multiple Cargo.toml containing the same crates in the [patch.crates-io] section, example with libsignal 0.31.0:

cat work/libsignal-0.31.0/rust/protocol/fuzz/Cargo.toml
[patch.crates-io]
# Use our fork of curve25519-dalek for zkgroup support.
curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.0.0' }
x25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.0.0' }

cat work/libsignal-0.31.0/Cargo.toml
[patch.crates-io]
# Use our fork of curve25519-dalek for zkgroup support.
curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.0.0' }
x25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.0.0' }
boring = { git = 'https://github.com/signalapp/boring', branch = 'libsignal' }
# This revision of snow is where curve25519-dalek v4.0.0 changes were merged in
snow = { git = 'https://github.com/mcginty/snow.git', rev = '586292364a30ecc74c785228b41e60b3ef03e773' }

So x25519-dalek and curve25519-dalek appears twice in work/.cargo/config.toml

Removing the duplicate in work/.cargo/config.toml won't work as the various awk scripts remove the [patch.crates-io] section in cargo.toml, cf https://cgit.freebsd.org/ports/tree/Mk/Scripts/cargo-crates-git-configure.awk?h=2023Q3#n65
So the second run won't put the needed dependency in work/.cargo/config.toml
Comment 2 Mikael Urankar freebsd_committer freebsd_triage 2023-09-26 13:30:54 UTC
Created attachment 245254 [details]
v0

The attached patch is an attempt at fixing the issue. It generates the dependency after parsing all the cargo.toml.
Comment 3 Tobias Kortkamp freebsd_committer freebsd_triage 2023-10-04 12:41:22 UTC
Comment on attachment 245254 [details]
v0

It's probably ok if all ports that have @git+ in CARGO_CRATES (or non-empty _CARGO_GIT_SOURCES) still pass 'make configure' ('make patch cargo-configure' is probably enough as a shortcut).

The "local" variables list (the one after "function add_crates_io_patches(\t") needs to be updated with local_crates and print_header. References to the unused header_printed can be removed.
Comment 4 Mikael Urankar freebsd_committer freebsd_triage 2023-10-05 10:39:45 UTC
Created attachment 245445 [details]
v1
Comment 5 Tobias Kortkamp freebsd_committer freebsd_triage 2023-10-06 14:39:24 UTC
Comment on attachment 245445 [details]
v1

lgtm
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-10-08 16:41:47 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=8fae936cf5a65db050d6b0950a912a4f028e34d8

commit 8fae936cf5a65db050d6b0950a912a4f028e34d8
Author:     Mikael Urankar <mikael@FreeBSD.org>
AuthorDate: 2023-10-08 16:36:11 +0000
Commit:     Mikael Urankar <mikael@FreeBSD.org>
CommitDate: 2023-10-08 16:41:17 +0000

    Mk/Scripts/cargo-crates-git-configure.awk: Generate the patch.crates-io section after parsing all the Cargo.toml files

    If we have multiple Cargo.toml files with the same crates in the
    [patch.crates-io] section we will end up with crates defined mutiple
    times and cargo will refuse to proceed.
    Write this section after parsing all the Cargo.toml files.

    PR:             273280
    Reviewed by:    tobik

 Mk/Scripts/cargo-crates-git-configure.awk | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
Comment 7 Mikael Urankar freebsd_committer freebsd_triage 2023-10-08 16:47:29 UTC
(In reply to Tobias Kortkamp from comment #5)
Thanks for the review.
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-10-09 14:38:16 UTC
A commit in branch 2023Q4 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1e49125934332178017a2508fa182865b47d890f

commit 1e49125934332178017a2508fa182865b47d890f
Author:     Mikael Urankar <mikael@FreeBSD.org>
AuthorDate: 2023-10-08 16:36:11 +0000
Commit:     Mikael Urankar <mikael@FreeBSD.org>
CommitDate: 2023-10-09 14:38:00 +0000

    Mk/Scripts/cargo-crates-git-configure.awk: Generate the patch.crates-io section after parsing all the Cargo.toml files

    If we have multiple Cargo.toml files with the same crates in the
    [patch.crates-io] section we will end up with crates defined mutiple
    times and cargo will refuse to proceed.
    Write this section after parsing all the Cargo.toml files.

    PR:             273280
    Reviewed by:    tobik

    (cherry picked from commit 8fae936cf5a65db050d6b0950a912a4f028e34d8)

 Mk/Scripts/cargo-crates-git-configure.awk | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)