Skip to content

Commit

Permalink
Merge pull request #55 from lnicola/bindgen
Browse files Browse the repository at this point in the history
Use bindgen for gdal-sys
  • Loading branch information
jdroenner authored Mar 10, 2018
2 parents e9d9887 + 0c09a67 commit 615267b
Show file tree
Hide file tree
Showing 47 changed files with 37,531 additions and 1,117 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rust:

script:
- cargo test
- cargo test --features bindgen
- cargo doc

after_success: |
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changes

## 0.4.0
* [Use `bindgen` to generate the low-level bindings](https://github.com/georust/rust-gdal/pull/55)

## 0.3.0

* [Add support for creating a SpatialRef from a esri "wkt" definition](https://github.com/georust/rust-gdal/pull/37)
Expand Down
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
name = "gdal"
description = "GDAL bindings for Rust"
license = "MIT"
version = "0.3.1"
version = "0.4.0"
authors = ["Alex Morega <[email protected]>"]
repository = "https://github.com/georust/rust-gdal"
documentation = "https://georust.github.io/rust-gdal/"

[features]
bindgen = ["gdal-sys/bindgen"]

[dependencies]
error-chain = "0.11"
libc = "0.2"
geo = "0.6"
gdal-sys = { path = "gdal-sys", version = "0.1"}
num-traits = "0.1"
geo = "0.7"
gdal-sys = { path = "gdal-sys", version = "0.2"}
num-traits = "0.2"

[workspace]
members = ["gdal-sys"]
6 changes: 3 additions & 3 deletions examples/read_write_ogr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn run() -> Result<(), Error> {
for fd in &fields_defn {
let field_defn = FieldDefn::new(&fd.0, fd.1)?;
field_defn.set_width(fd.2);
field_defn.add_to_layer(&lyr)?;
field_defn.add_to_layer(lyr)?;
}

// Prepare the origin and destination spatial references objects:
Expand All @@ -34,7 +34,7 @@ fn run() -> Result<(), Error> {
let htransform = CoordTransform::new(&spatial_ref_src, &spatial_ref_dst)?;

// Get the definition to use on each feature:
let defn = Defn::from_layer(&lyr);
let defn = Defn::from_layer(lyr);

for feature_a in layer_a.features() {
// Get the original geometry:
Expand All @@ -49,7 +49,7 @@ fn run() -> Result<(), Error> {
ft.set_field(&fd.0, &feature_a.field(&fd.0)?)?;
}
// Add the feature to the layer:
ft.create(&lyr)?;
ft.create(lyr)?;
}

Ok(())
Expand Down
12 changes: 6 additions & 6 deletions examples/write_ogr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ fn example_1() -> Result<(), Error> {

let field_defn = FieldDefn::new("Name", OGRFieldType::OFTString)?;
field_defn.set_width(80);
field_defn.add_to_layer(&lyr)?;
field_defn.add_to_layer(lyr)?;

let field_defn = FieldDefn::new("Value", OGRFieldType::OFTReal)?;
field_defn.add_to_layer(&lyr)?;
field_defn.add_to_layer(lyr)?;

let defn = Defn::from_layer(&lyr);
let defn = Defn::from_layer(lyr);

// 1st feature:
let mut ft = Feature::new(&defn)?;
ft.set_geometry(Geometry::from_wkt("POINT (45.21 21.76)")?)?;
ft.set_field_string("Name", "Feature 1")?;
ft.set_field_double("Value", 45.78)?;
ft.create(&lyr)?;
ft.create(lyr)?;

// 2nd feature:
let mut ft = Feature::new(&defn)?;
ft.set_field_double("Value", 0.789)?;
ft.set_geometry(Geometry::from_wkt("POINT (46.50 22.50)")?)?;
ft.set_field_string("Name", "Feature 2")?;
ft.create(&lyr)?;
ft.create(lyr)?;

// Feature triggering an error due to a wrong field name:
let mut ft = Feature::new(&defn)?;
Expand All @@ -44,7 +44,7 @@ fn example_1() -> Result<(), Error> {
Ok(v) => v,
Err(err) => println!("{}", err),
};
ft.create(&lyr)?;
ft.create(lyr)?;

Ok(())
}
Expand Down
16 changes: 13 additions & 3 deletions gdal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
name = "gdal-sys"
description = "Low level GDAL bindings for Rust"
license = "MIT"
version = "0.1.1"
version = "0.2.0"
repository = "https://github.com/georust/rust-gdal"
authors = ["Johannes Drönner <[email protected]>"]
build="build.rs"

[features]
default = ["min_gdal_version_1_11"]
min_gdal_version_1_11 = []
min_gdal_version_2_0 = []
min_gdal_version_2_1 = []
min_gdal_version_2_2 = []

[dependencies]
libc = "0.2"
libc = "0.2"

[build-dependencies]
bindgen = { git = "https://github.com/rust-lang-nursery/rust-bindgen", rev="f36f4e3", optional = true }
pkg-config = "0.3"
57 changes: 36 additions & 21 deletions gdal-sys/Readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
# gdal-sys

[![Build Status](https://travis-ci.org/georust/rust-gdal.png?branch=master)](https://travis-ci.org/georust/rust-gdal)

Low level [GDAL](http://gdal.org/) bindings for [Rust](http://www.rust-lang.org/).

Contains:

* mapping of data types
* raster (GDAL) and vector (ORG) operations
* error handling
* spatial reference operations

## build

The build script should work an Linux and Windows systems.

On Windows the `GDAL_HOME` environment variable is expected to point to the `GDAL` folder.

* windows-msvc requires `gdal_i.lib` to be found in `GDAL_HOME\lib`.
* windows-gnu requires either `gdal_i.lib` in `GDAL_HOME\lib` OR `gdal{version}.dll` in `GDAL_HOME\bin`.
# gdal-sys

[![Build Status](https://travis-ci.org/georust/rust-gdal.png?branch=master)](https://travis-ci.org/georust/rust-gdal)

Low level [GDAL](http://gdal.org/) bindings for [Rust](http://www.rust-lang.org/).

Contains:

* mapping of data types
* raster (GDAL) and vector (OGR) operations
* error handling
* spatial reference operations

## Build

The build script should work an Linux and Windows systems. It can be configured with a couple of environment variables:

* if `GDAL_INCLUDE_DIR` or `GDAL_LIB_DIR` are defined, they will be used
* otherwise, if `GDAL_HOME` is defined, the build script looks for `GDAL_HOME/include`, `GDAL_HOME/lib` and `GDAL_HOME/bin`
* finally, `pkg-config` is queried to determine the `GDAL` location
* you can define `GDAL_STATIC` to link `GDAL` statically

The include directories are only used if you choose to generate the bindings at build time.

On Linux, building should work out-of-the-box.

On Windows, the easiest solution is to point the `GDAL_HOME` environment variable to the `GDAL` folder.

* `windows-msvc` requires `gdal_i.lib` to be found in `%GDAL_HOME%\lib`.
* `windows-gnu` requires either `gdal_i.lib` in `%GDAL_HOME%\lib` OR `gdal{version}.dll` in `%GDAL_HOME%\bin`.

## Pre-generated bindings

By default, the bundled bindings will be used. To generate them when building the crate, the `bindgen` feature must be enabled.

You can enable one of the `min_gdal_version_X_Y` features to pick a specific version of the pre-generated bindings. For more information, see the [Cargo.toml](Cargo.toml) file.
Loading

0 comments on commit 615267b

Please sign in to comment.