Skip to content

Commit

Permalink
[GUI] Try to get wasm building again :imhex:
Browse files Browse the repository at this point in the history
  • Loading branch information
widberg committed Jan 14, 2024
1 parent 0db8d9e commit 4ed3af9
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 30 deletions.
18 changes: 14 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions bff-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 11 additions & 5 deletions bff-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand All @@ -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
8 changes: 6 additions & 2 deletions bff-gui/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Result<T, BffGuiError>;

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(())
Expand Down
19 changes: 14 additions & 5 deletions bff-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ 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;
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<T> = Result<T, BffGuiError>;

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -219,11 +221,15 @@ struct Gui {
}

impl Gui {
fn new(cc: &eframe::CreationContext<'_>, file: Option<PathBuf>) -> Self {
fn new(
cc: &eframe::CreationContext<'_>,
#[cfg(not(target_arch = "wasm32"))] file: Option<PathBuf>,
) -> 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);
Expand All @@ -232,6 +238,9 @@ impl Gui {
}
None => false,
};
#[cfg(target_arch = "wasm32")]
let bf_loading = false;

Self {
open_window: GuiWindow::default(),
tx,
Expand Down
12 changes: 6 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ 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]
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]
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
Expand All @@ -82,14 +82,14 @@ 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]
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

0 comments on commit 4ed3af9

Please sign in to comment.