From 0d57a59b6ef0466d5680ef343977ddedfc092bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sat, 20 Apr 2024 11:21:39 +0200 Subject: [PATCH 1/7] cmake: add reproductible build option --- CMakeLists.txt | 14 ++++++++++++++ Common++/header/PcapPlusPlusVersion.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3066d9482e..2ed5a2da94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,7 @@ cmake_dependent_option( option(PCAPPP_BUILD_TESTS "Build Tests" ${PCAPPP_MAIN_PROJECT}) option(PCAPPP_BUILD_COVERAGE "Generate Coverage Report" OFF) option(PCAPPP_BUILD_FUZZERS "Build Fuzzers binaries" OFF) +option(PCAPPP_BUILD_REPRODUCTIBLE "Build a reproductible version" OFF) option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) @@ -259,6 +260,19 @@ if(PCAPPP_TARGET_COMPILER_CLANG add_compile_options(-Wall) endif() +if (PCAPPP_BUILD_REPRODUCTIBLE) + add_definitions(-DPCAPPP_BUILD_REPRODUCTIBLE) + # We should not use __DATE__ nor __TIME__ in case of reproductible build + add_compile_options($<$:-Wdate-time>) + if(APPLE) + if (NOT $ENV{ZERO_AR_DATE}) + message(FATAL_ERROR "You need to set `export ZERO_AR_DATE=1`") + endif() + else() + add_link_options(-D) + endif() +endif() + if(PCAPPP_BUILD_FUZZERS) add_compile_options(-w) endif() diff --git a/Common++/header/PcapPlusPlusVersion.h b/Common++/header/PcapPlusPlusVersion.h index 22edfc4a97..00d6e57bce 100644 --- a/Common++/header/PcapPlusPlusVersion.h +++ b/Common++/header/PcapPlusPlusVersion.h @@ -37,10 +37,17 @@ namespace pcpp /** * @return The build date and time in a format of "Mmm dd yyyy hh:mm:ss" */ +#if PCAPPP_BUILD_REPRODUCTIBLE + inline std::string getBuildDateTime() + { + return " "; + } +#else inline std::string getBuildDateTime() { return std::string(__DATE__) + " " + std::string(__TIME__); } +#endif /** * @return The Git commit (revision) the binaries are built from From 9a1ed5699e75894e7bbb8a1b57a50088c9f2cc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sat, 20 Apr 2024 17:37:09 +0200 Subject: [PATCH 2/7] fix typo + add MSVC --- CMakeLists.txt | 13 +++++++------ Common++/header/PcapPlusPlusVersion.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ed5a2da94..eb25b01b62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ cmake_dependent_option( option(PCAPPP_BUILD_TESTS "Build Tests" ${PCAPPP_MAIN_PROJECT}) option(PCAPPP_BUILD_COVERAGE "Generate Coverage Report" OFF) option(PCAPPP_BUILD_FUZZERS "Build Fuzzers binaries" OFF) -option(PCAPPP_BUILD_REPRODUCTIBLE "Build a reproductible version" OFF) +option(PCAPPP_BUILD_REPRODUCIBLE "Build a reproducible version" OFF) option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) @@ -260,16 +260,17 @@ if(PCAPPP_TARGET_COMPILER_CLANG add_compile_options(-Wall) endif() -if (PCAPPP_BUILD_REPRODUCTIBLE) - add_definitions(-DPCAPPP_BUILD_REPRODUCTIBLE) - # We should not use __DATE__ nor __TIME__ in case of reproductible build - add_compile_options($<$:-Wdate-time>) +if (PCAPPP_BUILD_REPRODUCIBLE) + add_definitions(-DPCAPPP_BUILD_REPRODUCIBLE) if(APPLE) if (NOT $ENV{ZERO_AR_DATE}) message(FATAL_ERROR "You need to set `export ZERO_AR_DATE=1`") endif() + elseif(MSVC) + add_link_options(/Brepro) else() - add_link_options(-D) + # We should not use __DATE__ nor __TIME__ in case of reproducible build + add_compile_options(-Wdate-time) endif() endif() diff --git a/Common++/header/PcapPlusPlusVersion.h b/Common++/header/PcapPlusPlusVersion.h index 00d6e57bce..c005da44b4 100644 --- a/Common++/header/PcapPlusPlusVersion.h +++ b/Common++/header/PcapPlusPlusVersion.h @@ -37,7 +37,7 @@ namespace pcpp /** * @return The build date and time in a format of "Mmm dd yyyy hh:mm:ss" */ -#if PCAPPP_BUILD_REPRODUCTIBLE +#if PCAPPP_BUILD_REPRODUCIBLE inline std::string getBuildDateTime() { return " "; From 39d4a5fad503ccd8461aab6249af296032bfe1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sat, 20 Apr 2024 19:04:23 +0200 Subject: [PATCH 3/7] fix cmake format --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb25b01b62..138f9520bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,10 +260,10 @@ if(PCAPPP_TARGET_COMPILER_CLANG add_compile_options(-Wall) endif() -if (PCAPPP_BUILD_REPRODUCIBLE) +if(PCAPPP_BUILD_REPRODUCIBLE) add_definitions(-DPCAPPP_BUILD_REPRODUCIBLE) if(APPLE) - if (NOT $ENV{ZERO_AR_DATE}) + if(NOT $ENV{ZERO_AR_DATE}) message(FATAL_ERROR "You need to set `export ZERO_AR_DATE=1`") endif() elseif(MSVC) From 8eb2b4a86a04c8c72c92f16f1dbe9c63645a0aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Wed, 24 Apr 2024 10:17:48 +0200 Subject: [PATCH 4/7] cmake: disable incremental build in reproducible mode --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 138f9520bf..9e164c6c76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,6 +268,7 @@ if(PCAPPP_BUILD_REPRODUCIBLE) endif() elseif(MSVC) add_link_options(/Brepro) + add_link_options(/INCREMENTAL:NO) else() # We should not use __DATE__ nor __TIME__ in case of reproducible build add_compile_options(-Wdate-time) From 4eaba951dc57a913e5d8a9789f09198f10326fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sat, 25 May 2024 10:24:07 +0200 Subject: [PATCH 5/7] fix --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e164c6c76..cf8dbc51d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,8 +267,14 @@ if(PCAPPP_BUILD_REPRODUCIBLE) message(FATAL_ERROR "You need to set `export ZERO_AR_DATE=1`") endif() elseif(MSVC) - add_link_options(/Brepro) - add_link_options(/INCREMENTAL:NO) + message(FATAL_ERROR "Unsupported with MSVC compiler") + # Try to build a reproducible static library with MSVC doesn't work + # but this option should make it work for shared libraries or executables. + # add_compile_options(/Brepro) + # add_compile_options(/experimental:deterministic) + # add_link_options(/Brepro) + # add_link_options(/experimental:deterministic) + # add_link_options(/INCREMENTAL:NO) else() # We should not use __DATE__ nor __TIME__ in case of reproducible build add_compile_options(-Wdate-time) From b2a054d67ba7aa561b76eb481cc4f3762aacc409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sat, 20 Jul 2024 17:36:16 +0200 Subject: [PATCH 6/7] cmake: fix format --- CMakeLists.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf8dbc51d3..e25c6c4a67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,13 +268,9 @@ if(PCAPPP_BUILD_REPRODUCIBLE) endif() elseif(MSVC) message(FATAL_ERROR "Unsupported with MSVC compiler") - # Try to build a reproducible static library with MSVC doesn't work - # but this option should make it work for shared libraries or executables. - # add_compile_options(/Brepro) - # add_compile_options(/experimental:deterministic) - # add_link_options(/Brepro) - # add_link_options(/experimental:deterministic) - # add_link_options(/INCREMENTAL:NO) + # Try to build a reproducible static library with MSVC doesn't work but this option should make it work for shared + # libraries or executables. add_compile_options(/Brepro) add_compile_options(/experimental:deterministic) + # add_link_options(/Brepro) add_link_options(/experimental:deterministic) add_link_options(/INCREMENTAL:NO) else() # We should not use __DATE__ nor __TIME__ in case of reproducible build add_compile_options(-Wdate-time) From eafdbbe00e0930caf71ee67d04e52972f46275d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sun, 21 Jul 2024 18:45:49 +0200 Subject: [PATCH 7/7] fix --- Common++/header/PcapPlusPlusVersion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common++/header/PcapPlusPlusVersion.h b/Common++/header/PcapPlusPlusVersion.h index c005da44b4..0f43cea2a8 100644 --- a/Common++/header/PcapPlusPlusVersion.h +++ b/Common++/header/PcapPlusPlusVersion.h @@ -37,7 +37,7 @@ namespace pcpp /** * @return The build date and time in a format of "Mmm dd yyyy hh:mm:ss" */ -#if PCAPPP_BUILD_REPRODUCIBLE +#ifdef PCAPPP_BUILD_REPRODUCIBLE inline std::string getBuildDateTime() { return " ";