Skip to content

Commit

Permalink
Merge pull request #173 from dominikwerder/env_vars_for_non_standard_…
Browse files Browse the repository at this point in the history
…ncurses

Environment variables for non-standard ncurses
  • Loading branch information
jeaye committed Jan 8, 2019
2 parents b947210 + 6846a39 commit e06efcc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -4,7 +4,9 @@ ncurses-rs [![Build Status](https://travis-ci.org/jeaye/ncurses-rs.png)](https:/
This is a very thin wrapper around the ncurses TUI lib.

## Building

The compiled library will go to the `target` directory.

```
cargo build
```
Expand All @@ -25,3 +27,13 @@ Current examples:
**6.** [Pager & Syntax Highlighting](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_6.rs)
**7.** [Basic Input & Attributes (Unicode)](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_7.rs)
**8.** [Special ACS Characters](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_8.rs)

## Environment variables

Some environment variables are read by `build.rs`:

If set, `NCURSES_RS_RUSTC_LINK_LIB` will be used for `NCURSES_RS_RUSTC_LINK_LIB`.

If set, `NCURSES_RS_RUSTC_FLAGS` will be used for `cargo:rustc-flags`.

If set, `NCURSES_RS_CFLAGS` will be used for the compilation of the test program `chtype_size.c`.
36 changes: 26 additions & 10 deletions build.rs
Expand Up @@ -14,7 +14,6 @@ fn find_library(names: &[&str]) -> Option<Library> {
return Some(lib);
}
}
println!("cargo:rustc-link-lib={}", names.last().unwrap());
None
}

Expand All @@ -23,11 +22,12 @@ fn main() {

let wide = cfg!(all(feature = "wide", not(target_os = "macos")));

let ncurses_lib = if wide {
find_library(&["ncursesw5", "ncursesw"])
let ncurses_lib_names = if wide {
&["ncursesw5", "ncursesw"]
} else {
find_library(&["ncurses5", "ncurses"])
&["ncurses5", "ncurses"]
};
let ncurses_lib = find_library(ncurses_lib_names);

if cfg!(feature = "menu") {
if wide {
Expand All @@ -45,6 +45,17 @@ fn main() {
}
}

match std::env::var("NCURSES_RS_RUSTC_LINK_LIB") {
Ok(x) => println!("cargo:rustc-link-lib={}", x),
_ => if ncurses_lib.is_none() {
println!("cargo:rustc-link-lib={}", ncurses_lib_names.last().unwrap())
}
}

if let Ok(x) = std::env::var("NCURSES_RS_RUSTC_FLAGS") {
println!("cargo:rustc-flags={}", x);
}

check_chtype_size(&ncurses_lib);
}

Expand Down Expand Up @@ -77,16 +88,21 @@ int main(void)
}
").expect(&format!("cannot write into {}", src));

let compiler = cc::Build::new().get_compiler();

let mut compile_cmd = Command::new(compiler.path());
compile_cmd.arg(&src).arg("-o").arg(&bin);
let mut build = cc::Build::new();
if let Some(lib) = ncurses_lib {
for path in lib.include_paths.iter() {
compile_cmd.arg("-I").arg(path);
build.include(path);
}
}
compile_cmd.status().expect("compilation failed");
let compiler = build.try_get_compiler().expect("Failed Build::try_get_compiler");
let mut command = compiler.to_command();

if let Ok(x) = std::env::var("NCURSES_RS_CFLAGS") {
command.args(x.split(" "));
}

command.arg("-o").arg(&bin).arg(&src);
assert!(command.status().expect("compilation failed").success());
let features = Command::new(&bin).output()
.expect(&format!("{} failed", bin));
print!("{}", String::from_utf8_lossy(&features.stdout));
Expand Down

0 comments on commit e06efcc

Please sign in to comment.