Making sure I understood per-package-target

Hi,

I have an app that is split between a wasm part and a server part using Dioxus.

During dev time, human error made my server library to be injected in the wasm app, which I don't want to happen again ( I commented the #[server] to make some modifications and forgot to add it back).

After reading https://doc.rust-lang.org/cargo/reference/unstable.html#per-package-target, it appears that it will do exactly this.

I want a compile time error if my crate is compiled for anything else than x86_64 (this crate's code must remains on the server side).
That should make it to prevent any unwanted code in the wasm side.

So, is it guaranteed that this option does what I need, without any way to circumvent it ?

note: I use nightly toolchain.

Thanks

Have you tried adding something like this to your crate root:

#[cfg(not(target_arch = "x86_64"))]
compile_error!("This can only be build on `x86_64` architectures");

Might be easier than using another unstable feature that might break. But AFAIU the docs, the forced-target = "<target>" will cause Cargo to always build for <target>, even if a different target is specified.

Thanks jofas,
Indeed, your solution is much simpler!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.