sapling/eden/fs/Cargo.toml
David Tolnay 408a02b7da Add a -mocks subcrate exporting constructor function for mock clients
Summary:
According to the analysis in D54709575, about 60% of the compile time of Rust Thrift client crates is the mocks. Mocks are rarely used compared to the rest of the contents of the clients crate, and almost always just in tests. Moving mocks out to a separate crate therefore makes clients build 2.5× faster.

This diff keeps the mock implementations in the `-clients` crate for now, but adds a new `-mocks` crate matching the API that we'll need to migrate to. According to `fbgs -frs$ '>::mock()' -l` there are 769 call sites that need to be updated, which is small compared to the Thrift codemods from earlier in the year. Once the codemod is done, we get to cash in on the build speedup in {D56451418}.

The dependency graph is:

```lang=mermaid
flowchart BT;
    foo-clients --> foo["foo (#quot;types#quot;)"];
    foo-services --> foo;
    foo-mocks --> foo-clients;
```

Previously, mocks were constructed using an associated function on the client trait object: `<dyn FooClient>::mock()`. In the new API, the trait `FooClient` is defined in `foo-clients` whereas the mock client for the same Thrift service is defined in `foo-mocks`, so a different approach is needed because the mocks crate cannot add an inherent method onto a trait object defined in a different crate. We need to pick one of the following APIs to use instead:

1. An extension trait: `use foo_mocks::DynClient as _; <dyn FooService>::mock()`

2. `<dyn FooService as foo_mocks::DynClient>::mock()`

3. `foo_mocks:🆕:<dyn FooService>()`

4. `foo_mocks::FooService::new()`

5. `foo_mocks::FooServiceMock::new()` (append `Mock` suffix to service name)

Number 3 or 5 seems the most promising to me. 4 doesn't seem pleasant because you'd almost always want to have the client `trait FooService` imported in order to be able to make trait method calls on your mock, which gives rise to a name collision in the type namespace.

This diff implements option 3 but I am interested in feedback.

Reviewed By: Imxset21, shayne-fletcher

Differential Revision: D56451421

fbshipit-source-id: c23fd9a28f8dd5bd75306a913819bc0ed66fb4e5
2024-04-23 16:09:14 -07:00

45 lines
2.2 KiB
TOML

[patch.crates-io]
abomonation = { git = "https://github.com/markbt/abomonation", rev = "0f43346d2afa2aedc64d61f3f4273e8d1e454642" }
base64urlsafedata = { git = "https://github.com/kanidm/webauthn-rs.git", rev = "d278c56adfa39a0723c79bdcd461644194bc5138" }
bindgen = { git = "https://github.com/rust-lang/rust-bindgen", rev = "7e9043497297e04e91ae76dfe0d2e7998828e529" }
bindgen-cli = { git = "https://github.com/rust-lang/rust-bindgen", rev = "7e9043497297e04e91ae76dfe0d2e7998828e529" }
cxx = { package = "cxx", git = "https://github.com/facebookexperimental/cxx.git", rev = "69a4f12f40d99284ebda58f33602ab60b70624d7" }
cxx-build = { package = "cxx-build", git = "https://github.com/facebookexperimental/cxx.git", rev = "69a4f12f40d99284ebda58f33602ab60b70624d7" }
graphql-parser = { git = "https://github.com/graphql-rust//graphql-parser", rev = "8d76425d83c40670570cc325f57c730262f07456" }
imgui = { git = "https://github.com/imgui-rs/imgui-rs.git", rev = "47bb38be50fafe99021b6436672dea1c28920e70" }
lru-disk-cache = { git = "https://github.com/mozilla/sccache", rev = "fdbf843d174c6796d736b2b61dab0297670390f8" }
perf-event = { version = "0.4", git = "https://github.com/krallin/perf-event.git", rev = "86224a9bc025d5d19f719542f27c8c629a08b167" }
perf-event-open-sys = { version = "4.0", git = "https://github.com/krallin/perf-event.git", rev = "86224a9bc025d5d19f719542f27c8c629a08b167" }
quickcheck = { git = "https://github.com/jakoschiko/quickcheck", rev = "6ecdf5bb4b0132ce66670b4d46453aa022ea892c" }
riscv = { git = "https://github.com/rust-embedded/riscv.git", rev = "288d02328b4bc2ac966ba3dda5c5032e8a712dff" }
[workspace]
members = [
"benchmarks",
"cli_rs/edenfs-client",
"cli_rs/edenfs-commands",
"cli_rs/edenfs-config",
"cli_rs/edenfs-error",
"cli_rs/edenfs-utils",
"cli_rs/edenfsctl",
"cli_rs/stack-config",
"cli_rs/stack-config-derive",
"config",
"config/clients",
"config/mocks",
"config/services",
"inodes/overlay",
"inodes/overlay/clients",
"inodes/overlay/mocks",
"inodes/overlay/services",
"service",
"service/clients",
"service/mocks",
"service/services",
"service/thrift_streaming",
"service/thrift_streaming/clients",
"service/thrift_streaming/mocks",
"service/thrift_streaming/services",
]
resolver = "2"