make it possible to override wasm directory from wasm-dev during build

This commit is contained in:
liquidex 2024-08-23 23:14:33 +02:00
parent c9859124c3
commit 03412722d8
2 changed files with 6 additions and 2 deletions

View file

@ -1,7 +1,7 @@
port := "8080"
serve wasm_profile="wasm-dev": (wasm wasm_profile)
RKGK_PORT={{port}} cargo run -p rkgk
RKGK_PORT={{port}} RKGK_WASM_PATH=target/wasm32-unknown-unknown/{{wasm_profile}} cargo run -p rkgk
wasm profile="wasm-dev":
cargo build -p haku-wasm --target wasm32-unknown-unknown --profile {{profile}}

View file

@ -34,6 +34,7 @@ static GLOBAL_ALLOCATOR: tracy_client::ProfiledAllocator<std::alloc::System> =
struct Paths<'a> {
target_dir: &'a Path,
target_wasm_dir: &'a Path,
database_dir: &'a Path,
}
@ -47,7 +48,7 @@ fn build(paths: &Paths<'_>) -> eyre::Result<()> {
create_dir_all(paths.target_dir.join("static/wasm"))
.context("cannot create static/wasm directory")?;
copy(
"target/wasm32-unknown-unknown/wasm-dev/haku_wasm.wasm",
paths.target_wasm_dir.join("haku_wasm.wasm"),
paths.target_dir.join("static/wasm/haku.wasm"),
)
.context("cannot copy haku.wasm file")?;
@ -76,7 +77,10 @@ fn database(config: &Config, paths: &Paths<'_>) -> eyre::Result<Databases> {
}
async fn fallible_main() -> eyre::Result<()> {
let target_wasm_dir =
std::env::var("RKGK_WASM_PATH").unwrap_or("target/wasm32-unknown-unknown/wasm-dev".into());
let paths = Paths {
target_wasm_dir: Path::new(&target_wasm_dir),
target_dir: Path::new("target/site"),
database_dir: Path::new("database"),
};