-
Notifications
You must be signed in to change notification settings - Fork 409
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
yew framework: I think i want to run wasm-pack
from build.rs
#916
Comments
Heya! So I was thinking about this issue and got it working with this simple setup: use std::env;
use std::path::Path;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=client/");
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("web-client");
let output = Command::new("wasm-pack")
.args(&[
"build",
"--target",
"web",
"--out-name",
"client",
"--out-dir",
])
.arg(&dest_path)
.arg("./client/")
.output()
.expect("To build wasm files successfully");
if !output.status.success() {
panic!(
"Error while compiling:\n{}",
String::from_utf8_lossy(&output.stdout)
);
}
let js_file = dest_path.join("client.js");
let wasm_file = dest_path.join("client_bg.wasm");
for file in &[&js_file, &wasm_file] {
let file = std::fs::metadata(file).expect("file to exist");
assert!(file.is_file());
}
println!("cargo:rustc-env=PROJECT_NAME_JS={}", js_file.display());
println!(
"cargo:rustc-env=PROJECT_NAME_WASM={}",
wasm_file.display()
);
} This puts the filepaths into those env variables, which can then be used in an I do think this is just a temporary and somewhat hacky way to do it |
Hey o/ I just found this issue and I might have a good news for you. I'm building a tooling library that is more or less like I'm not entirely sure but I think it would be useful for you. Let me know if you have any suggestion/question. |
Finally released something! \o/ Give it a look and let me know if it covers/help your use case :) Otherwise I would be interested to know more to see if I can help. Check the "backend-and-frontend" example. https://github.com/IMI-eRnD-Be/wasm-run (More detail when I announced it here) |
@TheNeikos, I'm not sure that works. I gave it a try today, and found that it hangs. Since |
No I think that's correct. The devs of panoptix-za/web-bundler#6 (comment) found the same issue and circumvent it with a second target directory. This is something I want to address in wasmbl (a merge of wasm-run and web-bundler) |
Hmmm, so if I did something like this in fn main() {
Command::new("wasm-pack")
.arg("build")
.arg("--target=web")
.arg("--out-dir=dist")
} and ran it with |
I just tried changing the fn main() {
let build_opts = wasm_pack::command::build::BuildOptions {
disable_dts: true,
target: wasm_pack::command::build::Target::Web,
release: true,
extra_options: vec![
"--target-dir".to_string(),
"target-wasm".to_string(),
"--out-dir".to_string(),
"target-wasm".to_string(),
"-Z".to_string(),
"unstable-options".to_string(),
],
..Default::default()
};
wasm_pack::command::build::Build::try_from_opts(build_opts).unwrap().run().unwrap();
} |
Edit: See response at rustwasm/wasm-bindgen#3494 (reply in thread) Original comment: Over at PRQL/prql#2881 we're hoping to use a We're planning to use https://crates.io/crates/substrate-wasm-builder. That seems to allow building from I just found https://github.com/rustminded/xtask-wasm/blob/main/src/dist.rs by following some links from here, which also looks interesting, but doesn't seem to support building from I'm right at the beginning of looking at this — any thoughts or feedback welcome... |
Originally posted by @kud1ing in #251 (comment)
Using Yew
I'm using the yew framework, and I'm working inside of a Rust workspace. Since the
backend/
folder contains a bin crate for the backend server, and thefrontend/
folder contains a yew project (which needswasm-pack build --target web --out-name wasm --out-dir ../target/static
or something like that to be run to compile to webassembly), I'd like to be able to do so in an automated fashion (ideally usingcargo build
in the root of the repo).How should this be achieved?
If possible, integration with VS Code tasks is also desired.
Thanks for reading 🤗
The text was updated successfully, but these errors were encountered: