package config

  1. Overview
  2. Docs
Ergonomic, lightweight conditional compilation through attributes

Install

Dune Dependency

Authors

Maintainers

Sources

config-0.0.1.tbz
sha256=334d3c92993033388f5fbacd8ee36d15dcff35d03626f0215279594a208aa19c
sha512=1a494f4a3e6fedc570c4949485e80154c6262b0e99c389c31b10801306e1a7f7b7d2193bc3f0fb4ae331e49838e6ac11eff6c024328aa833573ed4b99bf03176

Description

Config implements the [@@config] annotation, to conditionally compile modules. You can use a small boolean language to check for conditions including some built-in ones and environment variables.

README

config.ml

Ergonomic, lightweight conditional compilation through attributes inspired by Rust's cfg macro.

Config implements the [@@config] annotation, to conditionally compile modules. You can use a small boolean language to check for conditions including some built-in ones and environment variables.

Currently includes/detects the following platforms:

  • Windows 32/64

  • macOS/tvOS/watchOS/iOS

  • FreeBSD/NetBSD

  • Android

  • Linux

And the following architectures:

  • x86-64

  • x86 i386

  • aarch64

  • arm

Getting Started

opam install config

And add it to your dune files:

(library
  (name my_lib)
  (preprocess (pps config.ppx)))

And tag your modules with the @@config attribute:

module A = A_unix [@@config any(target_os = "macos", target_os = "linux")]
module A = A_win32 [@@config any(target_os = "windows")]

Contributing

Currently config relies on C preprocessor definitions to detect different platforms and architectures. They are straightforward to add by extending the file ./config/config_stubs.cl. In there :

  • To add a new platform, extend the main if-else chain in the caml_config_target_os function to include your OS.

  • To add a new architecture, extend the main if-else chain in the caml_config_target_arch function to include your architecture.

Dependencies (5)

  1. dune >= "3.11"
  2. spices >= "0.0.2"
  3. sedlex >= "3.2"
  4. ppxlib >= "0.31.0"
  5. ocaml >= "5.1"

Dev Dependencies (1)

  1. odoc with-doc

Used by (1)

  1. libc

Conflicts

None