-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from nyx-space/hotfix/embed
Download assets in build.rs for the embed_ephem feature
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} |