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

Support custom derives on Request and Response #438

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

ShaneMurphy2
Copy link
Contributor

Replace the bespoke "derive_serde" with a more flexible "derive = [, , ...]" form.

Deprecate the old "derive_serde" form, and emit deprecation warnings.

Add trybuild tests in a separate test crate to ensure the deprecation, features, and error messages all behave as expected. This technique of a separate trybuild test crate is borrowed from tokio/tests-build. Update CI to run this new crate's tests under the serde matrix.

Copy link

google-cla bot commented Feb 23, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ShaneMurphy2
Copy link
Contributor Author

Not sure if I did the CI modification correctly, please take a look.

@ShaneMurphy2
Copy link
Contributor Author

Addresses #436

@ShaneMurphy2
Copy link
Contributor Author

Looks like one thing I still need to iron out (besides the CLA 😬) is the situation where serde1 is enabled but the user explicitly writes #[service(derive = [Serialize, Deserialize])]. That currently causes a conflicting implementation error. I guess I would need to scan through the paths in the meta list and look for Serialize or Deserialize. Of course, that wouldn't fix someone importing Serialize under a different name.

@tikue
Copy link
Collaborator

tikue commented Feb 23, 2024

the situation where serde1 is enabled but the user explicitly writes #[service(derive = [Serialize, Deserialize])]

Oh, this is what I meant to address by my 4th bullet of #436 (comment): only implicitly derive serialize when derive = [...] is not present.

@ShaneMurphy2
Copy link
Contributor Author

the situation where serde1 is enabled but the user explicitly writes #[service(derive = [Serialize, Deserialize])]

Oh, this is what I meant to address by my 4th bullet of #436 (comment): only implicitly derive serialize when derive = [...] is not present.

Gotcha, will work on it.

@ShaneMurphy2
Copy link
Contributor Author

Should be good now, I think I incorrectly updated the CI file though. Either way, do we wanna bikeshed the name a bit? Is derive clear? I should also update the documentation for the macro.

@ShaneMurphy2
Copy link
Contributor Author

Cleaned up the implementation a bit.

@ShaneMurphy2
Copy link
Contributor Author

Added some docs and should fix CI 🤞

@@ -0,0 +1,13 @@
[package]
name = "tests-build"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this package, could the tests go in the existing tarpc/tests/compile_fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, assumed trybuild tests would be in the plugins crate, my bad. Yes, I believe they can go there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@ShaneMurphy2 ShaneMurphy2 force-pushed the customizable-derives branch 2 times, most recently from e72eb0e to 2d88b44 Compare February 25, 2024 08:02
${{ matrix.serde }} ${{ matrix.tokio }} ${{ matrix.serde-transport }} \
${{ matrix.serde-transport-json }} ${{ matrix.serde-transport-bincode }} \
${{ matrix.tcp }} ${{ matrix.unix }} \
cargo test --manifest-path tests-build/Cargo.toml $ {{ matrix.serde }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't needed now, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will remove.

@tikue
Copy link
Collaborator

tikue commented Feb 28, 2024

Still seeing some test failures:
image

@ShaneMurphy2
Copy link
Contributor Author

Still seeing some test failures: image

Hm, tests passed locally, and those outputs look the same except for the number of candidate traits. Interesting.

@tikue
Copy link
Collaborator

tikue commented Feb 28, 2024

Still seeing some test failures: image

Hm, tests passed locally, and those outputs look the same except for the number of candidate traits. Interesting.

sometimes I've seen these changes based on whether the tests were run with nightly vs stable rustc?

@ShaneMurphy2
Copy link
Contributor Author

Still seeing some test failures: image

Hm, tests passed locally, and those outputs look the same except for the number of candidate traits. Interesting.

sometimes I've seen these changes based on whether the tests were run with nightly vs stable rustc?

I think it's that the test matrix in CI is enabling features that bring in dependencies that provide a serialize method under a trait. Because of that, the compiler is suggesting more items, causing the output to be different. I could re-generate the stderr files with all feature enabled, but I'm not sure if that would cause CI to fail in a different spot when it toggles the feature off. I think I'll try refactoring the test to use fully qualified syntax to the serialize method so that the error message is not ambiguous.

@ShaneMurphy2
Copy link
Contributor Author

That should fix it, I'm a little worried about how brittle these tests are though. Let me know if you think they're more trouble than they're worth.

@tikue
Copy link
Collaborator

tikue commented Feb 28, 2024

Oh looks like the CLA hasn't been signed, either? Is that something you can take a look at?

@ShaneMurphy2
Copy link
Contributor Author

Oh looks like the CLA hasn't been signed, either? Is that something you can take a look at?

Yeah, legal is looking at it. Should just be due diligence and not a problem.

@ShaneMurphy2
Copy link
Contributor Author

That should fix it, I'm a little worried about how brittle these tests are though. Let me know if you think they're more trouble than they're worth.

Forgot to overwrite the .stderr files 🤦

@ShaneMurphy2
Copy link
Contributor Author

Green!

@ShaneMurphy2
Copy link
Contributor Author

Re: CLA, the legal team is either at a conference or out sick, so it might be a few more days.

@ShaneMurphy2
Copy link
Contributor Author

Re: CLA, the legal team is either at a conference or out sick, so it might be a few more days.

Approved, just waiting for wheels to turn.

@ShaneMurphy2
Copy link
Contributor Author

Should be good to re-run the pipeline!

plugins/Cargo.toml Outdated Show resolved Hide resolved
Replace the bespoke "derive_serde" with a more flexible
"derive = [<path>, <path>, ...]" form.

Deprecate the old "derive_serde" form, and emit deprecation warnings.
@tikue
Copy link
Collaborator

tikue commented Mar 9, 2024

Thanks a lot! This is a great generalization.

@tikue tikue added this pull request to the merge queue Mar 9, 2024
Merged via the queue into google:master with commit 160b561 Mar 9, 2024
33 checks passed
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.

2 participants