Skip to content

Commit

Permalink
Break compilation for invalid feature combinations.
Browse files Browse the repository at this point in the history
Sadly our feature matrix is not orthogonal.  Some flag combinations don't
make sense together, and may even fail the compilation in confusing ways.

This commit changes the code to fail to compile when incompatible
feature sets are used.

Closes #129.
  • Loading branch information
filmil committed Jun 19, 2020
1 parent 26db294 commit 1011dad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ confusing compilation end result.

| Feature | Default? | Description |
| ------- | -------- | ----------- |
| `bindgen` | Yes | If set, cargo will run `bindgen` to generate bindings based on the installed ICU library. The program `icu-config` must be in $PATH for this to work. In the future there may be other approaches for auto-detecting libraries, such as via `pkg-config`. |
| `use-bindgen` | Yes | If set, cargo will run `bindgen` to generate bindings based on the installed ICU library. The program `icu-config` must be in $PATH for this to work. In the future there may be other approaches for auto-detecting libraries, such as via `pkg-config`. |
| `renaming` | Yes | If set, ICU bindings are generated with version numbers appended. This is called "renaming" in ICU, and is normally needed only when linking against specific ICU version is required, for example to work around having to link different ICU versions. See [the ICU documentation](http://userguide.icu-project.org/design) for a discussion of renaming. **This feature MUST be used when `bindgen` is NOT used.** |
| `icu_config` | Yes | If set, the binary icu-config will be used to configure the library. Turn this feature off if you do not want `build.rs` to try to autodetect the build environment. You will want to skip this feature if your build environment configures ICU in a different way. **This feature is only meaningful when `bindgen` feature is used; otherwise it has no effect.** |
| `icu_version_in_env` | No | If set, ICU bindings are made for the ICU version specified in the environment variable `RUST_ICU_MAJOR_VERSION_NUMBER`, which is made available to cargo at build time. See section below for details on how to use this feature. **This feature is only meaningful when `bindgen` feature is NOT used; otherwise it has no effect.** |
Expand Down
13 changes: 13 additions & 0 deletions rust_icu_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
unused_imports
)]

#[cfg(all(feature="icu_version_in_env", feature="icu_config"))]
compile_error!(
"Features `icu_version_in_env` and `icu_config` are not compatible." +
" Choose at most one of them.");

#[cfg(all(feature="icu_config", not(feature="use-bindgen")))]
compile_error!("Feature `icu_config` is useless without the feature `use-bindgen`");

// This feature combination is not inherrently a problem; we had no use case that
// required it just yet.
#[cfg(all(not(feature="renaming"), not(feature="use-bindgen")))]
compile_error!("You must use `renaming` when not using `use-bindgen`");

#[cfg(feature="use-bindgen")]
include!(concat!(env!("OUT_DIR"), "/macros.rs"));
#[cfg(all(feature="use-bindgen",feature="icu_config",not(feature="icu_version_in_env")))]
Expand Down

0 comments on commit 1011dad

Please sign in to comment.