# The Cargo workspace configuration shared by in-kernel crates.
#
# Most crates in Asterinas are written and built for the kernel space.
# The user-space and host-native exceptions are listed in `workspace.exclude`.

[workspace]
resolver = "2"
# All in-kernel crates.
#
# These crates share a single workspace
# so their `Cargo.toml` files do not need to repeat common settings.
members = [
    "osdk/deps/frame-allocator",
    "osdk/deps/heap-allocator",
    "osdk/deps/test-kernel",
    "ostd",
    "ostd/libs/align_ext",
    "ostd/libs/id-alloc",
    "ostd/libs/int-to-c-enum",
    "ostd/libs/int-to-c-enum/derive",
    "ostd/libs/linux-bzimage/boot-params",
    "ostd/libs/linux-bzimage/builder",
    "ostd/libs/linux-bzimage/setup",
    "ostd/libs/ostd-pod",
    "ostd/libs/ostd-pod/macros",
    "ostd/libs/ostd-macros",
    "ostd/libs/ostd-test",
    "ostd/libs/padding-struct",
    "kernel",
    "kernel/comps/block",
    "kernel/comps/cmdline",
    "kernel/comps/console",
    "kernel/comps/framebuffer",
    "kernel/comps/i8042",
    "kernel/comps/input",
    "kernel/comps/logger",
    "kernel/comps/mlsdisk",
    "kernel/comps/network",
    "kernel/comps/pci",
    "kernel/comps/softirq",
    "kernel/comps/systree",
    "kernel/comps/time",
    "kernel/comps/uart",
    "kernel/comps/virtio",
    "kernel/libs/aster-bigtcp",
    "kernel/libs/aster-rights",
    "kernel/libs/aster-rights-proc",
    "kernel/libs/aster-util",
    "kernel/libs/atomic-integer-wrapper",
    "kernel/libs/cpio-decoder",
    "kernel/libs/device-id",
    "kernel/libs/jhash",
    "kernel/libs/keyable-arc",
    "kernel/libs/logo-ascii-art",
    "kernel/libs/ring-buffer",
    "kernel/libs/typeflags",
    "kernel/libs/typeflags-util",
    "kernel/libs/xarray",
]
# All OSDK-based in-kernel crates.
#
# Use `cargo osdk <cmd>` for these crates.
# When adding a workspace crate that depends on OSTD,
# include it in `default-members`
# unless it requires special handling,
# such as only compiling on specific architectures
# or relying on its own Cargo configuration.
default-members = [
    "osdk/deps/frame-allocator",
    "osdk/deps/heap-allocator",
    "osdk/deps/test-kernel",
    "ostd",
    "kernel",
    "kernel/comps/block",
    "kernel/comps/cmdline",
    "kernel/comps/console",
    "kernel/comps/framebuffer",
    "kernel/comps/i8042",
    "kernel/comps/input",
    "kernel/comps/logger",
    "kernel/comps/mlsdisk",
    "kernel/comps/network",
    "kernel/comps/pci",
    "kernel/comps/softirq",
    "kernel/comps/systree",
    "kernel/comps/time",
    "kernel/comps/uart",
    "kernel/comps/virtio",
    "kernel/libs/aster-bigtcp",
    "kernel/libs/aster-util",
    "kernel/libs/device-id",
    "kernel/libs/ring-buffer",
    "kernel/libs/xarray",
]
# All user-space or host-native crates.
#
# Use plain `cargo <cmd>` for these crates.
# Their crate-level `Cargo.toml` files are not affected
# by the shared in-kernel workspace configuration.
exclude = [
    "kernel/libs/comp-sys/cargo-component",
    "kernel/libs/comp-sys/component",
    "kernel/libs/comp-sys/component-macro",
    "kernel/libs/comp-sys/controlled",
    "osdk",
    "tools/sctrace",
]

[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "warn"
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(ktest)'] }

[workspace.lints.clippy]
allow_attributes = "warn"
redundant_test_prefix = "warn"

# Keys under `workspace.package` and the `package` section of each crate 
# follow the ordering suggested at: 
# https://github.com/crate-ci/cargo-cargofmt/issues/29#issuecomment-3647516745
# 
# FIXME: The current key order is not yet finalized.
# Once `cargo-cargofmt` becomes stable, we will use it to enforce a consistent key order.
[workspace.package]
version = "0.17.2"
repository = "https://github.com/asterinas/asterinas"
license = "MPL-2.0"
edition = "2024"

[workspace.dependencies]
ostd = { version = "0.17.2", path = "ostd" }

# Crates under ostd/libs
align_ext = { path = "ostd/libs/align_ext", version = "0.1.0" }
id-alloc = { path = "ostd/libs/id-alloc", version = "0.1.0" }
int-to-c-enum = { path = "ostd/libs/int-to-c-enum", version = "0.1.0" }
linux-boot-params = { version = "0.17.2", path = "ostd/libs/linux-bzimage/boot-params" }
ostd-macros = { version = "0.17.2", path = "ostd/libs/ostd-macros" }
ostd-pod = { path = "ostd/libs/ostd-pod", version = "0.4.0" }
ostd-test = { version = "0.17.2", path = "ostd/libs/ostd-test" }

# Crates under kernel/comps
aster-block = { path = "kernel/comps/block" }
aster-cmdline = { path = "kernel/comps/cmdline" }
aster-console = { path = "kernel/comps/console" }
aster-framebuffer = { path = "kernel/comps/framebuffer" }
aster-i8042 = { path = "kernel/comps/i8042" }
aster-input = { path = "kernel/comps/input" }
aster-logger = { path = "kernel/comps/logger" }
aster-mlsdisk = { path = "kernel/comps/mlsdisk" }
aster-network = { path = "kernel/comps/network" }
aster-pci = { path = "kernel/comps/pci" }
aster-softirq = { path = "kernel/comps/softirq" }
aster-systree = { path = "kernel/comps/systree" }
aster-time = { path = "kernel/comps/time" }
aster-uart = { path = "kernel/comps/uart" }
aster-virtio = { path = "kernel/comps/virtio" }

# Crates under kernel/libs
aster-bigtcp = { path = "kernel/libs/aster-bigtcp" }
aster-rights = { path = "kernel/libs/aster-rights" }
aster-rights-proc = { path = "kernel/libs/aster-rights-proc" }
aster-util = { path = "kernel/libs/aster-util" }
atomic-integer-wrapper = { path = "kernel/libs/atomic-integer-wrapper" }
cpio-decoder = { path = "kernel/libs/cpio-decoder" }
device-id = { path = "kernel/libs/device-id" }
jhash = { path = "kernel/libs/jhash" }
keyable-arc = { path = "kernel/libs/keyable-arc" }
logo-ascii-art = { path = "kernel/libs/logo-ascii-art" }
ring-buffer = { path = "kernel/libs/ring-buffer" }
typeflags = { path = "kernel/libs/typeflags" }
typeflags-util = { path = "kernel/libs/typeflags-util" }
xarray = { path = "kernel/libs/xarray" }

# Crates under kernel/libs/comp-sys
component = { path = "kernel/libs/comp-sys/component" }
controlled = { path = "kernel/libs/comp-sys/controlled" }

# Crates under osdk/deps
osdk-frame-allocator = { path = "osdk/deps/frame-allocator" }
osdk-heap-allocator = { path = "osdk/deps/heap-allocator" }

# External dependencies only for unsafe crates (i.e., crates under ostd directory)
bit_field = "0.10.1"
gimli = { version = "0.28", default-features = false, features = ["read-core"] }
minicov = "0.3"
num-traits = { version = "0.2", default-features = false }
serde = { version = "1.0.192", default-features = false, features = ["alloc", "derive"] }
smallvec = "1.13.2"
uart_16550 = "0.3.0"
volatile = "0.6.1"

# External dependencies only for safe crates (i.e., crates under kernel or osdk/deps directories)
#
# Enable `force-soft` feature to disable `AES-NI` and `CLMUL` intrinsics, ensuring that the implementation
# relies solely on software, and in the software implementation, unsafe code is rarely used.
# FIXME: to utilize `AES-NI` and `CLMUL` intrinsics, some specific flags must be added to `RUSTFLAGS`,
# i.e. `-Ctarget-cpu=sandybridge -Ctarget-feature=+aes,+sse2,+sse4.1,+ssse3`.
# This suggests that `Asterinas` should support saving and restoring the `FPU` state within the kernel context,
# a capability it currently lacks.
aes-gcm = { version = "0.9.4", features = ["force-soft"] }
bittle = "0.5.6"
const_format = "0.2.35"
ctr = "0.8.0"
font8x8 = { version = "0.2.5", default-features = false, features = [ "unicode" ] }
getset = "0.1.2"
hashbrown = { version = "0.14.3", features = ["serde"]  }
inventory = { git = "https://github.com/asterinas/inventory", rev = "9dce587" }
itertools = "0.10.5"
lending-iterator = "0.1.7"
lru = "0.16.3"
owo-colors = "4.2.2"
paste = "1.0.15"
postcard = "1.0.6"
smoltcp = { git = "https://github.com/asterinas/smoltcp", tag = "r_2024-11-08_f07e5b5", default-features = false, features = [
    "alloc",
    "log",
    "medium-ethernet",
    "medium-ip",
    "proto-ipv4",
    "socket-udp",
    "socket-tcp",
] }
takeable = "0.2.2"
time = { version = "0.3", default-features = false, features = ["alloc"] }

# External dependencies for both safe and unsafe crates
bitflags = "1.3"
bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] }
cfg-if = "1.0"
inherit-methods-macro = { git = "https://github.com/asterinas/inherit-methods-macro", rev = "98f7e3e", version = "0.1.0" }
intrusive-collections = { version = "0.9.6", features = ["nightly"] }
libflate = { version = "2.3.0", default-features = false }
log = "0.4"
no_std_io2 = { version = "0.9.3", default-features = false, features = ["alloc", "nightly"] }
rand = { version = "0.9.2", default-features = false }
spin = "0.9.4"
xmas-elf = "0.10.0"
# Note: when updating the zerocopy version, 
# also update it in `ostd/libs/ostd-pod/README.md`.
zerocopy = { version = "0.8.34", features = [ "derive" ] }

# Proc-macro dependencies
proc-macro2 = { version = "1.0.95", features = ["span-locations"] }
quote = "1.0.35"
syn = { version = "2.0.77", features = ["full", "parsing", "fold"] }

# Cargo only looks at the profile settings 
# in the Cargo.toml manifest at the root of the workspace

[profile.dev]
panic = "unwind"

[profile.release]
lto = "thin"
panic = "unwind"

# Release profile configuration with Link Time Optimization (LTO) enabled.
#
# This profile is optimized for maximum runtime performance, 
# (achieving a 2% reduction in latency for the getpid system call).
# However, enabling LTO significantly increases compilation times,
# approximately doubling them compared to when LTO is not enabled.
[profile.release-lto]
inherits = "release"
lto = true
# lto can only be enabled when panic strategy is abort
panic = "abort"
# set codegen-units as the smallest number
codegen-units = 1
