diff --git a/examples/quick-start-workspace/Cargo.toml b/examples/quick-start-workspace/Cargo.toml index 2aebcb0c..5d882e29 100644 --- a/examples/quick-start-workspace/Cargo.toml +++ b/examples/quick-start-workspace/Cargo.toml @@ -1,6 +1,10 @@ [workspace] resolver = "2" -members = ["my-*", "my-workspace-hack"] +# Note that we define member crates with a wildcard here and NOT with explicit +# paths because the flake.nix is written in a way such that top-level members +# (`my-cli` and `my-server`) are built as different derivations which avoid being +# rebuilt if the other package's sources change. +members = ["crates/*"] [workspace.package] version = "0.1.0" diff --git a/examples/quick-start-workspace/my-cli/Cargo.toml b/examples/quick-start-workspace/crates/my-cli/Cargo.toml similarity index 100% rename from examples/quick-start-workspace/my-cli/Cargo.toml rename to examples/quick-start-workspace/crates/my-cli/Cargo.toml diff --git a/examples/quick-start-workspace/my-cli/src/main.rs b/examples/quick-start-workspace/crates/my-cli/src/main.rs similarity index 100% rename from examples/quick-start-workspace/my-cli/src/main.rs rename to examples/quick-start-workspace/crates/my-cli/src/main.rs diff --git a/examples/quick-start-workspace/my-common/Cargo.toml b/examples/quick-start-workspace/crates/my-common/Cargo.toml similarity index 100% rename from examples/quick-start-workspace/my-common/Cargo.toml rename to examples/quick-start-workspace/crates/my-common/Cargo.toml diff --git a/examples/quick-start-workspace/my-common/src/lib.rs b/examples/quick-start-workspace/crates/my-common/src/lib.rs similarity index 100% rename from examples/quick-start-workspace/my-common/src/lib.rs rename to examples/quick-start-workspace/crates/my-common/src/lib.rs diff --git a/examples/quick-start-workspace/my-server/Cargo.toml b/examples/quick-start-workspace/crates/my-server/Cargo.toml similarity index 100% rename from examples/quick-start-workspace/my-server/Cargo.toml rename to examples/quick-start-workspace/crates/my-server/Cargo.toml diff --git a/examples/quick-start-workspace/my-server/src/main.rs b/examples/quick-start-workspace/crates/my-server/src/main.rs similarity index 100% rename from examples/quick-start-workspace/my-server/src/main.rs rename to examples/quick-start-workspace/crates/my-server/src/main.rs diff --git a/examples/quick-start-workspace/my-workspace-hack/.gitattributes b/examples/quick-start-workspace/crates/my-workspace-hack/.gitattributes similarity index 100% rename from examples/quick-start-workspace/my-workspace-hack/.gitattributes rename to examples/quick-start-workspace/crates/my-workspace-hack/.gitattributes diff --git a/examples/quick-start-workspace/my-workspace-hack/Cargo.toml b/examples/quick-start-workspace/crates/my-workspace-hack/Cargo.toml similarity index 100% rename from examples/quick-start-workspace/my-workspace-hack/Cargo.toml rename to examples/quick-start-workspace/crates/my-workspace-hack/Cargo.toml diff --git a/examples/quick-start-workspace/my-workspace-hack/build.rs b/examples/quick-start-workspace/crates/my-workspace-hack/build.rs similarity index 100% rename from examples/quick-start-workspace/my-workspace-hack/build.rs rename to examples/quick-start-workspace/crates/my-workspace-hack/build.rs diff --git a/examples/quick-start-workspace/my-workspace-hack/src/lib.rs b/examples/quick-start-workspace/crates/my-workspace-hack/src/lib.rs similarity index 100% rename from examples/quick-start-workspace/my-workspace-hack/src/lib.rs rename to examples/quick-start-workspace/crates/my-workspace-hack/src/lib.rs diff --git a/examples/quick-start-workspace/flake.nix b/examples/quick-start-workspace/flake.nix index c5ee53dd..1989ebb5 100644 --- a/examples/quick-start-workspace/flake.nix +++ b/examples/quick-start-workspace/flake.nix @@ -71,8 +71,8 @@ fileset = lib.fileset.unions [ ./Cargo.toml ./Cargo.lock - ./my-common - ./my-workspace-hack + ./crates/my-common + ./crates/my-workspace-hack crate ]; }; @@ -81,15 +81,19 @@ # This allows consumers to only depend on (and build) only what they need. # Though it is possible to build the entire workspace as a single derivation, # so this is left up to you on how to organize things + # + # Note that the cargo workspace must define `workspace.members` using wildcards, + # otherwise, omitting a crate (like we do below) will result in errors since + # cargo won't be able to find the sources for all members. my-cli = craneLib.buildPackage (individualCrateArgs // { pname = "my-cli"; cargoExtraArgs = "-p my-cli"; - src = fileSetForCrate ./my-cli; + src = fileSetForCrate ./crates/my-cli; }); my-server = craneLib.buildPackage (individualCrateArgs // { pname = "my-server"; cargoExtraArgs = "-p my-server"; - src = fileSetForCrate ./my-server; + src = fileSetForCrate ./crates/my-server; }); in {