build.rs instead of frontend crate features

This commit is contained in:
Martin Kavík 2024-06-01 23:29:56 +02:00
parent e034a2bb14
commit be5d33e5c1
7 changed files with 43 additions and 26 deletions

View file

@ -14,8 +14,3 @@ wasm-bindgen-test = "0.3.19"
shared.workspace = true
zoon.workspace = true
wellen.workspace = true
[features]
platform_browser = []
platform_tauri = []

22
frontend/build.rs Normal file
View file

@ -0,0 +1,22 @@
use std::env;
// https://doc.rust-lang.org/cargo/reference/build-scripts.html
macro_rules! instruction {
($($arg: tt)*) => {
println!($($arg)*)
}
}
// https://github.com/rust-lang/cargo/issues/985
// macro_rules! warning {
// ($($arg: tt)*) => {
// instruction!("cargo:warning={}", format!($($arg)*))
// }
// }
fn main() {
let default_platform = "BROWSER";
let platform = env::var("FASTWAVE_PLATFORM").unwrap_or_else(|_| default_platform.to_owned());
instruction!("cargo:rustc-cfg=FASTWAVE_PLATFORM=\"{platform}\"");
}

View file

@ -143,10 +143,8 @@ impl ControlsPanel {
let hierarchy_and_time_table = hierarchy_and_time_table.clone();
Task::start(async move {
platform::load_waveform(test_file_name).await;
let (hierarchy, time_table) = join!(
platform::get_hierarchy(),
platform::get_time_table()
);
let (hierarchy, time_table) =
join!(platform::get_hierarchy(), platform::get_time_table());
hierarchy_and_time_table.set(Some((Rc::new(hierarchy), Rc::new(time_table))))
})
})

View file

@ -1,16 +1,16 @@
#[cfg(feature = "platform_tauri")]
// @TODO maybe rewrite `FASTWAVE_PLATFORM` to features once it's possible to set them through env vars:
// https://github.com/rust-lang/cargo/issues/4829
#[cfg(FASTWAVE_PLATFORM = "TAURI")]
mod tauri;
#[cfg(feature = "platform_tauri")]
#[cfg(FASTWAVE_PLATFORM = "TAURI")]
use tauri as platform;
#[cfg(feature = "platform_browser")]
#[cfg(FASTWAVE_PLATFORM = "BROWSER")]
mod browser;
#[cfg(feature = "platform_browser")]
#[cfg(FASTWAVE_PLATFORM = "BROWSER")]
use browser as platform;
#[cfg(all(feature = "platform_tauri", feature = "platform_browser"))]
compile_error!("feature \"foo\" and feature \"bar\" cannot be enabled at the same time");
pub async fn show_window() {
platform::show_window().await
}

View file

@ -1,7 +1,7 @@
use zoon::*;
use shared::wellen_helpers;
use std::sync::Mutex;
use wellen::simple::Waveform;
use shared::wellen_helpers;
use zoon::*;
#[derive(Default)]
struct Store {