Compile the project.
Synopsis
hx build [OPTIONS]Description
The build command compiles your Haskell project. By default, it builds all components (library, executables, tests, and benchmarks).
hx wraps Cabal’s build system, providing a streamlined interface with better error messages and progress reporting.
Options
Build Options
--release Build with optimizations (-O2)
-j, --jobs <N> Number of parallel jobs (default: number of CPUs)
--lib Build only the library
--exe <NAME> Build only the specified executable
--test Build only tests
--bench Build only benchmarks
--all Build all componentsCompiler Options
--backend <BACKEND> Compiler backend to use [ghc, bhc]
--ghc-options <OPTS> Additional options to pass to GHC
--target <TARGET> Cross-compilation target tripleOutput Options
-v, --verbose Show full compiler output
--timings Show compilation timing information
--progress Show progress bar (default in TTY)Examples
Basic Build
# Build all components with default settings
hx buildRelease Build
# Build with optimizations
hx build --releaseParallel Build
# Use 8 parallel jobs
hx build -j8
# Use all available CPUs
hx build -j0Build Specific Components
# Build only the library
hx build --lib
# Build a specific executable
hx build --exe my-app
# Build only tests (without running)
hx build --testUsing Different Compiler Backends
# Build with GHC (default)
hx build --backend ghc
# Build with BHC (Basel Haskell Compiler)
hx build --backend bhcCross-Compilation
# Build for Linux ARM64
hx build --target aarch64-linux-gnu
# Build for WebAssembly
hx build --target wasm32-wasi --backend bhcCustom GHC Options
# Enable warnings as errors
hx build --ghc-options="-Werror"
# Enable specific extensions
hx build --ghc-options="-XOverloadedStrings -XDeriveGeneric"Configuration
Build behavior can be configured in hx.toml:
[build]
release = false # Default to debug builds
jobs = 4 # Parallel jobs
ghc-options = ["-Wall"] # Default GHC options
split-sections = true # Enable split sections (smaller binaries)
[compiler]
backend = "ghc" # Default compiler backendSee Configuration Reference for all options.
Build Artifacts
Build output is placed in the dist-newstyle directory by default. The exact location of binaries depends on your project configuration:
dist-newstyle/
└── build/
└── <platform>/
└── ghc-<version>/
└── <package>/
└── x/
└── <exe-name>/
└── build/
└── <exe-name>/
└── <exe-name> # The binaryUse hx run to execute binaries without navigating this structure.
Incremental Builds
hx uses Cabal’s incremental build system. Only changed modules are recompiled. To force a full rebuild:
hx clean && hx buildSee Also
- hx run — Build and run the executable
- hx check — Type check without full compilation
- hx clean — Remove build artifacts
- Compiler Backends — Using GHC vs BHC