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

-Zpackage-workspace is not smart about publish = false #14356

Closed
workingjubilee opened this issue Aug 5, 2024 · 15 comments · Fixed by #14408
Closed

-Zpackage-workspace is not smart about publish = false #14356

workingjubilee opened this issue Aug 5, 2024 · 15 comments · Fixed by #14408
Labels
A-unstable Area: nightly unstable support C-bug Category: bug Command-package S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. Z-package-workspace Nightly: package-workspace

Comments

@workingjubilee
Copy link
Member

workingjubilee commented Aug 5, 2024

Problem

I was hoping to include -Zpackage-workspace as part of a workspace's CI so that it doesn't repeat certain embarrassing mistakes, but it didn't work as expected with respect to certain crates that have publish = false on them.

Steps

After bumping the versions of all packages I wished to publish a new release for, I used this on the workspace with the following command:

$ cargo +nightly package --workspace -Zpackage-workspace
     Locking 7 packages to latest compatible versions
    Updating cargo-pgrx v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/cargo-pgrx) -> v0.12.0-beta.4
    Updating pgrx v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx) -> v0.12.0-beta.4
    Updating pgrx-macros v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-macros) -> v0.12.0-beta.4
    Updating pgrx-pg-config v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-pg-config) -> v0.12.0-beta.4
    Updating pgrx-pg-sys v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-pg-sys) -> v0.12.0-beta.4
    Updating pgrx-sql-entity-graph v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-sql-entity-graph) -> v0.12.0-beta.4
    Updating pgrx-tests v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-tests) -> v0.12.0-beta.4
error: `aggregate` cannot be packaged.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.

Possible Solution(s)

This seems a curious error, given that this is intentional? I wish to not publish that crate and thus do not wish to package it for publishing?

Cargo has the option of doing the "smart" thing ("What I mean") here and simply ignoring such packages. The other obvious alternative is that it can simply continue to fail-fast, but if so it should probably have a more helpful error message. Note these are "leaf" packages on which nothing depends, so automatically excluding them would work.

Notes

I do have the option of simply removing it from the workspace, but it all gets a bit awkward. To complicate matters further, these packages being in the workspace does affect feature resolution which also affects whether or not basic cargo check or cargo test work (as the library is one of those "you must enable one and only one of these features" sorts).

Related:

Version

cargo 1.82.0-nightly (b5d44db1d 2024-07-26)
release: 1.82.0-nightly
commit-hash: b5d44db1daf0469b227a6211b987162a39a54730
commit-date: 2024-07-26
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:OpenSSL/3.3.1)
ssl: OpenSSL 3.3.1 4 Jun 2024
os: Arch Linux Rolling Release [64-bit]
@workingjubilee workingjubilee added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Aug 5, 2024
@epage epage added Command-package S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. A-unstable Area: nightly unstable support and removed S-triage Status: This issue is waiting on initial triage. labels Aug 5, 2024
@torhovland
Copy link
Contributor

I agree this looks like an issue. However, I guess it's a matter of interpretation whether or not publish = false implies it shouldn't be packaged. In the example above, "doing what I mean" implies not packaging it. But are there other use cases where you might want to package but not publish?

@epage
Copy link
Contributor

epage commented Aug 6, 2024

Because publish = false allows cargo package to run today, we would need to maintain that. So in this case, cargo +nightly package --workspace -Zpackage-workspace should succeed with every workspace member packaged.

@torhovland
Copy link
Contributor

should succeed with every workspace member packaged

Every member except for those that cannot be packaged (hence may have publish = false), right?

@epage
Copy link
Contributor

epage commented Aug 6, 2024

No, that doesn't follow with what I said.

From what I can tell, cargo package can run when package.publish = false. So if a user selects a package to run cargo package on, whether via the CWD, with -p, or with --workspace, we should package it, independent of package.publish.

@torhovland
Copy link
Contributor

OK, so packaging should simply not fail on:

The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.

@epage
Copy link
Contributor

epage commented Aug 6, 2024

As far as I can tell from existing precedence in cargo package, yes. Which might put a wrinkle in how we did workspace publishing packaging.

@workingjubilee
Copy link
Member Author

...I uhh... certainly would not want "publish the publish.false crates" to become the semantic of cargo publish --workspace if that ever appears. 😅

@workingjubilee
Copy link
Member Author

I do have the option of simply removing it from the workspace, but it all gets a bit awkward. To complicate matters further, these packages being in the workspace does affect feature resolution which also affects whether or not basic cargo check or cargo test work (as the library is one of those "you must enable one and only one of these features" sorts).

It looks like the thing that I would most want to do in the meantime is to cull the workspace down to only the crates I want to publish, but I can't think of a good way, currently, to enable a feature for some of the packages in the workspace so that cargo check and cargo test still work and simply use the default feature I want them to.

@epage
Copy link
Contributor

epage commented Aug 7, 2024

I wonder if that would be a flag of interested for cargo hack, a --publishable or something. Would be a good way to vet use cases and usefulness to do it in a third-party command.

@torhovland
Copy link
Contributor

I'll try writing a test for this.

@torhovland
Copy link
Contributor

@epage @jneem While this issue was quite easy to fix, I'm not sure it's the right fix. Could you take a look at my description in #14364, please?

@workingjubilee workingjubilee changed the title -Zpublish-workspace is not smart about publish = false -Zpackage-workspace is not smart about publish = false Aug 9, 2024
@workingjubilee
Copy link
Member Author

typo whoops.

workingjubilee added a commit to pgcentralfoundation/pgrx that referenced this issue Aug 9, 2024
Test that pgrx will always build after we publish it. It should never
again take an excessive amount of time to release pgrx, because we will
always be confident we are ready to release. This does not finish making
the release "turnkey", but it does take care of every obstacle to such.

Note that there is a technicality: we are "only" testing that our
_package_ builds. We are not actually pulling a published-to-cargo
release and testing it. We are not running the `cargo publish --dry-run`
command, either, because there is no `cargo publish --workspace`.
Instead, we are packaging the workspace and rebuilding *that package*.
This unfortunately demands that we factor out all the packages in the
workspace that are not going to be published.

Other details of the refactoring are informed by these oddities:
- `package.publish = false` doesn't play well with the extensions to
`cargo package --workspace`:
rust-lang/cargo#14356
- `workspace.exclude = []` does not properly support globs:
rust-lang/cargo#6009
- We *need* to reuse the same `CARGO_TARGET_DIR` for building and
testing our many examples or we run out of storage space on the runners.
@workingjubilee
Copy link
Member Author

workingjubilee commented Aug 11, 2024

I carried out the repo refactoring I mentioned. Obviously, what I "really want" is cargo publsih --workspace --dry-run, but that doesn't exist today. That day seems like a long way off. Even if it suddenly exists, and works as expected, it seemed likely I would be frustrated by it for other reasons with my current half-published half-not workspace. Thus the refactoring seemed useful, even if some details wound up quite gnarly.

For now, I am quite pleased that cargo package --workspace (actually cargo +nightly package --workspace -Zpackage-workspace but whatever) seems to now do exactly what I want it to do with this feature, as for a while now I have not had confidence that the pgrx repository can be released. This is both because of the whole "publishing an entire workspace isn't an atomic step" thing, and also because some changes in Cargo.toml can break packaged code while not affecting the usual tests, thus creating the oddity of code that passes CI but does not work in its actual release. If I don't pay close attention and notice that e.g. the docs.rs build is broken (which is a very indirect sign!), I can miss that happening. I want to do more repository-level refactoring, so having this in-place, and it being so easy... I thought I'd have to write my own non-integrated tooling, which is necessarily more verbose, and thus a slog... really helps.

@epage
Copy link
Contributor

epage commented Aug 12, 2024

That day seems like a long way off

The reason we have cargo package --workspace is people are actively working towards cargo publish --workspace.

Even if it suddenly exists, and works as expected, it seemed likely I would be frustrated by it for other reasons with my current half-published half-not workspace. Thus the refactoring seemed useful, even if pgcentralfoundation/pgrx#1796.

I assume what you are referring to is cargo publish --dry-run --workspace skipping publish = false packages. The semantics of cargo publish and cargo package are different which carries over when --workspace is used with cargo publish --workspace likely being less well constricted, allowing us to more openly discuss ideas like this.

@workingjubilee
Copy link
Member Author

"a long way off" can still be far enough out that it's worth the time to reengineer my repo to make things work now!

I assume what you are referring to is cargo publish --dry-run --workspace skipping publish = false packages. The semantics of cargo publish and cargo package are different which carries over when --workspace is used with cargo publish --workspace likely being less well constricted, allowing us to more openly discuss ideas like this.

oh good.

bors added a commit that referenced this issue Sep 6, 2024
Publish workspace

Adds support for simultaneously publishing multiple (possibly inter-dependent) packages in a workspace, gated by the `-Zpackage-workspace` flag.

Questions to be worked out through stabilization:
- Are we ok stabilizing this and #10948 at the same time?  Currently, they are behind the same flag
- What is the desired behavior for the publish timeout? This PR uploads the crates in batches (depending on the dependency graph), and we only timeout if nothing in the batch is available within the timeout, deferring the rest to the next wait-for-publish. So for example, if you have packages `a`, `b`, `c` then we'll wait up to 60 seconds and if only `a` and `b` were ready in that time, we'll then wait another 60 seconds for `c`.
- What is the desired behavior when some packages in a workspace have `publish = false`? This PR raises an error whenever any of the selected packages has `publish = false`, so it will error on `cargo publish --workspace` in a workspace with an unpublishable package. An alternative interface would implicitly exclude unpublishable packages in this case, but still error out if you explicitly select an unpublishable package with `-p package-name` (see #14356). This PR's behavior is the most conservative one as it can change from an error to implicit excludes later.

This is part of #1169
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-unstable Area: nightly unstable support C-bug Category: bug Command-package S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. Z-package-workspace Nightly: package-workspace
Projects
None yet
3 participants