Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo: Embed resolved manifest in generated sources #349

Merged
merged 3 commits into from
Mar 28, 2023

Conversation

gasinvein
Copy link
Member

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
Copy link
Member Author

gasinvein commented Feb 15, 2023

@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

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
Copy link
Member 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.
@sebastian-de
Copy link

@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
Copy link
Member

muelli commented Mar 28, 2023

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

seems to work for delta chat :)

@gasinvein
Copy link
Member 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