Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: migrate geos-sys to bindgen and prebuilt GEOS bindings #113

Merged
merged 32 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6245542
WIP: initial setup of bindgen workflow
brendan-ward Jun 17, 2022
baad1ab
Fix bugs in building static version and build of geos-src
brendan-ward Jun 17, 2022
b475439
Add bindings for GEOS 3.7 - 3.11beta2, fix build script
brendan-ward Jun 18, 2022
d8602f6
Try to fix CI, fix clippy errors
brendan-ward Jun 18, 2022
898166c
Try to fix CI syntax error
brendan-ward Jun 18, 2022
e3c1236
Try again to fix CI syntax
brendan-ward Jun 18, 2022
976279b
Fix typo
brendan-ward Jun 18, 2022
8223cf6
Use correct ninja package
brendan-ward Jun 18, 2022
4d2723e
Try again to fix CI
brendan-ward Jun 18, 2022
82b493e
More logging for git
brendan-ward Jun 18, 2022
36e2036
Try without quoting
brendan-ward Jun 18, 2022
d8ce417
try to discover GEOS via geos-config
brendan-ward Jun 18, 2022
ef8428e
try just linking to geos_c
brendan-ward Jun 18, 2022
16f3274
Try to use ccache to speed up GEOS builds
brendan-ward Jun 18, 2022
125c896
Just use env vars for build again
brendan-ward Jun 18, 2022
d441afa
Move binding generation to separate crate, only use prebuilt bindings…
brendan-ward Jun 22, 2022
b1b3931
Fix missed f64 => c_double
brendan-ward Jun 22, 2022
ee20878
Fix CI typos
brendan-ward Jun 22, 2022
2dab361
Fix use of version features
brendan-ward Jun 22, 2022
2e8c30e
Fix lint errors
brendan-ward Jun 22, 2022
fb959ab
Fix more lint errors
brendan-ward Jun 22, 2022
7c82626
Update bindings, simplify binding generation, PR feedback
brendan-ward Jun 22, 2022
ccc4334
use CLI param for GEOS header file path instead of env vars
brendan-ward Jun 23, 2022
201c7ca
Remove 3.11, simplify CI, don't link to bindings if building docs
brendan-ward Jun 23, 2022
1cec8d6
Fix CI version feature
brendan-ward Jun 23, 2022
49138e6
Fix remove of v3_6_0 from main crate
brendan-ward Jun 23, 2022
41a2f15
Merge branch 'master' into try_bindgen
brendan-ward Jun 29, 2022
30e8232
Add GEOS 3.11 now that officially released
brendan-ward Jul 9, 2022
a740a52
Update submodule to 3.11, update build to use cfg for binding version…
brendan-ward Jul 16, 2022
4153f56
lint fix
brendan-ward Jul 16, 2022
aebdfa9
Use version feature for cfg in lib.rs
brendan-ward Jul 19, 2022
5776845
Fix lint errors
brendan-ward Jul 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 91 additions & 44 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
name: CI

on:
push:
branches: [master]
pull_request:
workflow_dispatch:

name: CI
# cancel running jobs on new commit to PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
rustfmt:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -20,7 +26,7 @@ jobs:
- run: cd sys && cargo fmt -- --check

clippy:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -29,104 +35,145 @@ jobs:
toolchain: nightly
override: true
components: clippy

- name: Install dependencies
run: |
sudo apt update
sudo apt install -y libgeos-dev
- run: cargo clippy -- -D warnings
- run: cd sys && cargo clippy -- -D warnings

check_static:
name: Check static feature
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
LD_LIBRARY_PATH: /usr/local/lib

steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
submodules: "true"

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install dependencies
run: |
sudo apt update
sudo apt install valgrind
sudo apt remove libgeos-dev -y
- name: Install geos
# First we install the 3.8 version of libgeos and then checkout the 3.8.1 version
run: |
git clone https://github.com/libgeos/geos
cd geos
git checkout 24650422b3982f17cc493fe92a70228f2ad624b4
./autogen.sh
./configure
make
sudo make install
sudo ldconfig

- name: Build static geos crate
run: cargo build --features static

check:
name: Check ${{ matrix.toolchain }} / ${{ matrix.triple.target }}
runs-on: ubuntu-latest
name: Check ${{ matrix.toolchain }} / ${{ matrix.geos }} - ${{ matrix.triple.target }}
runs-on: ubuntu-20.04
env:
LD_LIBRARY_PATH: /usr/local/lib
GEOS_LIB_DIR: "/usr/lib/x86_64-linux-gnu"
GEOS_VERSION: ${{ matrix.geos }}

strategy:
fail-fast: false
matrix:
toolchain:
- stable
- nightly
geos: ["3.6.5", "3.7.5", "3.8.3", "3.9.3", "3.10.3", "3.11.0"]
include:
- geos: "3.7.5"
version_feature: "v3_7_0"
- geos: "3.8.3"
version_feature: "v3_8_0"
- geos: "3.9.3"
version_feature: "v3_9_0"
- geos: "3.10.3"
version_feature: "v3_10_0"
- geos: "3.11.0"
version_feature: "v3_11_0"
steps:
- uses: actions/checkout@v2
with:
submodules: "true"

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true

- name: Install dependencies
run: |
sudo apt update
sudo apt install valgrind
sudo apt remove libgeos-dev -y
- name: Install geos
# First we install the 3.8 version of libgeos and then checkout the 3.8.1 version
sudo apt install build-essential ccache ninja-build pkg-config valgrind
sudo /usr/sbin/update-ccache-symlinks

- name: Prepare ccache
run: ccache --clear --set-config cache_dir=~/.ccache

- name: Cache ccache
uses: actions/cache@v2
env:
cache-name: ccache-v1
with:
path: ~/.ccache
key: ${{ env.cache-name }}-${{ matrix.os }}-${{ github.job }}-${{ github.ref }}-${{ github.sha }}-${{ github.head_ref }}
restore-keys: |
${{ env.cache-name }}-${{ matrix.os }}-${{ github.job }}-${{ github.ref }}-${{ github.sha }}
${{ env.cache-name }}-${{ matrix.os }}-${{ github.job }}-${{ github.ref }}
${{ env.cache-name }}-${{ matrix.os }}-${{ github.job }}

- name: Clear ccache statistics
run: |
ccache --zero-stats --set-config cache_dir=~/.ccache
ccache --max-size=2G --set-config cache_dir=~/.ccache
ccache --show-stats --set-config cache_dir=~/.ccache

- name: Install GEOS
run: |
git clone https://github.com/libgeos/geos
cd geos
git checkout 24650422b3982f17cc493fe92a70228f2ad624b4
./autogen.sh
./configure
make
sudo make install
sudo ldconfig
cd sys/geos-src/source
git fetch --unshallow --tags origin
git checkout "tags/${{ matrix.geos }}"
mkdir build
cd build
cmake -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=Release ..
sudo ninja install

- name: Build geos crate
run: |
cargo build
cargo build --features v3_8_0
cargo build --features v3_7_0
cargo build --features v3_6_0
cargo build --features 'geo,json'

- name: Build geos crate for GEOS version > 3.6
if: ${{ matrix.version_feature }}
run: |
cargo build --features ${{ matrix.version_feature }}
cargo build --features '${{ matrix.version_feature }},geo,json'

- name: Run geos tests
run: |
cargo test --features v3_8_0
cargo test --features v3_7_0
cargo test --features v3_6_0
cargo test --features geo
cargo test --features json
cargo test --features 'v3_8_0,geo,json'
cargo test
cargo test --features 'geo,json'

- name: Run geos tests for GEOS version > 3.6
if: ${{ matrix.version_feature }}
run: |
cargo test --features ${{ matrix.version_feature }}
cargo test --features '${{ matrix.version_feature }},geo,json'

- name: Check doc generation
run: |
cargo doc --features dox
cargo doc

- name: Run examples
run: |
cargo run --example verbose_example
cargo run --example prepared_geom
cargo run --features geo --example prepared_geom
cargo run --example from_geo
cargo run --features geo --example from_geo

- name: Check memory leaks
# run valgrind to check that there are no memoryleaks
# Note: cargo seems to randomly name the executable, so we use find to find all the tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/target/
sys/target/
sys/geos-src/target/
geos-sys-bind/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Expand Down
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ readme = "README.md"
edition = "2021"

[features]
json = ["geojson"]
dox = ["geo-types", "wkt", "json"]
geo = ["geo-types", "wkt"]
v3_6_0 = ["geos-sys/v3_6_0"]
json = ["geojson"]
static = ["geos-sys/static"]

v3_6_0 = []
v3_7_0 = ["geos-sys/v3_7_0", "v3_6_0"]
v3_8_0 = ["geos-sys/v3_8_0", "v3_7_0"]
dox = ["geo-types", "wkt", "json"]
static = ["geos-sys/static"]
v3_9_0 = ["geos-sys/v3_9_0", "v3_8_0"]
v3_10_0 = ["geos-sys/v3_10_0", "v3_9_0"]
v3_11_0 = ["geos-sys/v3_11_0", "v3_10_0"]

[dependencies]
libc = "0.2"
Expand Down
13 changes: 13 additions & 0 deletions geos-sys-bind/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "geos-sys-bind"
version = "0.1.0"
edition = "2021"

description = "Generate GEOS C API bindings"

[dependencies]
bindgen = "0.60.1"
clap = { version = "3.2.6", features = ["derive"] }
pkg-config = "0.3.25"
regex = "1.5"
semver = "1.0"
56 changes: 56 additions & 0 deletions geos-sys-bind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# geos-sys-bin

This create builds low level [GEOS](https://libgeos.org/) C API bindings for use
in `geos-sys`.

## Creating bindings

[bindgen](https://docs.rs/bindgen/latest/bindgen/) is used to automatically
create bindings from the GEOS C API.

You need to have the GEOS version for which you want to generate bindings
installed on your system. At minimum, you need to have the `geos_c.h` header
file for that version available (this is created by the GEOS build process).

This crate will attempt to automatically detect your installation of GEOS:

- `pkg-config` is used to automatically detect GEOS >= 3.9
- `geos-config` is used to automatically detect GEOS < 3.9

## Adding a new GEOS version

### 1. Generate new bindings

By default, the bindings are generated against your installed version of GEOS:

```bash
cargo run
```

You can also use the `-h` / `--header` command line flag to specify the location
of the GEOS header file:

```bash
cargo run -- --header <path_to_geos_c.h>
```

This will produce a new binding in
`geos-sys/prebuilt-bindings/geos_<major>.<minor>.rs` based on the major and minor
version of your system-installed GEOS.
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved

Review the contents of this file to determine if there are new bindings that
will be problematic to integrate in Rust, such as data types that vary by
architecture. Common data types are provided using `libc`. You can compare to
bindings from a previous version of GEOS for reference.

### 2. Add feature entry for new version

Add a new feature entry for this GEOS version with the pattern
`"v<major>_<minor>_0"` to `Cargo.toml` in the root of this repository and
`sys/Cargo.toml`. The feature for each newer version of GEOS depends on the
previous version.

### 3. Update included version of GEOS

* update the GEOS submodule to the latest available GEOS version
* update `BUNDLED_GEOS_VERSION` in `sys/build.rs` to match this version
Loading