Skip to content

Commit

Permalink
Organize deps
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesTaylor7 committed May 19, 2024
1 parent 1c92d76 commit 3833a25
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 54 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 117 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,57 +1,137 @@
[package]
name = "citadels"
edition = "2021"
default-run = "citadels"
version = "0.7.1"
default-run = "citadels"

[[bin]]
name = "citadels"
path = "src/main.rs"
[package.metadata.cargo-machete]
ignored = ["tower"]

[dependencies]
askama = { version = "0.12.1", default-features = false }
axum = { version = "0.7.2", features = ["ws","macros"], default-features = true }
futures = { version = "0.3.30", default-features = false }
http = { version = "1.0.0", default-features = false }
rand = { version = "0.8.5", default-features = false }
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] }
tokio-stream = { version = "0.1.14", default-features = false }
tower = "0.4.13"
tower-http = { version = "0.5.0", features = ["fs", "trace"] }
tower-layer = "0.3.2"
tower-cookies = "0.10.0"
async-trait = "0.1.80"
axum-core = "0.4.3"
log = "0.4.20"
env_logger = { version = "0.10.1", features = ["color"] }
percent-encoding = "2.3.1"
rand_xoshiro = "0.6.0"
rand_core = { version = "0.6.4", features = ["getrandom"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
time = "0.3.31"
dotenv = { version = "0.15.0", optional = true }
axum-core = "0.4.3"
serde_with = "3.5.0"
tracing = { version = "0.1.40", default-features = false }
macros = { path = "./macros"}
reqwest = { version = "0.12.4", features = ["json"], default-features = false }
anyhow = { version = "1.0.83", features = ["std", "backtrace"], default-features = false }
maud = { version = "0.26.0", features = ["axum"], default-features = false}
arcstr = { version = "1.2.0", features = ["serde"], default-features = false }
uuid = { version = "1.8.0", features = ["v4"] }
thiserror = "1.0.61"
percent-encoding = "2.3.1"
pkce = { path = "./vendor/pkce" }
time = "0.3.31"
tower = "0.4.13"
tower-cookies = "0.10.0"
tower-layer = "0.3.2"
tower-service = "0.3.2"
async-trait = "0.1.80"
jsonwebtoken = { version = "9.3.0", default-features = false }
getrandom = { version = "0.2.11", default-features = false }

[dependencies.anyhow]
version = "1.0.83"
features = ["std", "backtrace"]
default-features = false

[dependencies.arcstr]
version = "1.2.0"
features = ["serde"]
default-features = false

[dependencies.askama]
version = "0.12.1"
features = []
default-features = false

[dependencies.axum]
version = "0.7.2"
features = ["ws", "macros"]

[dependencies.dotenv]
version = "0.15.0"
features = []
optional = true

[dependencies.env_logger]
version = "0.10.1"
features = ["color"]

[dependencies.futures]
version = "0.3.30"
features = []
default-features = false

[dependencies.http]
version = "1.0.0"
features = []
default-features = false

[dependencies.jsonwebtoken]
version = "9.3.0"
features = []
default-features = false

[dependencies.macros]
path = "./macros"
features = []

[dependencies.maud]
version = "0.26.0"
features = ["axum"]
default-features = false

[dependencies.pkce]
path = "./vendor/pkce"
features = []

[dependencies.rand]
version = "0.8.5"
features = []
default-features = false

[dependencies.rand_core]
version = "0.6.4"
features = ["getrandom"]

[dependencies.reqwest]
version = "0.12.4"
features = ["json"]
default-features = false

[dependencies.serde]
version = "1.0.195"
features = ["derive"]

[dependencies.tokio]
version = "1.35.1"
features = ["macros", "rt-multi-thread"]

[dependencies.tokio-stream]
version = "0.1.14"
features = []
default-features = false

[dependencies.tower-http]
version = "0.5.0"
features = ["fs"]
default-features = false
optional = true

[dependencies.tracing]
version = "0.1.40"
features = []
default-features = false

[dependencies.uuid]
version = "1.8.0"
features = ["v4"]
default-features = false

[features]
dev = []
dev = ["dep:tower-http"]
dotenv = ["dep:dotenv"]

# https://old.reddit.com/r/rust/comments/gvrgca/this_is_a_neat_trick_for_getting_good_runtime/
[profile.dev]
opt-level = 0

[profile.dev.package."*"]
opt-level = 3

[profile.dev]
opt-level = 0
[[bin]]
path = "src/main.rs"
name = "citadels"
required-features = []
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ This is excessive, and I will try to stick to 3:
- info

## Env & Secret management
Script to generate a new signing key:
```bash
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
```
In prod use `fly secret`.
In dev, use the .env file.

Expand All @@ -87,3 +83,8 @@ For production go in:
- Use `fly secret`, for the secret env vars.

Don't use `.config/cargo.toml` or the env! macro. We need runtime env lookup, not compile time.

## Dependency Management
Use cargo-machete & cargo-unused-features to prune what is downloaded and compiled.

Use careful judgement about when to include a dep, and when to fork and vendor. By vendoring we can still respect the licenses but remove unused optional dependencies. `vendor/` folder is for forked vendored libraries.
1 change: 0 additions & 1 deletion sample.json

This file was deleted.

6 changes: 0 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ async fn main() {
#[cfg(feature = "dotenv")]
dotenv::dotenv().expect(".env not found");

/*
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();
*/

citadels::logger::init();

let host = "0.0.0.0:8080";
Expand Down
5 changes: 2 additions & 3 deletions src/server/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use serde::Deserialize;
use std::borrow::{Borrow, Cow};
use std::collections::{HashMap, HashSet};
use tower_cookies::{CookieManagerLayer, Cookies};
use tower_http::trace::TraceLayer;

pub fn get_router(state: AppState) -> Router {
let mut router = Router::new()
Expand All @@ -52,13 +51,13 @@ pub fn get_router(state: AppState) -> Router {
.route("/game/action", post(submit_game_action))
.route("/game/menu/:menu", get(get_game_menu));

if cfg!(feature = "dev") {
#[cfg(feature = "dev")]
{
use tower_http::services::ServeDir;
router = router.nest_service("/public", ServeDir::new("public"));
}

router
.layer(TraceLayer::new_for_http())
.layer(SessionCookieLayer::new())
.layer(CookieManagerLayer::new())
.with_state(state)
Expand Down

0 comments on commit 3833a25

Please sign in to comment.