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

Make CMSIS pack downloading feature optional #216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions rust/cmsis-cffi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fs::{create_dir_all, OpenOptions};
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf};

#[cfg(feature = "pack-download")]
use cmsis_pack::update::DownloadConfig;

use anyhow::{anyhow, Error};
Expand All @@ -16,6 +17,7 @@ pub struct ConfigBuilder {
pack_store: Option<PathBuf>,
}

#[cfg(feature = "pack-download")]
impl DownloadConfig for Config {
fn pack_store(&self) -> PathBuf {
self.pack_store.clone()
Expand Down
2 changes: 2 additions & 0 deletions rust/cmsis-cffi/src/pack.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "pack-download")]

use std::ffi::CStr;
use std::os::raw::c_char;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down
16 changes: 15 additions & 1 deletion rust/cmsis-cffi/src/pack_index.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#![allow(clippy::missing_safety_doc)]

use std::borrow::{Borrow, BorrowMut};
use std::ffi::{CStr, CString};
use std::mem;
use std::os::raw::c_char;
use std::path::PathBuf;
use std::ptr::null_mut;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver, Sender};

#[cfg(feature = "pack-download")]
use std::sync::mpsc::{channel, Sender};
use std::sync::mpsc::Receiver;
use std::sync::Arc;
use std::thread;

use anyhow::{anyhow, Error};

#[cfg(feature = "pack-download")]
use crate::config::{read_vidx_list, ConfigBuilder, DEFAULT_VIDX_LIST};
use crate::utils::set_last_error;

#[cfg(feature = "pack-download")]
use cmsis_pack::update::update;

#[cfg(feature = "pack-download")]
use cmsis_pack::update::DownloadProgress;

pub struct UpdateReturn(pub(crate) Vec<PathBuf>);
Expand All @@ -31,14 +40,18 @@ pub struct DownloadUpdate {
pub size: usize,
}


#[cfg(feature = "pack-download")]
pub(crate) struct DownloadSender(Sender<DownloadUpdate>);

#[cfg(feature = "pack-download")]
impl DownloadSender {
pub(crate) fn from_sender(from: Sender<DownloadUpdate>) -> Self {
DownloadSender(from)
}
}

#[cfg(feature = "pack-download")]
impl DownloadProgress for DownloadSender {
fn size(&self, size: usize) {
let _ = self.0.send(DownloadUpdate {
Expand Down Expand Up @@ -81,6 +94,7 @@ impl UpdateReturn {
}
}

#[cfg(feature = "pack-download")]
cffi! {
fn update_pdsc_index(
pack_store: *const c_char,
Expand Down
7 changes: 4 additions & 3 deletions rust/cmsis-pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ log = "0.4.8"
minidom = "0.12.0"
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["macros", "rt"] }
reqwest = { version = "0.11.0", default_features = false, features = ["rustls-tls-native-roots", "trust-dns", "stream"] }
tokio = { version = "1.0", features = ["macros", "rt"], optional = true }
reqwest = { version = "0.11.0", default_features = false, features = ["rustls-tls-native-roots", "trust-dns", "stream"], optional = true }
anyhow = "1.0.56"

[dev-dependencies]
time = "0.3.3"

[features]
default = []
default = ["pack-download"]
pack-download = ["dep:tokio", "dep:reqwest"]
5 changes: 5 additions & 0 deletions rust/cmsis-pack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ pub mod utils;
extern crate futures;
extern crate log;
extern crate minidom;

#[cfg(feature = "pack-download")]
extern crate reqwest;

extern crate serde;
extern crate serde_json;

#[cfg(feature = "pack-download")]
extern crate tokio;
2 changes: 2 additions & 0 deletions rust/cmsis-pack/src/update/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "pack-download")]

use anyhow::Error;
use std::path::PathBuf;
use tokio::runtime;
Expand Down