Cargo build vs. dfx build

I can build perfectly fine when I run cargo build in my Rust create.

Finished dev [unoptimized + debuginfo] target(s) in 0.08s

However, when I run dfx build in the same crate, I receive many type errors related to the libs serde and typenum.

I had to run rustup target add wasm32-unknown-unknown to resolve this. Do you know what is happening here?

Is cargo build doing something different than dfx build?

cargo build will compile for the default target, whereas dfx build compiles explicitly for the target wasm-unknown-unknown.

You can find the exact command in the source of dfx: sdk/src/dfx/src/lib/builders/rust.rs at 4346ed71594df5d37aac3b662964275ea5a3d1f3 · dfinity/sdk · GitHub

1 Like