# Cargo build vs. dfx build

**URL:** <https://forum.dfinity.org/t/cargo-build-vs-dfx-build/25909>\
**Category:** Developers\
**Created:** [December 26, 2023, 10:49pm UTC](https://forum.dfinity.org/t/cargo-build-vs-dfx-build/25909 "2023-12-26T22:49:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![princess\_eth](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@princess\_eth](https://forum.dfinity.org/u/princess_eth)\
**Post date:** [December 26, 2023, 10:49pm UTC](https://forum.dfinity.org/t/cargo-build-vs-dfx-build/25909/1 "2023-12-26T22:49:34Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [January 3, 2024, 3:29pm UTC](https://forum.dfinity.org/t/cargo-build-vs-dfx-build/25909/2 "2024-01-03T15:29:16Z")

</div>

`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](https://github.com/dfinity/sdk/blob/4346ed71594df5d37aac3b662964275ea5a3d1f3/src/dfx/src/lib/builders/rust.rs#L54)
