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

Using workspaces with small closures #270

Open
jmgilman opened this issue Dec 8, 2022 · 3 comments
Open

Using workspaces with small closures #270

jmgilman opened this issue Dec 8, 2022 · 3 comments

Comments

@jmgilman
Copy link

jmgilman commented Dec 8, 2022

Background

I have a repository setup as such:

Cargo.toml
Cargo.lock
src/pkg1/Cargo.toml
src/pkg2/Cargo.toml
src/pkg3/Cargo.toml

The root Cargo.toml establishes a workspace as such:

[workspace]
members = [
  "src/pkg1",
  "src/pkg2",
  "src/pkg3"
]

Then packages are built as such:

# ...
naersk.buildPackage {
  inherit name version;

  root = inputs.self;

  cargoBuildOptions = x: x ++ ["--package" "${name}"];
  cargoTestOptions = x: x ++ ["--package" "${name}"] ;
}

Problem

The above derivation captures the entire repository (because of inputs.self). Thus, when anything in the repository changes, the input hash changes and causes a rebuild of any of the packages.

If I filter root to only include the source of a single package, cargo fails because it expects all packages defined in the workspace to exist on the filesystem. For example, if I filter only to include src/pkg1, it fails with:

opening file '/nix/store/abc123-source/pkg2/Cargo.toml': No such file or directory

This creates a problematic setup because I cannot disassociate the projects such that changes in one do not invalidate another one. I imagine I must be doing something wrong here. Is there a way to isolate workspace packages to avoid this problem?

@jmgilman
Copy link
Author

jmgilman commented Dec 8, 2022

For additional context, I tried using the targets option instead of specifying the --package flag and it built the entire workspace. I looked through the source and it looks like it's not wired up to anything, so I think the documentation might be outdated.

@Patryk27
Copy link
Contributor

Patryk27 commented Dec 8, 2022

I see - maybe members = [ "src/*" ] (+ filtering-out unnecessary directories through Nix) will do it?

I looked through the source and it looks like it's not wired up to anything [...]

Whoopsie, yeah - looks like it 😅

@jmgilman
Copy link
Author

jmgilman commented Dec 8, 2022

Hmm, doesn't look like it works as one might expect. Cargo still tries to find the specific workspace members. I'm not sure you can override it like that, cargo still uses the root Cargo.toml to determine the workspace members.

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