From 80698c0b1736cbe4b5549f31b0317d868c874aa9 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 6 Sep 2024 19:51:06 -0400 Subject: [PATCH] docs: add some more conduwuit development info Signed-off-by: strawberry --- CONTRIBUTING.md | 9 +++-- development.md | 1 + docs/contributing.md | 2 +- docs/development.md | 78 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 83 insertions(+), 7 deletions(-) create mode 120000 development.md mode change 100644 => 120000 docs/contributing.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b5fa56e4..0a11394e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Contributing guide This page is for about contributing to conduwuit. The -[development](development.md) page may be of interest for you as well. +[development](./development.md) page may be of interest for you as well. If you would like to work on an [issue][issues] that is not assigned, preferably ask in the Matrix room first at [#conduwuit:puppygock.gay][conduwuit-matrix], @@ -67,7 +67,7 @@ failing from your changes, please review the logs (they are uploaded as artifacts) and determine if they're intended or not. If you'd like to run Complement locally using Nix, see the -[testing](docs/development/testing.md) page. +[testing](development/testing.md) page. [Sytest][sytest] support will come soon. @@ -128,7 +128,10 @@ Direct all PRs/MRs to the `main` branch. By sending a pull request or patch, you are agreeing that your changes are allowed to be licenced under the Apache-2.0 licence and all of your conduct is -in line with the Contributor's Covenant. +in line with the Contributor's Covenant, and conduwuit's Code of Conduct. + +Contribution by users who violate either of these code of conducts will not have +their contributions accepted. [issues]: https://github.com/girlbossceo/conduwuit/issues [conduwuit-matrix]: https://matrix.to/#/#conduwuit:puppygock.gay diff --git a/development.md b/development.md new file mode 120000 index 00000000..35e9aab8 --- /dev/null +++ b/development.md @@ -0,0 +1 @@ +docs/development.md \ No newline at end of file diff --git a/docs/contributing.md b/docs/contributing.md deleted file mode 100644 index 81ddb505..00000000 --- a/docs/contributing.md +++ /dev/null @@ -1 +0,0 @@ -{{#include ../CONTRIBUTING.md}} diff --git a/docs/contributing.md b/docs/contributing.md new file mode 120000 index 00000000..44fcc634 --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1 @@ +../CONTRIBUTING.md \ No newline at end of file diff --git a/docs/development.md b/docs/development.md index eda9392a..e1f36c0c 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,10 +1,74 @@ # Development Information about developing the project. If you are only interested in using -it, you can safely ignore this section. If you plan on contributing, see the -[contributor's guide](contributing.md). +it, you can safely ignore this page. If you plan on contributing, see the +[contributor's guide](./contributing.md). -## List of forked dependencies During conduwuit development, we have had to fork +## conduwuit project layout + +conduwuit uses a collection of sub-crates, packages, or workspace members +that indicate what each general area of code is for. All of the workspace +members are under `src/`. The workspace definition is at the top level / root +`Cargo.toml`. + +The crate names are generally self-explanatory: +- `admin` is the admin room +- `api` is the HTTP API, Matrix C-S and S-S endpoints, etc +- `core` is core conduwuit functionality like config loading, error definitions, +global utilities, logging infrastructure, etc +- `database` is RocksDB methods, helpers, RocksDB config, and general database definitions, +utilities, or functions +- `macros` are conduwuit Rust [macros][macros] like general helper macros, logging +and error handling macros, and [syn][syn] and [procedural macros][proc-macro] +used for admin room commands and others +- `main` is the "primary" sub-crate. This is where the `main()` function lives, +tokio worker and async initialisation, Sentry initialisation, [clap][clap] init, +and signal handling. If you are adding new [Rust features][features], they *must* +go here. +- `router` is the webserver and request handling bits, using axum, tower, tower-http, +hyper, etc, and the [global server state][state] to access `services`. +- `service` is the high-level database definitions and functions for data, +outbound/sending code, and other business logic such as media fetching. + +It is highly unlikely you will ever need to add a new workspace member, but +if you truly find yourself needing to, we recommend reaching out to us in +the Matrix room for discussions about it beforehand. + +The primary inspiration for this design was apart of hot reloadable development, +to support "conduwuit as a library" where specific parts can simply be swapped out. +There is evidence Conduit wanted to go this route too as `axum` is technically an +optional feature in Conduit, and can be compiled without the binary or axum library +for handling inbound web requests; but it was never completed or worked. + +See the Rust documentation on [Workspaces][workspaces] for general questions +and information on Cargo workspaces. + +## Adding compile-time [features][features] + +If you'd like to add a compile-time feature, you must first define it in +the `main` workspace crate located in `src/main/Cargo.toml`. The feature must +enable a feature in the other workspace crate(s) you intend to use it in. Then +the said workspace crate(s) must define the feature there in its `Cargo.toml`. + +So, if this is adding a feature to the API such as `woof`, you define the feature +in the `api` crate's `Cargo.toml` as `woof = []`. The feature definition in `main`'s +`Cargo.toml` will be `woof = ["conduit-api/woof"]`. + +The rationale for this is due to Rust / Cargo not supporting +["workspace level features"][9], we must make a choice of; either scattering +features all over the workspace crates, making it difficult for anyone to add +or remove default features; or define all the features in one central workspace +crate that propagate down/up to the other workspace crates. It is a Cargo pitfall, +and we'd like to see better developer UX in Rust's Workspaces. + +Additionally, the definition of one single place makes "feature collection" in our +Nix flake a million times easier instead of collecting and deduping them all from +searching in all the workspace crates' `Cargo.toml`s. Though we wouldn't need to +do this if Rust supported workspace-level features to begin with. + +## List of forked dependencies + +During conduwuit development, we have had to fork some dependencies to support our use-cases in some areas. This ranges from things said upstream project won't accept for any reason, faster-paced development (unresponsive or slow upstream), conduwuit-specific usecases, or @@ -53,3 +117,11 @@ RUSTFLAGS="--cfg tokio_unstable" cargo build \ [6]: https://github.com/tokio-rs/tracing/ [7]: https://docs.rs/tokio-console/latest/tokio_console/ [8]: https://github.com/zaidoon1/ +[9]: https://github.com/rust-lang/cargo/issues/12162 +[workspaces]: https://doc.rust-lang.org/cargo/reference/workspaces.html +[macros]: https://doc.rust-lang.org/book/ch19-06-macros.html +[syn]: https://docs.rs/syn/latest/syn/ +[proc-macro]: https://doc.rust-lang.org/reference/procedural-macros.html +[clap]: https://docs.rs/clap/latest/clap/ +[features]: https://doc.rust-lang.org/cargo/reference/features.html +[state]: https://docs.rs/axum/latest/axum/extract/struct.State.html