Skip to content

cargo: Embed resolved manifest in generated sources#349

Merged
gasinvein merged 3 commits into
flatpak:masterfrom
gasinvein:cargo-inherit-workspace
Mar 28, 2023
Merged

cargo: Embed resolved manifest in generated sources#349
gasinvein merged 3 commits into
flatpak:masterfrom
gasinvein:cargo-inherit-workspace

Conversation

@gasinvein

Copy link
Copy Markdown
Contributor

Cargo with inherit-workspace feature requires workspace packages Cargo.toml's to be resolved when using vendored sources, because the workspace manifest won't be available when building them.
Fixes #348
See also rust-lang/cargo#11414

@gasinvein

gasinvein commented Feb 15, 2023

Copy link
Copy Markdown
Contributor Author

@tim77 @sebastian-de @muelli Can you please test this patched cargo generator with the apps you maintain (Veloren, Lapce and Delta Chat respectively (these three are known to be the most complex rust apps on Flathub and heavily use packages from git))?
This PR aims to ensure that the generator will continue to work when Cargo's inherit-workspace feature becomes more widespread (it's not in a stable release yet), but I want to be 100% sure it doesn't break existing apps.

@gasinvein gasinvein changed the title cargo: Embed resolved manifest cargo: Embed resolved manifest in generated sources Feb 15, 2023
@sebastian-de

Copy link
Copy Markdown

Hi @gasinvein, thanks for reaching out.
I did a quick test with https://raw.githubusercontent.com/lapce/lapce/master/Cargo.lock which yields:

[...]
INFO:root:Loading packages from https://github.com/lapce/wasi-experimental-http
DEBUG:root:Loading dependency wasi-experimental-http from crates/wasi-experimental-http
DEBUG:root:Loading dependency wasi-experimental-http-wasmtime from crates/wasi-experimental-http-wasmtime
DEBUG:root:Loading workspace member ./crates/wasi-experimental-http/Cargo.toml in /home/sepp/.cache/flatpak-cargo/https_github.com_lapce_wasi-experimental-http
DEBUG:root:Loading workspace member ./crates/wasi-experimental-http-wasmtime/Cargo.toml in /home/sepp/.cache/flatpak-cargo/https_github.com_lapce_wasi-experimental-http
DEBUG:root:Loading workspace member ./tests/rust/Cargo.toml in /home/sepp/.cache/flatpak-cargo/https_github.com_lapce_wasi-experimental-http
DEBUG:root:Packages in https://github.com/lapce/wasi-experimental-http:
{
    "wasi-experimental-http": "crates/wasi-experimental-http",
    "wasi-experimental-http-wasmtime": "crates/wasi-experimental-http-wasmtime",
    "wasi-experimental-http-wasmtime-sample": ".",
    "simple-wasi-http-tests": "tests/rust"
}
INFO:root:Adding package wasi-experimental-http-wasmtime from https://github.com/lapce/wasi-experimental-http
Traceback (most recent call last):
  File "/home/sepp/src/flatpack-cargo-generator-test/./flatpak-cargo-generator.py", line 446, in <module>
    main()
  File "/home/sepp/src/flatpack-cargo-generator-test/./flatpak-cargo-generator.py", line 439, in main
    generated_sources = asyncio.run(generate_sources(load_toml(args.cargo_lock),
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/sepp/src/flatpack-cargo-generator-test/./flatpak-cargo-generator.py", line 393, in generate_sources
    for pkg in await asyncio.gather(*pkg_coros):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sepp/src/flatpack-cargo-generator-test/./flatpak-cargo-generator.py", line 343, in get_package_sources
    return await get_git_package_sources(package, git_repos)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sepp/src/flatpack-cargo-generator-test/./flatpak-cargo-generator.py", line 313, in get_git_package_sources
    'contents': toml.dumps(git_pkg.normalized),
                           ^^^^^^^^^^^^^^^^^^
  File "/home/sepp/src/flatpack-cargo-generator-test/./flatpak-cargo-generator.py", line 131, in normalized
    for key, value in section.items():
                      ^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'items'

This is probably because https://github.com/lapce/wasi-experimental-http uses a subdirectory called crates, but I didn't have a look at your code, yet.

@gasinvein gasinvein force-pushed the cargo-inherit-workspace branch from d684bd7 to 5fe210a Compare February 15, 2023 12:56
@gasinvein

Copy link
Copy Markdown
Contributor Author

@sebastian-de Thanks for the feedback. I've updated the PR (force-pushed), can you try again with these changes, please?

Cargo with `inherit-workspace` feature requires workspace packages
Cargo.toml's to be resolved when using vendored sources, because
the workspace manifest won't be available when building them.
@gasinvein gasinvein force-pushed the cargo-inherit-workspace branch from 5fe210a to c27b0cc Compare February 15, 2023 12:58
@sebastian-de

Copy link
Copy Markdown

@gasinvein with your latest change the script runs fine and generates valid sources. I also did a test build of the Lapce Flatpak with the new script - works!

@muelli

muelli commented Mar 28, 2023

Copy link
Copy Markdown
Member

@muelli Can you please test this patched cargo generator with the apps you maintain

seems to work for delta chat :)

@gasinvein

Copy link
Copy Markdown
Contributor Author

Ok, thanks, then I believe it should be good to go.

@gasinvein gasinvein merged commit de81f43 into flatpak:master Mar 28, 2023
@gasinvein gasinvein deleted the cargo-inherit-workspace branch March 28, 2023 15:12
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.

cargo generator doesn't include .workspace versions

3 participants