diff --git a/Cargo.lock b/Cargo.lock index ce7555a..dfab892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3459,9 +3459,9 @@ dependencies = [ [[package]] name = "shadow-rs" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "615d846f7174a0850dca101bca72f6913e3376a64c5fda2b965d7fc3d1ff60cb" +checksum = "878cb1e3162d98ee1016b832efbb683ad6302b462a2894c54f488dc0bd96f11c" dependencies = [ "const_format", "git2", @@ -3879,12 +3879,22 @@ dependencies = [ [[package]] name = "tzdb" -version = "0.5.7" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec758958f2fb5069cd7fae385be95cc8eceb8cdfd270c7d14de6034f0108d99e" +checksum = "1b580f6b365fa89f5767cdb619a55d534d04a4e14c2d7e5b9a31e94598687fb1" dependencies = [ "iana-time-zone", "tz-rs", + "tzdb_data", +] + +[[package]] +name = "tzdb_data" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "629555d2921f3f0dc0de98699415a8b2b61dfcd3a0b082a327f7ed748bbb2b76" +dependencies = [ + "tz-rs", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 671af81..42d7629 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,6 @@ [workspace] resolver = "2" -members = [ - "bff", - "bff-cli", - "bff-derive", - "bff-gui", -] +members = ["bff", "bff-cli", "bff-derive", "bff-gui"] [workspace.package] version = "0.1.0" diff --git a/bff-cli/Cargo.toml b/bff-cli/Cargo.toml index 678f430..33ba0a7 100644 --- a/bff-cli/Cargo.toml +++ b/bff-cli/Cargo.toml @@ -11,10 +11,10 @@ clap = { version = "4.2.4", features = ["derive"] } derive_more = "0.99.17" pathdiff = "0.2.1" serde_json = "1.0.96" -shadow-rs = "0.25.0" +shadow-rs = "0.26.0" [build-dependencies] -shadow-rs = "0.25.0" +shadow-rs = "0.26.0" [lints] workspace = true diff --git a/bff-gui/Cargo.toml b/bff-gui/Cargo.toml index 6194650..1fbae0e 100644 --- a/bff-gui/Cargo.toml +++ b/bff-gui/Cargo.toml @@ -7,6 +7,7 @@ rust-version.workspace = true [dependencies] bff = { path = "../bff" } +clap = { version = "4.2.4", features = ["derive"] } derive_more = "0.99.17" eframe = "0.23.0" egui = "0.23.0" @@ -23,21 +24,22 @@ rfd = { version = "0.12.0", features = ["file-handle-inner"] } rodio = { version = "0.17.1", features = ["wav"], default-features = false } serde = "1.0.188" serde_json = "1.0.107" +shadow-rs = { version = "0.26.0", optional = true } three-d = { version = "0.16.1", default-features = false } three-d-asset = "0.6.0" -shadow-rs = "0.25.0" -clap = { version = "4.2.4", features = ["derive"] } [target.'cfg(target_os = "windows")'.dependencies] winreg = "0.52.0" windows = { version = "0.52.0", features = ["Win32_UI_Shell"], default-features = false } [build-dependencies] -shadow-rs = "0.25.0" derive_more = "0.99.17" +shadow-rs = { version = "0.26.0", optional = true } +winres = "0.1.12" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1.33.0", features = ["rt-multi-thread", "time"] } +shadow-rs = "0.26.0" # https://github.com/rust-lang/cargo/issues/1197 [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -48,8 +50,12 @@ three-d = { version = "0.16.1", default-features = false, features = [ eframe = { version = "0.23.0", features = ["persistence"] } async-std = "1.12.0" -[target.'cfg(target_os = "windows")'.build-dependencies] -winres = "0.1.12" +# I fucking hate this. Does Cargo seriously not have a way to detect the target architecture from cfg's at build time? +# This means I can't do [target.'cfg(cargo_target_arch = "wasm32")'.build-dependencies] or similar and need this +# stupid fucking feature thing. +[features] +not_wasm32 = ["dep:shadow-rs"] +default = ["not_wasm32"] [lints] workspace = true diff --git a/bff-gui/build.rs b/bff-gui/build.rs index a56c118..9834c67 100644 --- a/bff-gui/build.rs +++ b/bff-gui/build.rs @@ -3,19 +3,23 @@ use derive_more::From; #[derive(Debug, From)] enum BffGuiError { Io(std::io::Error), + #[cfg(feature = "not_wasm32")] Shadow(shadow_rs::ShadowError), } type BffGuiResult = Result; fn main() -> BffGuiResult<()> { - #[cfg(target_os = "windows")] - { + // https://users.rust-lang.org/t/compile-for-windows-from-linux-when-have-build-rs/76858 + let target_arch = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); + + if target_arch == "windows" { let mut res = winres::WindowsResource::new(); res.set_icon("resources/bff.ico"); res.compile()?; } + #[cfg(feature = "not_wasm32")] shadow_rs::new()?; Ok(()) diff --git a/bff-gui/src/main.rs b/bff-gui/src/main.rs index a0104fc..6d71b07 100644 --- a/bff-gui/src/main.rs +++ b/bff-gui/src/main.rs @@ -7,11 +7,10 @@ use std::sync::mpsc::{Receiver, Sender}; use artifact::Artifact; use bff::bigfile::BigFile; use bff::names::Name; +#[cfg(not(target_arch = "wasm32"))] use clap::Parser; -use derive_more::From; #[cfg(not(target_arch = "wasm32"))] use helpers::load::load_bf; -use shadow_rs::shadow; pub mod artifact; pub mod helpers; @@ -19,19 +18,22 @@ mod panels; pub mod traits; mod views; -shadow!(build); +#[cfg(not(target_arch = "wasm32"))] +shadow_rs::shadow!(build); #[cfg(not(target_arch = "wasm32"))] const TITLE: &str = "BFF Studio"; #[cfg(not(target_arch = "wasm32"))] const WINDOW_SIZE: egui::Vec2 = egui::vec2(800.0, 600.0); -#[derive(Debug, From)] +#[cfg(not(target_arch = "wasm32"))] +#[derive(Debug, derive_more::From)] enum BffGuiError { Io(std::io::Error), EFrame(eframe::Error), } +#[cfg(not(target_arch = "wasm32"))] type BffGuiResult = Result; #[cfg(not(target_arch = "wasm32"))] @@ -219,11 +221,15 @@ struct Gui { } impl Gui { - fn new(cc: &eframe::CreationContext<'_>, file: Option) -> Self { + fn new( + cc: &eframe::CreationContext<'_>, + #[cfg(not(target_arch = "wasm32"))] file: Option, + ) -> Self { cc.egui_ctx.set_pixels_per_point(1.25); egui_extras::install_image_loaders(&cc.egui_ctx); setup_custom_font(&cc.egui_ctx); let (tx, rx) = std::sync::mpsc::channel(); + #[cfg(not(target_arch = "wasm32"))] let bf_loading = match file { Some(path) => { let p = PathBuf::from(path); @@ -232,6 +238,9 @@ impl Gui { } None => false, }; + #[cfg(target_arch = "wasm32")] + let bf_loading = false; + Self { open_window: GuiWindow::default(), tx, diff --git a/justfile b/justfile index 0101fe4..1f1b4a4 100644 --- a/justfile +++ b/justfile @@ -34,7 +34,7 @@ build: [unix] build-wasm: cd bff-gui - /usr/bin/env CC="{{ wasi_sdk_path }}/bin/clang --sysroot={{ wasi_sdk_path }}/share/wasi-sysroot" trunk build --release + /usr/bin/env CC="{{ wasi_sdk_path }}/bin/clang --sysroot={{ wasi_sdk_path }}/share/wasi-sysroot" trunk build --release --no-default-features # trunk (https://github.com/trunk-rs/trunk) [windows] @@ -42,13 +42,13 @@ build-wasm: #!powershell -NoLogo cd bff-gui $ENV:CC = "{{ wasi_sdk_path }}/bin/clang --sysroot={{ wasi_sdk_path }}/share/wasi-sysroot" - trunk build --release + trunk build --release --no-default-features # trunk (https://github.com/trunk-rs/trunk) [unix] serve-wasm: cd bff-gui - /usr/bin/env CC="{{ wasi_sdk_path }}/bin/clang --sysroot={{ wasi_sdk_path }}/share/wasi-sysroot" trunk serve --release + /usr/bin/env CC="{{ wasi_sdk_path }}/bin/clang --sysroot={{ wasi_sdk_path }}/share/wasi-sysroot" trunk serve --release --no-default-features # trunk (https://github.com/trunk-rs/trunk) [windows] @@ -56,7 +56,7 @@ serve-wasm: #!powershell -NoLogo cd bff-gui $ENV:CC = "{{ wasi_sdk_path }}/bin/clang --sysroot={{ wasi_sdk_path }}/share/wasi-sysroot" - trunk serve --release + trunk serve --release --no-default-features doc: cargo doc @@ -82,7 +82,7 @@ install-dev-deps-wasm: # flamegraph (https://github.com/flamegraph-rs/flamegraph) [unix] flamegraph CMD *OPTIONS: - /usr/bin/env CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --root --release --bin {{ CMD }} -- -- {{ OPTIONS }} + /usr/bin/env CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --root --release --bin {{ CMD }} -- {{ OPTIONS }} # flamegraph (https://github.com/flamegraph-rs/flamegraph) and blondie (https://github.com/nico-abram/blondie) [windows] @@ -90,6 +90,6 @@ flamegraph CMD *OPTIONS: #!powershell -NoLogo $ENV:CARGO_PROFILE_RELEASE_DEBUG = "true" $ENV:DTRACE = "blondie_dtrace" - cargo flamegraph --release --bin {{ CMD }} -- -- {{ OPTIONS }} + cargo flamegraph --release --bin {{ CMD }} -- {{ OPTIONS }} check: fmt clippy test