Skip to content

Commit c459aeb

Browse files
authored
Split the C bindings and wrapper into separate crates (#73)
1 parent fd2dc48 commit c459aeb

File tree

18 files changed

+381
-357
lines changed

18 files changed

+381
-357
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "third-party/libswiftnav"]
2-
path = third-party/libswiftnav
2+
path = swiftnav-sys/src/libswiftnav
33
url = https://github.com/swift-nav/libswiftnav.git

Cargo.toml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
[package]
2-
name = "swiftnav-rs"
3-
version = "0.5.2-alpha.0"
4-
authors = ["Swift Navigation <[email protected]>"]
5-
edition = "2018"
6-
description = "GNSS positioning and related utilities"
7-
readme = "README.md"
8-
repository = "https://github.com/swift-nav/swiftnav-rs"
9-
license = "LGPL-3.0"
10-
11-
[dependencies]
12-
chrono = { version = "0.4", optional = true }
13-
14-
[build-dependencies]
15-
bindgen = "0.59"
16-
cmake = "0.1"
17-
18-
[features]
19-
testcpp = []
20-
chrono-support = ["chrono"]
1+
[workspace]
2+
members = [
3+
"swiftnav",
4+
"swiftnav-sys"
5+
]

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
# swiftnav-rs
1+
# swiftnav
22

3-
`swiftnav-rs` is a crate that implements GNSS utility functions for use by
3+
`swiftnav` is a crate that implements GNSS utility functions for use by
44
software-defined GNSS receivers or software requiring GNSS functionality. It is
55
intended to be as portable as possible and has limited dependencies.
66

7-
`swiftnav-rs` does not provide any functionality for communicating with Swift
7+
`swiftnav` does not provide any functionality for communicating with Swift
88
Navigation receivers. See [libsbp](https://github.com/swift-nav/libsbp) to
99
communicate with receivers using Swift Binary Protocol (SBP).
1010

11-
## Publishing a new release
11+
# swiftnav-sys
12+
13+
`swiftnav-sys` is a crate which builds and exposes Rust FFI bindings for the
14+
`libswiftnav` C library.
15+
16+
# Publishing a new release
1217

1318
Use the [`cargo-release`](https://github.com/sunng87/cargo-release) tool:
1419

1520
```
1621
cargo release --skip-publish
1722
```
1823

19-
## License
24+
# License
2025
This crate is distributed under the terms of the LGPLv3, full details are
2126
available in the [LICENSE](./LICENSE) file.

swiftnav-sys/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "swiftnav-sys"
3+
version = "0.5.2-alpha.0"
4+
authors = ["Swift Navigation <[email protected]>"]
5+
edition = "2018"
6+
description = "FFI bindings for libswiftnav"
7+
readme = "../README.md"
8+
repository = "https://github.com/swift-nav/swiftnav-rs"
9+
license = "LGPL-3.0"
10+
11+
[build-dependencies]
12+
bindgen = "0.59"
13+
cmake = "0.1"
14+
15+
[features]
16+
testcpp = []

build.rs renamed to swiftnav-sys/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::env;
44
use std::path::PathBuf;
55

66
fn main() {
7-
let mut cmake = cmake::Config::new("third-party/libswiftnav/");
7+
println!("cargo:rerun-if-changed=build.rs");
8+
9+
let mut cmake = cmake::Config::new("src/libswiftnav/");
810
let out_dir = env::var("OUT_DIR").unwrap();
911

1012
if !cfg!(feature = "testcpp") {
File renamed without changes.

swiftnav/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "swiftnav"
3+
version = "0.5.2-alpha.0"
4+
authors = ["Swift Navigation <[email protected]>"]
5+
edition = "2018"
6+
description = "GNSS positioning and related utilities"
7+
readme = "../README.md"
8+
repository = "https://github.com/swift-nav/swiftnav-rs"
9+
license = "LGPL-3.0"
10+
11+
[dependencies]
12+
chrono = { version = "0.4", optional = true }
13+
swiftnav-sys = { version = "0.5.2-alpha.0", path = "../swiftnav-sys/" }
14+
15+
[features]
16+
chrono-support = ["chrono"]

src/coords.rs renamed to swiftnav/src/coords.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
//! and Mapping Annual Conference. Orlando, Florida.
4747
//! * "Transformation from Cartesian to Geodetic Coordinates Accelerated by
4848
//! Halley’s Method", T. Fukushima (2006), Journal of Geodesy.
49-
use crate::c_bindings;
5049
5150
/// WGS84 geodetic coordinates (Latitude, Longitude, Height)
5251
///
@@ -95,7 +94,7 @@ impl LLHDegrees {
9594
/// just the representation of the angular values.
9695
pub fn to_radians(&self) -> LLHRadians {
9796
let mut rad = LLHRadians::default();
98-
unsafe { c_bindings::llhdeg2rad(self.as_ptr(), rad.as_mut_ptr()) };
97+
unsafe { swiftnav_sys::llhdeg2rad(self.as_ptr(), rad.as_mut_ptr()) };
9998
rad
10099
}
101100

@@ -184,7 +183,7 @@ impl LLHRadians {
184183
/// just the representation of the angular values.
185184
pub fn to_degrees(&self) -> LLHDegrees {
186185
let mut deg = LLHDegrees::default();
187-
unsafe { c_bindings::llhrad2deg(self.as_ptr(), deg.as_mut_ptr()) };
186+
unsafe { swiftnav_sys::llhrad2deg(self.as_ptr(), deg.as_mut_ptr()) };
188187
deg
189188
}
190189

@@ -193,7 +192,7 @@ impl LLHRadians {
193192
/// (X, Y and Z).
194193
pub fn to_ecef(&self) -> ECEF {
195194
let mut ecef = ECEF::default();
196-
unsafe { c_bindings::wgsllh2ecef(self.as_ptr(), ecef.as_mut_ptr()) };
195+
unsafe { swiftnav_sys::wgsllh2ecef(self.as_ptr(), ecef.as_mut_ptr()) };
197196
ecef
198197
}
199198
}
@@ -280,7 +279,7 @@ impl ECEF {
280279
/// longitude and height).
281280
pub fn to_llh(&self) -> LLHRadians {
282281
let mut llh = LLHRadians::from_array(&[0.0; 3]);
283-
unsafe { c_bindings::wgsecef2llh(self.as_ptr(), llh.as_mut_ptr()) };
282+
unsafe { swiftnav_sys::wgsecef2llh(self.as_ptr(), llh.as_mut_ptr()) };
284283
llh
285284
}
286285

@@ -294,7 +293,7 @@ impl ECEF {
294293
pub fn azel_of(&self, point: &ECEF) -> AzimuthElevation {
295294
let mut azel = AzimuthElevation::new(0.0, 0.0);
296295
unsafe {
297-
c_bindings::wgsecef2azel(point.as_ptr(), self.as_ptr(), &mut azel.az, &mut azel.el)
296+
swiftnav_sys::wgsecef2azel(point.as_ptr(), self.as_ptr(), &mut azel.az, &mut azel.el)
298297
};
299298
azel
300299
}

src/edc.rs renamed to swiftnav/src/edc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1010
//! Error detection code
1111
12-
use crate::c_bindings;
13-
1412
/// Calculate Qualcomm 24-bit Cyclical Redundancy Check (CRC-24Q).
1513
///
1614
/// This CRC is used with the RTCM protocol
@@ -21,7 +19,7 @@ use crate::c_bindings;
2119
///
2220
/// Mask 0x1864CFB, not reversed, not XOR'd
2321
pub fn compute_crc24q(buf: &[u8], initial_value: u32) -> u32 {
24-
unsafe { c_bindings::crc24q(buf.as_ptr(), buf.len() as u32, initial_value) }
22+
unsafe { swiftnav_sys::crc24q(buf.as_ptr(), buf.len() as u32, initial_value) }
2523
}
2624

2725
#[cfg(test)]

0 commit comments

Comments
 (0)