corrosion-rs / corrosion

Marrying Rust and CMake - Easy Rust and C/C++ Integration!
https://corrosion-rs.github.io/corrosion/
MIT License
1.1k stars 106 forks source link

[Bug]: strip=true and missing pdb files on Windows #538

Closed diresi closed 5 months ago

diresi commented 5 months ago

Current Behavior

On Windows, using strip=true in Cargo.toml causes builds to fail while copying byproducts as no PDB files are generated and attempts to copy them fail.

Using strip=false doesn't show the problem, byproducts are created and copied just fine.

Expected Behavior

strip=true should be supported, PDB files should be optional.

Steps To Reproduce

Cargo.toml:

[package]
name = "thing"
version = "0.1.0"
edition = "2021"

[dependencies]

[profile.release]
strip = true

Environment

- OS: Windows
- CMake: 3.28.0
- CMake Generator: MSVC

C:\work\work\tmp\thing\b>cmake .
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- Rust Toolchain: 1.75-x86_64-pc-windows-msvc
-- Rust Target: x86_64-pc-windows-msvc
-- Using Corrosion as a subdirectory
-- Configuring done (3.3s)
-- Generating done (0.0s)
-- Build files have been written to: C:/work/work/tmp/thing/b

C:\work\work\tmp\thing\b>cmake --version
cmake version 3.28.0-msvc1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

CMake configure log with Debug log-level

C:\work\work\tmp\thing\b>cmake ..
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- Rust Toolchain: 1.75-x86_64-pc-windows-msvc
-- Rust Target: x86_64-pc-windows-msvc
-- Using Corrosion as a subdirectory
-- Configuring done (3.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/work/work/tmp/thing/b

CMake Build step log

C:\work\work\tmp\thing\b>cmake --build . --config Release
MSBuild version 17.9.5+33de0b227 for .NET Framework

      Finished release [optimized] target(s) in 0.01s
  Copying byproducts `thing.exe` to C:/work/work/tmp/thing/b    Copying byproducts `thing.pdb` to C:/work/work/tmp/thing/b
  Error copying file (if different) from "C:/work/work/tmp/thing/b/x64/Release/cargo/build/x86_64-pc-windows-msvc/release/thing.pdb" to "C:/work/work/tmp/th
  ing/b".
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: The command "setloca
l [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\Mi
crosoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E make_directory C:/work/work/tmp/thing/b [C:\wor
k\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq
0 goto :cmEnd [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\Mi
crosoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_if_different C:/work/work/tmp/thing/b/x64/
Release/cargo/build/x86_64-pc-windows-msvc/release/thing.exe C:/work/work/tmp/thing/b [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq
0 goto :cmEnd [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmEnd [C:\work\work
\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: endlocal & call :cmE
rrorLevel %errorlevel% & goto :cmDone [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmErrorLevel [C:\wo
rk\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: exit /b %1 [C:\work\
work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmDone [C:\work\wor
k\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq
0 goto :VCEnd [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: setlocal [C:\work\wo
rk\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\Mi
crosoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E make_directory C:/work/work/tmp/thing/b [C:\wor
k\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq
0 goto :cmEnd [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\Mi
crosoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_if_different C:/work/work/tmp/thing/b/x64/
Release/cargo/build/x86_64-pc-windows-msvc/release/thing.pdb C:/work/work/tmp/thing/b [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq
0 goto :cmEnd [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmEnd [C:\work\work
\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: endlocal & call :cmE
rrorLevel %errorlevel% & goto :cmDone [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmErrorLevel [C:\wo
rk\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: exit /b %1 [C:\work\
work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmDone [C:\work\wor
k\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq
0 goto :VCEnd [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :VCEnd" exited with
code 1. [C:\work\work\tmp\thing\b\_cargo-build_thing.vcxproj]
jschwe commented 5 months ago

Does this behavior still occur with Rust 1.79?

Prior to 1.79, this unintentionally disabled the generation of *.pdb files on MSVC, resulting in the absence of symbols.

Source: https://doc.rust-lang.org/rustc/codegen-options/index.html#strip

diresi commented 5 months ago

I need to step up my google-fu, you're obviously right! Let's close this issue then.

(Ahem. Unless you wanna add some skip-pdb flag for those poor people stuck with 1.75 for a while. But do you?)

diresi commented 5 months ago

Ah, no worries, we're good as it seems. strip doesn't make a difference in that particular binary, so why bother?