[package]
name = "trojan"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
documentation.workspace = true
description = "A Rust implementation of the Trojan protocol"
keywords = ["trojan", "proxy", "tls", "network"]
categories = ["network-programming"]

[workspace]
resolver = "2"
members = [
    "crates/trojan-core",
    "crates/trojan-proto",
    "crates/trojan-auth",
    "crates/trojan-config",
    "crates/trojan-metrics",
    "crates/trojan-analytics",
    "crates/trojan-server",
    "crates/trojan-client",
    "crates/trojan-cert",
    "crates/trojan-rs",
    "crates/trojan-relay",
    "crates/trojan-transport",
]

[workspace.package]
version = "0.3.0"
edition = "2024"
license = "GPL-3.0-only"
authors = ["0x72757374 <257538187+0x72757374@users.noreply.github.com>"]
repository = "https://github.com/trojan-rs/trojan-rs"
homepage = "https://github.com/trojan-rs/trojan-rs"
documentation = "https://docs.rs/trojan"

[workspace.dependencies]
trojan = { version = "0.3.0", path = "." }
trojan-core = { version = "0.3.0", path = "crates/trojan-core" }
trojan-proto = { version = "0.3.0", path = "crates/trojan-proto" }
trojan-auth = { version = "0.3.0", path = "crates/trojan-auth" }
trojan-config = { version = "0.3.0", path = "crates/trojan-config" }
trojan-metrics = { version = "0.3.0", path = "crates/trojan-metrics" }
trojan-analytics = { version = "0.3.0", path = "crates/trojan-analytics" }
trojan-server = { version = "0.3.0", path = "crates/trojan-server" }
trojan-client = { version = "0.3.0", path = "crates/trojan-client" }
trojan-cert = { version = "0.3.0", path = "crates/trojan-cert" }
trojan-relay = { version = "0.3.0", path = "crates/trojan-relay" }
trojan-transport = { version = "0.3.0", path = "crates/trojan-transport" }

[features]
default = ["cli", "sql-sqlite"]
cli = ["trojan-auth/cli", "dep:clap", "dep:tokio"]

# Self-upgrade from GitHub releases (disabled by default, enabled in CI builds)
upgrade = [
    "cli",
    "dep:reqwest",
    "dep:serde",
    "dep:serde_json",
    "dep:self-replace",
    "dep:flate2",
    "dep:tar",
    "dep:sha2",
    "dep:hex",
    "dep:tokio-util",
    "dep:futures-util",
    "dep:tempfile",
    "dep:zip",
]

# Certificate management CLI
cert = ["cli", "dep:trojan-cert"]

# Database drivers for auth CLI
sql-sqlite = ["trojan-auth/sql-sqlite"]
sql-postgres = ["trojan-auth/sql-postgres"]
sql-mysql = ["trojan-auth/sql-mysql"]

[[bin]]
name = "trojan"
path = "src/main.rs"
required-features = ["cli"]

[dependencies]
trojan-core.workspace = true
trojan-proto.workspace = true
trojan-auth.workspace = true
trojan-config.workspace = true
trojan-metrics.workspace = true
trojan-server.workspace = true
trojan-client.workspace = true
trojan-relay.workspace = true
trojan-cert = { workspace = true, optional = true }

# CLI dependencies
clap = { version = "4", features = ["derive"], optional = true }
tokio = { version = "1", features = [
    "rt-multi-thread",
    "macros",
], optional = true }
reqwest = { version = "0.12", default-features = false, features = [
    "json",
    "stream",
    "rustls-tls",
], optional = true }
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
self-replace = { version = "1", optional = true }
flate2 = { version = "1", optional = true }
tar = { version = "0.4", optional = true }
sha2 = { version = "0.10", optional = true }
hex = { version = "0.4", optional = true }
tokio-util = { version = "0.7", features = ["io"], optional = true }
futures-util = { version = "0.3", optional = true }
tempfile = { version = "3", optional = true }

# Windows-only dependencies for upgrade feature
[target.'cfg(windows)'.dependencies]
zip = { version = "2", default-features = false, features = [
    "deflate",
], optional = true }

[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
strip = true
panic = "abort"
