You can check out `cargo2port` ( https://ports.macports.org/port/cargo2port/ ), and I have a similar utility here: https://github.com/herbygillot/cargo2ports
On Thu, Nov 30, 2023 at 2:07 PM Austin Ziegler <halosta...@gmail.com> wrote: > I was opening a new PR to update a Rust dependency today and could not > figure out how to update the `cargo.crates` section. Digging through the > cargo-fetch portgroup pointed me to > https://github.com/macports/macports-contrib/tree/master/cargo2port/cargo2port.tcl, > which fails to run because the Cargo.lock format appears not to be the same > as it was when written. > > Using toml2json (from the Python remarshal package) and jq, I managed to > make a simple bash function that does the same thing, more or less. It > *always* prints using the max name / version lengths and it requires that > `Cargo.lock` be in the current directory, but these are small prices to > pay. This may also be simplified if you have > https://github.com/simonrupf/convert2json installed, where I believe you > could simply use `tq` (this is not currently available as a port; adding > one won't be hard, but feature selection will be tricky because it attempts > to install a `yq` binary by default, making it conflict with the yq port). > > cargo2port() { > toml2json Cargo.lock | jq -r $' > def lpad($len; $fill): tostring | ($len - length) as $l | ($fill * > $l)[:$l] + .; > def lpad($len): lpad($len; " "); > def rpad($len; $fill): tostring | ($len - length) as $l | . + ($fill * > $l)[:$l]; > def rpad($len): rpad($len; " "); > .package | > map(select(.checksum != null)) | > (. | max_by(.name | length) | .name | length) as $max_name | > (. | max_by(.version | length) | .version | length) as $max_version | > map(" \(.name | rpad($max_name)) \(.version | lpad($max_version)) > \(.checksum)") | > join(" \\\\\n") as $body | > "cargo.crates \\\\\n\($body)" > ' > } > > In any case, I hope this helps anyone else who wants to modify a Rust port. > > -a > -- > Austin Ziegler • halosta...@gmail.com • aus...@halostatue.ca > http://www.halostatue.ca/ • http://twitter.com/halostatue >