Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPrint proper cargo:include values #139
Conversation
This prints proper values for cargo:include in the build script for both the pkg-config and vendored cases.
|
Oh, I forgot to mention one thing. Currently, the |
|
Well, I've now discovered |
|
That seems valuable. |
|
I think #140 provides a satisfactory answer to the testing issue (for me, at least). Any thoughts on the other two issues ( BTW, I think this PR is a self-contained improvement and useful to me. If you wanted to postpone dealing with the other issues, merge this, and make a release, I wouldn't complain. |
|
Okay, my ignorance is gradually dissipating. For the |
|
@bors-servo r+ |
|
|
Print proper cargo:include values
In order to build a Rust crate with C/C++ that uses the HarfBuzz library referenced by the `harfbuzz` crate, I need to know where the header files are. I believe the standard way of doing that is the `links` key/value environment variables. In particular, I'm expecting `DEP_HARFBUZZ_INCLUDE` to tell me the include path for `hb.h` and other header files. Unfortunately, this doesn't seem to be working correctly now. This PR is an attempt to resolve that.
Summary of changes:
* Prints proper values for `cargo:include` in the build script for both the `pkg-config` and vendored cases.
* Changes a use of `to_str().unwrap()` to `PathBuf::display()`. I believe this is better, but I'm happy to be corrected.
As far as adding a useful feature goes, I think this PR is complete. However, there are a couple of potential improvements that would be nice, but I'm not sure how to go about them.
**`not(feature = "build-native-harfbuzz")`**
I'm not exactly sure what disabling the feature `build-native-harfbuzz` does. It doesn't use `pkg-config` and doesn't build the vendored library? Consequently I'm not sure what to print for `cargo:include` here.
**Testing**
It would be nice to test for the presence and correctness of `DEP_HARFBUZZ_INCLUDE`. I used the following files (in the repository's top-level directory for convenience) both with `HARFBUZZ_SYS_NO_PKG_CONFIG=1` and without:
`Cargo.toml`:
```toml
[project]
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
[dependencies]
harfbuzz-sys = { path = "harfbuzz-sys" }
[build-dependencies]
cc = "1.0"
```
`build.rs`:
```rust
use std::env;
fn main() {
let mut cfg = cc::Build::new();
for path in env::split_paths(&env::var_os("DEP_HARFBUZZ_INCLUDE").unwrap()) {
cfg.include(path);
}
cfg.file("src/test.c").warnings(false).compile("test");
}
```
`src/test.c`:
```c
#include <hb.h>
int test() {
hb_font_t *hb_font;
return 0;
}
```
`src/lib.rs`: empty
I'm not sure how to add such a test without simply writing a script and running it in CI. I did a quick search on GitHub and couldn't find any other projects that actually tested `cargo:include` in this way.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-harfbuzz/139)
<!-- Reviewable:end -->
|
|
Add harfbuzz-sys-test using ctest This adds a crate to the workspace for testing `harfbuzz-sys` automatically using `ctest`. I changed a few types in `harfbuzz-sys/src/lib.rs` to make the testing automatic (i.e. to avoid creating special cases). However, I suppose `lib.rs` is generated? If so, this might be problematic if it is regenerated later. The changes seem quite sensible to me, so maybe there's an alternative to tweak the generation to get something similar? `harfbuzz-sys-test` currently only works with `HARFBUZZ_SYS_NO_PKG_CONFIG=1` because it doesn't get the `DEP_HARFBUZZ_INCLUDE` environment variable otherwise. The `.travis.yml` change reflects that. If #139 or something similar is merged, this special case can be removed, and the test should be run for both `HARFBUZZ_SYS_NO_PKG_CONFIG=1` and without `HARFBUZZ_SYS_NO_PKG_CONFIG`. There's a `FIXME` in `harfbuzz-sys-test/build.rs` because I don't understand the errors when these functions are not skipped. I would appreciate it if someone else would take a look at that. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-harfbuzz/140) <!-- Reviewable:end -->
|
Thanks! |
spl commentedMar 28, 2019
•
edited by larsbergstrom
In order to build a Rust crate with C/C++ that uses the HarfBuzz library referenced by the
harfbuzzcrate, I need to know where the header files are. I believe the standard way of doing that is thelinkskey/value environment variables. In particular, I'm expectingDEP_HARFBUZZ_INCLUDEto tell me the include path forhb.hand other header files. Unfortunately, this doesn't seem to be working correctly now. This PR is an attempt to resolve that.Summary of changes:
cargo:includein the build script for both thepkg-configand vendored cases.to_str().unwrap()toPathBuf::display(). I believe this is better, but I'm happy to be corrected.As far as adding a useful feature goes, I think this PR is complete. However, there are a couple of potential improvements that would be nice, but I'm not sure how to go about them.
not(feature = "build-native-harfbuzz")I'm not exactly sure what disabling the feature
build-native-harfbuzzdoes. It doesn't usepkg-configand doesn't build the vendored library? Consequently I'm not sure what to print forcargo:includehere.Testing
It would be nice to test for the presence and correctness of
DEP_HARFBUZZ_INCLUDE. I used the following files (in the repository's top-level directory for convenience) both withHARFBUZZ_SYS_NO_PKG_CONFIG=1and without:Cargo.toml:build.rs:src/test.c:src/lib.rs: emptyI'm not sure how to add such a test without simply writing a script and running it in CI. I did a quick search on GitHub and couldn't find any other projects that actually tested
cargo:includein this way.This change is