Skip to content

Commit

Permalink
Merge pull request #277 from nyx-space/hotfix/embed
Browse files Browse the repository at this point in the history
Download assets in build.rs for the embed_ephem feature
  • Loading branch information
ChristopherRabotin authored Jul 10, 2024
2 parents e9f4cf3 + ab7f7d9 commit c69cc7d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ jobs:
env:
LAGRANGE_BSP: ${{ secrets.LAGRANGE_BSP }}
run: cargo test --release --workspace --exclude anise-gui --exclude anise-py

- name: Test rust_embed build
run: |
rm -rf data # Not available on crates.io
cd anise # Build only the Rust library
cargo build --features embed_ephem
cargo build --features embed_ephem --release
lints:
name: Lints
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["anise", "anise-cli", "anise-gui", "anise-py"]

[workspace.package]
version = "0.4.0"
version = "0.4.1"
edition = "2021"
authors = ["Christopher Rabotin <[email protected]>"]
description = "ANISE provides a toolkit and files for Attitude, Navigation, Instrument, Spacecraft, and Ephemeris data. It's a modern replacement of NAIF SPICE file."
Expand Down
5 changes: 4 additions & 1 deletion anise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rust-embed = { version = "8.4.0", features = [
"interpolate-folder-path",
"include-exclude",
], optional = true }
regex = {version = "1.10.5" , optional = true}
regex = { version = "1.10.5", optional = true }

[dev-dependencies]
rust-spice = "0.7.6"
Expand All @@ -49,6 +49,9 @@ polars = { version = "0.41.1", features = ["lazy", "parquet"] }
rayon = "1.7"
serde_yaml = "0.9.30"

[build-dependencies]
reqwest = { version = "0.11", features = ["blocking"], optional = true }

[features]
default = ["metaload"]
# Enabling this flag significantly increases compilation times due to Arrow and Polars.
Expand Down
54 changes: 54 additions & 0 deletions anise/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#[cfg(feature = "embed_ephem")]
fn main() {
// Download the files to embed at build time.
use std::{
fs::{self, File},
io::Write,
path::Path,
time::Duration,
};
let client = reqwest::blocking::Client::builder()
.connect_timeout(Duration::from_secs(30))
.timeout(Duration::from_secs(30))
.build()
.unwrap();

let embedded_files = [
(
"http://public-data.nyxspace.com/anise/v0.4/pck11.pca",
format!("{}/../data/pck11.pca", env!("CARGO_MANIFEST_DIR")),
),
(
"http://public-data.nyxspace.com/anise/de440s.bsp",
format!("{}/../data/de440s.bsp", env!("CARGO_MANIFEST_DIR")),
),
];

let data_path = Path::new(&env!("CARGO_MANIFEST_DIR")).join("../data");

// Create the directory if it doesn't exist
if !data_path.exists() {
fs::create_dir_all(&data_path).expect(&format!("failed to create directory {data_path:?}"));
}

for (url, dest_path) in embedded_files {
let resp = client
.get(url)
.send()
.expect(&format!("could not download {url}"));

let bytes = resp
.bytes()
.expect(&format!("could not read bytes from {url}"));

let mut file =
File::create(&dest_path).expect(&format!("could not create the data path {dest_path}"));
file.write_all(&bytes)
.expect(&format!("could not write asset data to {dest_path}"));
}
}

#[cfg(not(feature = "embed_ephem"))]
fn main() {
// Nothing to do if we aren't embedded files.
}

0 comments on commit c69cc7d

Please sign in to comment.