Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opslang-wasm packaging #134

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions devtools-frontend/crates/opslang-wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
use std::fs;
use std::process::Command;
use std::{env, path::PathBuf};

fn main() {
// no build logic on wasm32 build (cargo build called from wasm-pack)
let target = env::var("TARGET").unwrap();
if target.contains("wasm32") {
return;
}

// Just called cargo build (target may be x86_64 or aarch64)
// But, now we build wasm by wasm-pack

let out_dir = env::var("OUT_DIR").unwrap();

// pass dist directory path to dependents crate (via package.links)
// it can be used as DEP_OPSLANG_WASM_OUT_DIR in dependents build.rs
println!("cargo:out_dir={}", out_dir);

let target = env::var("TARGET").unwrap();
// Of course we think we should copy source dir into $OUT_DIR
// & build(wasm-pack build) in $OUT_DIR,
// we can't be happy with cargo-metadata called from wasm-pack build
// (from cargo build only.not from cargo package)
let out_dir = PathBuf::from(out_dir);

if !target.contains("wasm32") {
let out_dir = PathBuf::from(out_dir);
// Let's go
let status = Command::new("wasm-pack")
.arg("build")
.arg("--weak-refs")
.arg("--target")
.arg("web")
.arg("--release")
.arg("--out-dir")
.arg(out_dir)
.status()
.expect("failed to execute wasm-pack");
assert!(status.success(), "failed to wasm-pack build");

let status = Command::new("wasm-pack")
.arg("build")
.arg("--weak-refs")
.arg("--target")
.arg("web")
.arg("--release")
.arg("--out-dir")
.arg(out_dir)
.status()
.expect("failed to execute wasm-pack");
assert!(status.success(), "failed to wasm-pack build");
}
// wasm-pack build (cargo build --target wasm32) generates Cargo.lock
// On cargo build, it's fine.
// On cargo package, it cause a catastrophe!!! (it can't be exists in source directory)
fs::remove_file("Cargo.lock").unwrap_or(());
}
Loading