Skip to content

Commit df8f720

Browse files
authored
chore(c/sedona-s2geography): Remove build time bindgen dependency (#221)
1 parent 85ce98d commit df8f720

File tree

4 files changed

+76
-22
lines changed

4 files changed

+76
-22
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

c/sedona-s2geography/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ edition.workspace = true
2727
rust-version.workspace = true
2828

2929
[build-dependencies]
30-
bindgen = "0.71.0"
3130
cmake = { version = "0.1" }
3231
regex = { workspace = true }
3332

c/sedona-s2geography/build.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
use std::{
1818
collections::HashSet,
19-
env,
2019
path::{Path, PathBuf},
2120
};
2221

@@ -59,20 +58,6 @@ fn main() {
5958
// Parse the output we wrote from CMake that is the linker flags
6059
// that CMake thinks we need for Abseil and OpenSSL.
6160
parse_cmake_linker_flags(&dst);
62-
63-
// Generate bindings from the header
64-
println!("cargo::rerun-if-changed=src/geography_glue.h");
65-
let bindings = bindgen::Builder::default()
66-
.header("src/geography_glue.h")
67-
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
68-
.generate()
69-
.expect("Unable to generate bindings");
70-
71-
// Write the bindings to the $OUT_DIR/bindings.rs file.
72-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
73-
bindings
74-
.write_to_file(out_path.join("bindings.rs"))
75-
.expect("Couldn't write bindings!");
7661
}
7762

7863
fn parse_cmake_linker_flags(binary_dir: &Path) {

c/sedona-s2geography/src/geography_glue_bindgen.rs

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,80 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
#![allow(non_upper_case_globals)]
18-
#![allow(non_camel_case_types)]
19-
#![allow(non_snake_case)]
20-
#![allow(dead_code)]
2117

22-
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
18+
use std::os::raw::{c_char, c_int, c_void};
19+
20+
#[repr(C)]
21+
pub struct ArrowSchema {
22+
_private: [u8; 0],
23+
}
24+
25+
#[repr(C)]
26+
pub struct ArrowArray {
27+
_private: [u8; 0],
28+
}
29+
30+
#[repr(C)]
31+
#[derive(Debug, Copy, Clone)]
32+
pub struct SedonaGeographyArrowUdf {
33+
pub init: Option<
34+
unsafe extern "C" fn(
35+
self_: *mut SedonaGeographyArrowUdf,
36+
arg_schema: *mut ArrowSchema,
37+
options: *const c_char,
38+
out: *mut ArrowSchema,
39+
) -> c_int,
40+
>,
41+
pub execute: Option<
42+
unsafe extern "C" fn(
43+
self_: *mut SedonaGeographyArrowUdf,
44+
args: *mut *mut ArrowArray,
45+
n_args: i64,
46+
out: *mut ArrowArray,
47+
) -> c_int,
48+
>,
49+
pub get_last_error:
50+
Option<unsafe extern "C" fn(self_: *mut SedonaGeographyArrowUdf) -> *const c_char>,
51+
pub release: Option<unsafe extern "C" fn(self_: *mut SedonaGeographyArrowUdf)>,
52+
pub private_data: *mut c_void,
53+
}
54+
55+
macro_rules! declare_s2_c_udfs {
56+
($($name:ident),*) => {
57+
$(
58+
paste::item! {
59+
pub fn [<SedonaGeographyInitUdf $name>](out: *mut SedonaGeographyArrowUdf);
60+
}
61+
)*
62+
}
63+
}
64+
65+
unsafe extern "C" {
66+
pub fn SedonaGeographyGlueNanoarrowVersion() -> *const c_char;
67+
pub fn SedonaGeographyGlueGeoArrowVersion() -> *const c_char;
68+
pub fn SedonaGeographyGlueOpenSSLVersion() -> *const c_char;
69+
pub fn SedonaGeographyGlueS2GeometryVersion() -> *const c_char;
70+
pub fn SedonaGeographyGlueAbseilVersion() -> *const c_char;
71+
pub fn SedonaGeographyGlueTestLinkage() -> f64;
72+
73+
declare_s2_c_udfs!(
74+
Area,
75+
Centroid,
76+
ClosestPoint,
77+
Contains,
78+
ConvexHull,
79+
Difference,
80+
Distance,
81+
Equals,
82+
Intersection,
83+
Intersects,
84+
Length,
85+
LineInterpolatePoint,
86+
LineLocatePoint,
87+
MaxDistance,
88+
Perimeter,
89+
ShortestLine,
90+
SymDifference,
91+
Union
92+
);
93+
}

0 commit comments

Comments
 (0)