[Inquiry] Inconsistent binary size with 'cargo +stable build' vs 'cargo +1.50-x86_64-pc-windows-msvc' ? (original) (raw)
Problem
I am not 100% sure this is a bug or expected, but while exploring #75804, I have identified this inconsistency in the size of binaries of the same sources when using +stable
vs +1.50-x86_64-pc-windows-msvc
:
I would have expected that since the current stable is 1.50, cargo +stable build
, cargo +1.50-... build
and cargo build
to yield the same results, but they don't.
Unfortunately I can't share the actual tool sources, but I can share the deps list.
Steps
- Use a script like the one below to do multiple builds on various versions (automation in cygwin)
RUST_DBG_FLAGS='-C debuginfo=1 -C panic=abort -C opt-level=0'
RUST_REL_FLAGS='-C debuginfo=0 -C panic=abort -C opt-level=3'
set -e -u
BUILD=build MAIN=parser
cargo -vV rustc -vV
rustup toolchain list rustup override list
mkdir -p ${BUILD}/debug mkdir -p ${BUILD}/release for ver in 1.{45..50} beta nightly stable; do echo "-- $ver" for variant in release debug; do
if [ ${variant} == release ]; then
x_opt=--release
else
x_opt=
fi
bin=${BUILD}/${variant}/${MAIN}-${ver}.exe
cargo clean
cargo +$ver-x86_64-pc-windows-msvc build ${x_opt}
cp target/${variant}/${MAIN}.exe ${bin}
size=$(stat --printf="%s" $bin)
printf " %s: %d\n" <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>v</mi><mi>a</mi><mi>r</mi><mi>i</mi><mi>a</mi><mi>n</mi><mi>t</mi></mrow><annotation encoding="application/x-tex">{variant} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6595em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">ian</span><span class="mord mathnormal">t</span></span></span></span></span>size
done
done
echo "No params" cargo clean cargo build cargo build --release
echo "release" ls -lnG {target,build}/release/.exe | cut -f4,8 -d ' ' echo "debug" ls -lnG {target,build}/debug/.exe | cut -f4,8 -d ' '
- Run using cygwin's bash (WSL would use Linux's cargo and I haven't checked if it happens there)
c:\tools\cygwin64\bin\bash.exe build-all.sh
- Note that stable and 1.50 yield different results, in spite 1.50 being the current stable.
C:\usr\perso\rust\test-size\parser>c:\tools\cygwin64\bin\bash.exe build-all.sh cargo 1.50.0 (f04e7fab7 2021-02-04) release: 1.50.0 commit-hash: f04e7fab73128592a4063983c302da788bdfaba5 commit-date: 2021-02-04 rustc 1.50.0 (cb75ad5db 2021-02-10) binary: rustc commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b commit-date: 2021-02-10 host: x86_64-pc-windows-msvc release: 1.50.0 stable-x86_64-pc-windows-msvc (default) beta-x86_64-pc-windows-msvc nightly-x86_64-pc-windows-msvc 1.45-x86_64-pc-windows-msvc 1.46-x86_64-pc-windows-msvc 1.47-x86_64-pc-windows-msvc 1.48-x86_64-pc-windows-msvc 1.49-x86_64-pc-windows-msvc 1.50-x86_64-pc-windows-msvc C:\usr\src\rust\sbenitez-cs140e nightly-2018-01-09-x86_64-pc-windows-msvc -- 1.45 Compiling proc-macro2 v1.0.24 Compiling unicode-xid v0.2.1 Compiling ucd-trie v0.1.3 Compiling syn v1.0.60 Compiling maplit v1.0.2 Compiling unindent v0.1.7 Compiling pest v2.1.3 Compiling indoc v1.0.3 Compiling pest_meta v2.1.3 Compiling quote v1.0.9 Compiling pest_generator v2.1.3 Compiling pest_derive v2.1.0 Compiling parser v0.1.3 (C:\usr\perso\rust\test-size\parser) Finished release [optimized] target(s) in 25.78s release: 171520 [...] release 171520 build/release/parser-1.45.exe 172032 build/release/parser-1.46.exe 172032 build/release/parser-1.47.exe 165376 build/release/parser-1.48.exe 167424 build/release/parser-1.49.exe 169984 build/release/parser-1.50.exe 167424 build/release/parser-beta.exe 167936 build/release/parser-nightly.exe 170496 build/release/parser-stable.exe 170496 target/release/parser.exe debug 583680 build/debug/parser-1.45.exe 577024 build/debug/parser-1.46.exe 574464 build/debug/parser-1.47.exe 573440 build/debug/parser-1.48.exe 549376 build/debug/parser-1.49.exe 546304 build/debug/parser-1.50.exe 546816 build/debug/parser-beta.exe 548864 build/debug/parser-nightly.exe 547328 build/debug/parser-stable.exe 547328 target/debug/parser.exe
Note how 1.50 versions have a different size than +stable
and default on both release and debug builds.
- It seems that stable builds have some extra strings in them with paths to the %USERPROFILE%\.rustup\toolchains:
C:\usr\perso\rust\test-size\parser>strings build/release/parser-1.50.exe | grep '1.50.*'
C:\usr\perso\rust\test-size\parser>strings build/release/parser-1.50.exe | grep 'stable.*'
C:\usr\perso\rust\test-size\parser>strings build/release/parser-stable.exe | grep -o '1.50.*'
C:\usr\perso\rust\test-size\parser>strings build/release/parser-stable.exe | grep -o 'stable.*' stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\collections\btree\map.rs stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\io\mod.rs stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\slice\mod.rs stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\collections\btree\node.rs stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\slice.rs stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\str\pattern.rsSpan stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\alloc\layout.rs
Is this expected?
Possible Solution(s)
Notes
Output of cargo version
:
cargo 1.50.0 (f04e7fab7 2021-02-04)
release: 1.50.0
commit-hash: f04e7fab73128592a4063983c302da788bdfaba5
commit-date: 2021-02-04
OS and toolchain info above