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

Sharing xtask across repositories #29

Open
elichai opened this issue Mar 25, 2024 · 2 comments
Open

Sharing xtask across repositories #29

elichai opened this issue Mar 25, 2024 · 2 comments

Comments

@elichai
Copy link

elichai commented Mar 25, 2024

I have a project where we use xtask to handle building and publishing,
Now I want to create a different repository for a different project where my xtask logic will be almost one to one to the other project (modulo few features)
I wondered about best practices ideas on sharing xtask between repositories

(extracting logic to library and sharing that between the xtasks, moving the xtask to a third repository, duplicating all the logic, something more creative?)

@matklad
Copy link
Owner

matklad commented Mar 25, 2024

Good question! "extracting logic to library" is something I tried a while ago to share the common logic for building a crate and publishing it to crates.io: https://github.com/matklad/xaction.

However, I consider that to be a failed experiment and switched to "duplicating all logic" instead.

The main thing you loose when extracting a library is the ability to just look at the source code of xtask and understand what's going on, to see see the sequence of steps that constitute an xtask.

So my current advice would probably be:

  • duplicate the orchestrating parts of xtask. Things like CLI flags parsing should be duplciated across the repos. Similarly, if an xtask needs to run a command like cargo build, you probably want that invocation to be present verbatim in every repo, so that you can see "here we are doing cargo build".
  • for "meatier" parts of the task, do extract them to a reusable library. A litmus test here would probably be "can this be used outside of an xtask?". So, if, e.g., you are using an xtask to cook up a debian package, you probably want to have a debian packaging library or some such.

@matklad
Copy link
Owner

matklad commented Mar 25, 2024

Coming back to that xaction example, the thing I wanted to duplicate there was essentially "run cargo test, run git tag, run cargo publish". But that is orchestration! The actual logic for doing all those things was already shared by virtue of being a part of git and cargo! It doesn't by you much to try to abstract just the sequence of commands.

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

No branches or pull requests

2 participants