wasm-pack
wasm-pack copied to clipboard
can I run with a specified Cargo.toml path
💡 Feature description
like:
wasm-pack build --manifest-path folder/Cargo.toml
so I can keep 2 copies of Cargo.toml
and use one of them for wasm-pack.
original problem was I need to build both staticlib
dylib
and cdylib
, they produce a conflict. I want to keep multiple versions of Cargo.toml
for switching.
💻 Basic example
same as above.
Hi Jon,
What problem are you trying to solve with the Cargo switching?
For now, I'm guessing you want two Cargo.toml files for building to different targets. If not, why else would you want this?
Have you read the Cargo docs? It supports release profiles.
Cargo also supports conditional dependencies:
[target.'cfg(target_arch = "wasm32")'.dependencies]
crate = "0.1.0"
etc...
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crate = "0.2.1
etc...
If this somehow doesn't suit you... can you use git branches?
I use a separate crate for the WebAssembly wrapper code and build config, so a top-level my-project/Cargo.toml
:
[workspace]
members = [
"my-rust-lib",
"my-wasm-wrapper",
]
... and then those crates have separate files my-rust-lib/Cargo.toml
and my-wasm-wrapper/Cargo.toml
.
Keep things simple and clear. Does this kind of workspace separation suit you, @jiyinyiyong ?
@tijlleenders I thought about that for a while, it was not for dependencies, but for lib types:
[lib]
crate-types = [...]
it appears that it's still not supported according to https://github.com/rust-lang/cargo/issues/4881 so I cannot use in that way.
@gthb thanks, it might work, but I think it does not fit my current case. I have to compile a same piece of code to multiple targets. Splitting code into multiple crates add extra complexities. I have a dirty solution at now.
Wow... that issue is three years old. Seems pretty clear it's not solvable at the moment.
My workaround would be to swap the cargo.toml in the build pipeline.
My workaround would be to swap the cargo.toml in the build pipeline.
yep. my current dirty way.