Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huonw/compile_msg
Compile-time user-defined diagnostics
https://github.com/huonw/compile_msg
Last synced: 8 days ago
JSON representation
Compile-time user-defined diagnostics
- Host: GitHub
- URL: https://github.com/huonw/compile_msg
- Owner: huonw
- License: apache-2.0
- Created: 2014-08-11T21:52:10.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-05-02T13:00:43.000Z (7 months ago)
- Last Synced: 2024-10-31T13:50:16.234Z (15 days ago)
- Language: Rust
- Homepage:
- Size: 213 KB
- Stars: 17
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# compile_msg
[![Build Status](https://travis-ci.org/huonw/compile_msg.png)](https://travis-ci.org/huonw/compile_msg)
A syntax extension for emitting messages at compile time, via the
compiler, similar to `#warning` and `#error` in the C
preprocessor. Four macros are provided (in order of increasing
severity):- `compile_note`: tell the user a tidbit of information without implying it is a problem,
- `compile_warning`: tell the user that something could go wrong,
- `compile_error`: tell the user about some error, compilation will
not stop immediately, but will halt before any compiler passes after
macro expansion.
- `compile_fatal`: tell the user about a catastrophic error and
immediately halt compilation. `compile_error` is *strongly*
preferred as it allows further errors and warnings to be picked up
in a single pass.The macros can be placed as an item (expanding to nothing), and as an
expression (expanding to a literal unit, i.e. `()`). They are best
used in conditionally compiled items, e.g. if a certain operating
system is entirely unsupported, one can use `compile_error!` with an
appropriate `#[cfg]` attribute.## Usage
Ensure your `Cargo.toml` contains:
```toml
[dependencies]
compile_msg = "0"
```and then load the syntax in the normal manner:
```rust
#![feature(plugin)]#[plugin] extern crate compile_msg;
#[cfg(target_os = "hal")]
compile_error!("I'm sorry, Dave, I'm afraid I can't do that.");fn main() {
compile_note!("please be careful"); // note: please be carefulcompile_warning!("take more care"); // warning: take more care
compile_error!("things are breaking"); // error: things are breaking
compile_fatal!("catastrophic failure!"); // error: catastrophic failure
// (compilation stops here)compile_warning!("not emitted");
}
```(If that compiled, it would be equivalent to `fn main() {}` at runtime.)