mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-19 10:55:46 +00:00
80 lines
2.4 KiB
Markdown
80 lines
2.4 KiB
Markdown
# Coding and building
|
|
|
|
This file provides guidance on coding style and approaches and on building the code.
|
|
|
|
## Code Style and Formatting
|
|
|
|
The project uses **fourmolu** for Haskell code formatting. Configuration is in `fourmolu.yaml`.
|
|
|
|
**Key formatting rules:**
|
|
- 2-space indentation
|
|
- Trailing function arrows, commas, and import/export style
|
|
- Record brace without space: `{field = value}`
|
|
- Single newline between declarations
|
|
- Never use unicode symbols
|
|
- Inline `let` style with right-aligned `in`
|
|
|
|
**Format code before committing:**
|
|
|
|
```bash
|
|
# Format a single file
|
|
fourmolu -i src/Simplex/Messaging/Protocol.hs
|
|
```
|
|
|
|
Some files that use CPP language extension cannot be formatted as a whole, so individual code fragments need to be formatted.
|
|
|
|
**Follow existing code patterns:**
|
|
- Match the style of surrounding code
|
|
- Use qualified imports with short aliases (e.g., `import qualified Data.ByteString.Char8 as B`)
|
|
- Use record syntax for types with multiple fields
|
|
- Prefer explicit pattern matching over partial functions
|
|
|
|
**Comments policy:**
|
|
- Avoid redundant comments that restate what the code already says
|
|
- Only comment on non-obvious design decisions or tricky implementation details
|
|
- Function names and type signatures should be self-documenting
|
|
- Do not add comments like "wire format encoding" (Encoding class is always wire format) or "check if X" when the function name already says that
|
|
- Assume a competent Haskell reader
|
|
|
|
### Haskell Extensions
|
|
- `StrictData` enabled by default
|
|
- Use STM for safe concurrency
|
|
- Assume concurrency in PostgreSQL queries
|
|
- Comprehensive warning flags with strict pattern matching
|
|
|
|
## Build Commands
|
|
|
|
```bash
|
|
# Standard build
|
|
cabal build
|
|
|
|
# Fast build
|
|
cabal build --ghc-options -O0
|
|
|
|
# Build specific executables
|
|
cabal build exe:smp-server exe:xftp-server exe:ntf-server exe:xftp
|
|
|
|
# Build with PostgreSQL server support
|
|
cabal build -fserver_postgres
|
|
|
|
# Client-only library build (no server code)
|
|
cabal build -fclient_library
|
|
|
|
# Find binary location
|
|
cabal list-bin exe:smp-server
|
|
```
|
|
|
|
### Cabal Flags
|
|
|
|
- `swift`: Enable Swift JSON format
|
|
- `client_library`: Build without server code
|
|
- `client_postgres`: Use PostgreSQL instead of SQLite for agent persistence
|
|
- `server_postgres`: PostgreSQL support for server queue/notification store
|
|
|
|
## External Dependencies
|
|
|
|
Custom forks specified in `cabal.project`:
|
|
- `aeson`, `hs-socks` (SimpleX forks)
|
|
- `direct-sqlcipher`, `sqlcipher-simple` (encrypted SQLite)
|
|
- `warp`, `warp-tls` (HTTP server)
|