-
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
build.rs usage? #251
Comments
Hmmm I personally don't think so since
There's some other steps but those are mostly "what options have you passed in" and are kind of inconsequential to your question. Out of all of these 1 and 2 can be made to be part of a Lots of people have wanted post build scripts for some time actually! Which would solve 4,5, and 6. The only problem would be specifying a default triple for a directory so that you can just do As it stands I don't think this is currently possible until the other things are fixed or added. These issues are similar to the one xargo faces and unless cargo fundamentally changes I don't think that this workflow will be possible anytime soon. It'll require quite a few RFCs and then implementation of them 😅 That being said I'm glad you asked the question 😄 I had fun writing out an answer to your question and I think it's a good question to ask. Not everyone understands the design constraints this project faces and so having some time to dump out what was just sitting in my head onto an issue so that others can understand why this is a separate cli tool and not part of cargo is a good thing 👍 Does that answer your question? Is there something I can answer better? |
EDIT: you want to run this in |
If post-build cargo scripts were a thing, then I would say that wasm-pack could be something you use as a library in a post-build script. Unfortunately, I don't think that post-build scripts are going to be supported in cargo any time soon. I seem to remember there being one RFC that got closed, but it was also an overly terse/vague RFC, IIRC. |
As I've looked at |
I think i want to run Any advice on how to call |
Hey there, I'd like to run Here's my specific use case. I have a workspace setup for a single repo. It contains multiple crates, one of which is an http server, and another which is my wasm app. Let's call them "my-server", and "my-wasm" The server builds a single binary with embedded static assets. One of these static assets is "my-wasm". When I run Think of this as falling under "Performing any platform-specific configuration needed for the crate." as defined in the page on build.rs scripts in https://doc.rust-lang.org/cargo/reference/build-scripts.html. It seems in line with a lot of the examples listed as well. Something as simple as exposing the steps here in https://github.com/rustwasm/wasm-pack/blob/9f9634ca9ffa9147c044f947a31808f02715aa44/src/command/build.rs would really go a long way. tldr; I'd like to treat the output of a PS: all things considered, I really think this is a terrific tool! thank you to the maintainers and contributors :) |
Following up to this in case anyone is interested. If you're not using all of wasm-packs features, and you really just need a .wasm file and the JS bindings, I've found this solution to be a quick, and relatively painless way to build those using In your cargo build -p mywasm \
--target=wasm32-unknown-unknown \
--target-dir=alt-target
--release
wasm-bindgen --target=web \
--out-dir=final-out-dir \
alt-target/wasm32-unknown-unknown/release/mywasm.wasm Building to an alternate target directory solves the cargo locking issue, and running wasm-bindgen will get you the JS bindings. If you want to build for debug or do optimizations, you may need to fill out the command arguments, which can get a little messy, but it works. |
FYI: I have the same issue/use-case as @vogtb and still think this is a pressing issue. There's a few related/compounding issues as well that I'd like to flag here just in case someone wants to try to fix them all together (or maybe just needs catharsis :-). I'm also hoping that some of them maybe separable issues that maybe wise people can provide pointers on how to fix :-)
In general, I would suggest that this is a common enough usage that it would be super helpful to have some sort of best practices/list of issues as an example, IMHO, in the repo. What are people's thoughts on it? I'm relatively new to rust and am happy to volunteer to check in what is kinda/sorta working for me if smarter people can offer to sanity check it. Thoughts? |
FWIW there's a good explanation of the issues at rustwasm/wasm-bindgen#3494 (reply in thread) It's worth checking out some links there too — i.e. how https://crates.io/crates/wasm-server-runner & https://crates.io/crates/substrate-wasm-builder do this. |
If it's just about the compilation time, can we just exclude some code with |
Does it make sense to call this tool from
build.rs
to have a fully cargo driven build workflow?If so, can we add some examples of this to the README? If it makes sense, I'll try to figure it out and could send a PR for the README, but I want to make sure it makes sense first.
The text was updated successfully, but these errors were encountered: