Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Reproducible build with build_type=Debug #16967

Open
1 task done
Paultergeist opened this issue Sep 10, 2024 · 1 comment
Open
1 task done

[question] Reproducible build with build_type=Debug #16967

Paultergeist opened this issue Sep 10, 2024 · 1 comment
Assignees

Comments

@Paultergeist
Copy link

What is your question?

Documentation on Revisions has the following paragraph:

Best practices
Having more than 1 package revision for any given recipe revision + package_id is a smell or a potential bad practice. It means that something was rebuilt when it was not necessary, wasting computing and storage resources. There are ways to avoid doing it, like conan create . --build=missing:hello* will only build that package binary if it doesn’t exist already (or running conan graph info can also return information of what needs to be built.)

But because the build folder is different every time, Debug builds will always have different package revision even if nothing changes.

For example, if I create a new recipe with conan new:

conan new -d name=test_repro -d version=1.0 cmake_lib

and the build it twice with build_type=Release, package revision will be identical

% conan create . -s build_type=Release |& grep "Full package reference:"
test_repro/1.0: Full package reference: test_repro/1.0#4dd8581d5fb0f28ec7588863214486c4:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe#e61283aaa4c05b1b608229fcabe536b8
% conan create . -s build_type=Release |& grep "Full package reference:"
test_repro/1.0: Full package reference: test_repro/1.0#4dd8581d5fb0f28ec7588863214486c4:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe#e61283aaa4c05b1b608229fcabe536b8

But if I build with build_type=Debug twice in a row, I'll get two different revisions:

% conan create . -s build_type=Debug |& grep "Full package reference:"
test_repro/1.0: Full package reference: test_repro/1.0#4dd8581d5fb0f28ec7588863214486c4:451c431212a77cf562d97fe96ec83958609ba9e0#b853aa3f83f93ebf39cda69ffa5de8a1
% conan create . -s build_type=Debug |& grep "Full package reference:"
test_repro/1.0: Full package reference: test_repro/1.0#4dd8581d5fb0f28ec7588863214486c4:451c431212a77cf562d97fe96ec83958609ba9e0#e255e572311e32b0e5616e038df56493

My assumption that it's because build folder is different every time and path to sources gets embedded into binary as debug info.

% conan create . -s build_type=Debug |& grep "Build folder"
test_repro/1.0: Build folder /home/paul/.conan2/p/b/test_04e33249bdcc1/b/build/Debug
% conan create . -s build_type=Debug |& grep "Build folder"
test_repro/1.0: Build folder /home/paul/.conan2/p/b/test_94ae3a2fa0641/b/build/Debug
% conan create . -s build_type=Debug
<...skipped...>
test_repro/1.0: Package '451c431212a77cf562d97fe96ec83958609ba9e0' built
test_repro/1.0: Build folder /home/paul/.conan2/p/b/test_2137bcb049a84/b/build/Debug
test_repro/1.0: Generating the package
test_repro/1.0: Packaging in folder /home/paul/.conan2/p/b/test_2137bcb049a84/p
test_repro/1.0: Calling package()
test_repro/1.0: Running CMake.install()
test_repro/1.0: RUN: cmake --install "/home/paul/.conan2/p/b/test_2137bcb049a84/b/build/Debug" --prefix "/home/paul/.conan2/p/b/test_2137bcb049a84/p"
-- Install configuration: "Debug"
-- Installing: /home/paul/.conan2/p/b/test_2137bcb049a84/p/lib/libtest_repro.a
-- Installing: /home/paul/.conan2/p/b/test_2137bcb049a84/p/include/test_repro.h

test_repro/1.0: package(): Packaged 1 '.h' file: test_repro.h
test_repro/1.0: package(): Packaged 1 '.a' file: libtest_repro.a
test_repro/1.0: Created package revision 2f8c1fe52aab32626fbfbfa0710576c5
test_repro/1.0: Package '451c431212a77cf562d97fe96ec83958609ba9e0' created
test_repro/1.0: Full package reference: test_repro/1.0#4dd8581d5fb0f28ec7588863214486c4:451c431212a77cf562d97fe96ec83958609ba9e0#2f8c1fe52aab32626fbfbfa0710576c5
test_repro/1.0: Package folder /home/paul/.conan2/p/b/test_2137bcb049a84/p
% grep 2137bcb049a84 /home/paul/.conan2/p/b/test_2137bcb049a84/p/lib/libtest_repro.a
grep: /home/paul/.conan2/p/b/test_2137bcb049a84/p/lib/libtest_repro.a: binary file matches

So the question is - how to have reproducible builds with debug info? And why is build folder different every time?

The only way I see currently is to manually do

conan install && conan build && conan export-pkg

but maybe there is better solution?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Sep 11, 2024
@memsharded
Copy link
Member

Hi @Paultergeist

Thanks for your question.

The truth is that C++ are not deterministic in the general case, there are many other factors that can change the resulting binary beyond some source paths. So it could also easily affect Release builds as well. And they could be different package revisions even if the folder would be the same.

The real solution is not rebuilding again from source or recreating a package that already exists. This can be easily achieved with conan create ... --build=missing.
In Conan 2, having more than 1 package revision for the same recipe-revision + package_id is considered a model or process error, and it should be avoided altogether in the first place (basically with the help of --build=missing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants