I am building the same Cargo.toml with two different command-lines. This is for building NEAR protocol smart contracts.
First using --manifest-path
cargo build --manifest-path contract/Cargo.toml --release --target wasm32-unknown-unknown
...
Finished release [optimized] target(s) in 23.25s
ls -lha contract/target/wasm32-unknown-unknown/release
...
-rwxr-xr-x 2 moo staff 1.7M Oct 5 12:32 nep9000_pool.wasm*
-rwxr-xr-x 2 moo staff 1.8M Oct 5 12:32 nep9000_token.wasm*
The size of a binary is 1.8 megabytes.
Then I execute the cargo build from within the folder where the Cargo.toml is.
cd contract
cargo build --release --target wasm32-unknown-unknown
Finished release [optimized] target(s) in 22.85s
ls -lha target/wasm32-unknown-unknown/release
-rwxr-xr-x 2 moo staff 127K Oct 5 12:35 nep9000_pool.wasm*
-rw-r--r-- 1 moo staff 305 Sep 30 21:09 nep9000_token.d
-rwxr-xr-x 2 moo staff 189K Oct 5 12:35 nep9000_token.wasm*
Binary size is 10x smaller in the latter method.
Why is this? How do the cargo commands above differ?