Clarity about cargo workspaces

Hi there,

I am confused about the expected compilation of cargo workspaces.

I thought the idea is that crates inside the workspace wouldn't get recompiled unless they changed but that doesn't seem to be the case.

I currently have a single workspace for all my projects and they tend to be structured:

  • project-1-api
  • project-1-model (most of the logic)
  • project-1-client
  • project-1-server
  • project-2-api
  • project-2-model (most of the logic)
  • project-2-client
  • project-2-server

whenever I do anything I can see all 8 (in this example) crates get compiled.

If this is the case, is there any benefit in splitting the crates inside a workspace or should I just use Cargo features and have the following layout?:

  • project-1
  • project-2

Thanks!

In which directory are you calling cargo build? Any downstream dependencies are also recompiled if you call it from the top-level directory.

my understanding was that calling cargo build in the workspace root would be a no-op if none of the source code/Cargo.toml in the workspace crates had changed, but it still compiles each one.

If I call cargo build in a specific workspace crate then it would be a no-op if none of the source code/Cargo.toml in the workspace crates it depends on had changed, but it still compiles each workspace crate it depends on.

From the workspace root:

➜  rust git:(develop) ✗ cargo build
   Compiling dist-builder v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dist_builder)
   Compiling tiberius v0.6.4
   Compiling jonah-cli v0.1.0 (/Users/coliny/Dev/XXX/src/rust/jonah-cli)
   Compiling db-test v0.1.0 (/Users/coliny/Dev/XXX/src/rust/db-test)
   Compiling ldap-khshp v0.1.0 (/Users/coliny/Dev/XXX/src/rust/ldap-khshp)
   Compiling i18n v0.1.0 (/Users/coliny/Dev/XXX/src/rust/i18n)
   Compiling log-store-proto-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-proto-client)
   Compiling dashboard_ui_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard_ui_server)
   Compiling authentication-log-stream v0.1.0 (/Users/coliny/Dev/XXX/src/rust/authentication-log-stream)
   Compiling security-log-stream v0.1.0 (/Users/coliny/Dev/XXX/src/rust/security-log-stream)
   Compiling log-store-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-api)
   Compiling log-store-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-client)
   Compiling log-db-lib v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-db-lib)
   Compiling dashboard-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard-api)
   Compiling session_db v0.1.0 (/Users/coliny/Dev/XXX/src/rust/session_db)
   Compiling reference_data_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/reference_data_server)
   Compiling analytocs_feeder v0.1.0 (/Users/coliny/Dev/XXX/src/rust/analytocs_feeder)
   Compiling log-store-cli v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-cli)
   Compiling log-store-server-load-test v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-server-load-test)
   Compiling dashboard-domain v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard-domain)
   Compiling golden-data-set-simple v0.1.0 (/Users/coliny/Dev/XXX/src/rust/golden-data-set-simple)
   Compiling log_store_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log_store_server)
   Compiling dashboard_backend_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard_backend_server)
   Compiling external-patient-integration v0.1.0 (/Users/coliny/Dev/XXX/src/rust/external-patient-integration)
    Finished dev [unoptimized + debuginfo] target(s) in 23.37s
➜  rust git:(develop) ✗ cargo build
   Compiling log-store-proto-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-proto-client)
   Compiling log-store-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-api)
   Compiling log-store-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-client)
   Compiling log-db-lib v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-db-lib)
   Compiling dashboard-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard-api)
   Compiling analytocs_feeder v0.1.0 (/Users/coliny/Dev/XXX/src/rust/analytocs_feeder)
   Compiling log-store-server-load-test v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-server-load-test)
   Compiling session_db v0.1.0 (/Users/coliny/Dev/XXX/src/rust/session_db)
   Compiling log-store-cli v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-cli)
   Compiling reference_data_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/reference_data_server)
   Compiling dashboard-domain v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard-domain)
   Compiling golden-data-set-simple v0.1.0 (/Users/coliny/Dev/XXX/src/rust/golden-data-set-simple)
   Compiling log_store_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log_store_server)
   Compiling dashboard_backend_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard_backend_server)
    Finished dev [unoptimized + debuginfo] target(s) in 9.71s
➜  rust git:(develop) ✗ cargo build
   Compiling log-store-proto-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-proto-client)
   Compiling log-store-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-api)
   Compiling log-store-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-client)
   Compiling log-db-lib v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-db-lib)
   Compiling dashboard-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard-api)
   Compiling analytocs_feeder v0.1.0 (/Users/coliny/Dev/XXX/src/rust/analytocs_feeder)
   Compiling reference_data_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/reference_data_server)
   Compiling session_db v0.1.0 (/Users/coliny/Dev/XXX/src/rust/session_db)
   Compiling log-store-cli v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-cli)
   Compiling log-store-server-load-test v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-server-load-test)
   Compiling log_store_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log_store_server)
   Compiling dashboard-domain v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard-domain)
   Compiling golden-data-set-simple v0.1.0 (/Users/coliny/Dev/XXX/src/rust/golden-data-set-simple)
   Compiling dashboard_backend_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/dashboard_backend_server)
    Finished dev [unoptimized + debuginfo] target(s) in 9.02s
➜  rust git:(develop) ✗ 

from a specific crate:

➜  reference_data_server git:(develop) ✗ cargo build
   Compiling log-store-proto-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-proto-client)
   Compiling log-store-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-api)
   Compiling log-store-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-client)
   Compiling reference_data_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/reference_data_server)
    Finished dev [unoptimized + debuginfo] target(s) in 6.72s
➜  reference_data_server git:(develop) ✗ cargo build
   Compiling log-store-proto-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-proto-client)
   Compiling log-store-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-api)
   Compiling log-store-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-client)
   Compiling reference_data_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/reference_data_server)
    Finished dev [unoptimized + debuginfo] target(s) in 5.48s
➜  reference_data_server git:(develop) ✗ cargo build
   Compiling log-store-proto-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-proto-client)
   Compiling log-store-api v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-api)
   Compiling log-store-client v0.1.0 (/Users/coliny/Dev/XXX/src/rust/log-store-client)
   Compiling reference_data_server v0.1.0 (/Users/coliny/Dev/XXX/src/rust/reference_data_server)
    Finished dev [unoptimized + debuginfo] target(s) in 5.11s
➜  reference_data_server git:(develop) ✗ 

How many Cargo.lock files do you have in the workspace?

Just the one:

➜  rust git:(develop) ✗ find . -name Cargo.lock
./Cargo.lock

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.