Skip to content

Commit

Permalink
Fix some more maelstrom-web publishing issues
Browse files Browse the repository at this point in the history
The profiles from the crate root need to be copied to the individual
Cargo.toml if it is to be used with publishing

Put web.tar in OUT_DIR, and read it from there, this is the right way of
doing this and should work with publishing
  • Loading branch information
bobbobbio committed Jan 21, 2024
1 parent e2e1813 commit 74f9862
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 8 additions & 0 deletions crates/maelstrom-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ cargo_metadata.workspace = true
# These dependencies ensure the build script re-runs
maelstrom-plot.workspace = true
maelstrom-base.workspace = true

# These profiles are copied from the workspace root so they can be used when
# publishing. See this issue <https://github.com/rust-lang/cargo/issues/8264>
[profile.wasm_dev]
inherits = "dev"

[profile.wasm_release]
inherits = "release"
9 changes: 3 additions & 6 deletions crates/maelstrom-web/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fs;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::process::Command;
use wasm_bindgen_cli_support::Bindgen;

Expand Down Expand Up @@ -123,11 +123,8 @@ fn create_web_tar(profile: &str, build_dir: &Path) {
wasm_opt(&pkg_dir.join("maelstrom_web_bg.wasm"));
}

create_tar(
Path::new("www"),
&pkg_dir,
&build_dir.join(profile).join("web.tar"),
);
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
create_tar(Path::new("www"), &pkg_dir, &out_dir.join("web.tar"));
}

fn main() {
Expand Down
7 changes: 2 additions & 5 deletions crates/maelstrom-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ pub async fn start() -> Result<(), JsValue> {
}
}

#[cfg(all(not(target_arch = "wasm32"), not(debug_assertions)))]
pub const WASM_TAR: &[u8] = include_bytes!("../../../target/wasm_release/web.tar");

#[cfg(all(not(target_arch = "wasm32"), debug_assertions))]
pub const WASM_TAR: &[u8] = include_bytes!("../../../target/wasm_dev/web.tar");
#[cfg(not(target_arch = "wasm32"))]
pub const WASM_TAR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/web.tar"));

0 comments on commit 74f9862

Please sign in to comment.