Skip to content

Commit b6c6198

Browse files
Introduce reproducible builds and always normalize temporary names [GH #426]
This commit also: - updates the copyright notice in the version command to credit contributors - and removes the Edison Design Group-specific DEMO_VERSION_ID configuration option.
1 parent 2bba4a5 commit b6c6198

81 files changed

Lines changed: 458 additions & 630 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CMakeLists.txt‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
2626
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2727
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2828

29+
# A generator expression that is true for the build types that generate
30+
# debugging information (for use as "$<${EDG_HAS_DEBUG_INFO}:...>").
31+
set(EDG_HAS_DEBUG_INFO "$<CONFIG:Debug,RelWithDebInfo>")
32+
2933
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
3034
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3135
if (UNIX AND NOT APPLE)
3236
# Perform static linking of the binary.
3337
add_link_options("$<$<CONFIG:Release>:-static>")
3438
endif()
3539
# If we're building with GCC or any variant of Clang, use -g3 as our debug
36-
# flag to include macro information in our debug builds.
37-
add_compile_options("$<$<CONFIG:Debug>:-g3>")
40+
# flag to include macro information in builds with debugging information.
41+
add_compile_options("$<${EDG_HAS_DEBUG_INFO}:-g3>")
3842
endif()
3943

4044
# Attempt to determine the best linker
@@ -96,6 +100,27 @@ set(EDG_EAGER_REBUILD_LIB FALSE CACHE BOOL
96100
# Support for 32-bit build
97101
set(32BIT_BUILD FALSE CACHE BOOL "Build cpfe as a 32-bit executable")
98102

103+
# Support for reproducible builds. A build identifier replaces the build date
104+
# and time in the front end (see src/CMakeLists.txt).
105+
set(EDG_BUILD_IDENTIFIER "" CACHE STRING
106+
"Build identifier to use in place of the build date and time")
107+
if(NOT "$CACHE{EDG_BUILD_IDENTIFIER}" STREQUAL "" AND
108+
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
109+
CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
110+
# In builds with debugging information, record the source and build
111+
# directories as relative paths in that information and in __FILE__, so the
112+
# same sources produce the same executables wherever they are checked out
113+
# and built. The build directory is listed last so that it takes precedence
114+
# when it is inside the source directory. (-ffile-prefix-map is avoided
115+
# because it also remaps the paths recorded for gcov, which coverage reports
116+
# use to find the sources.)
117+
add_compile_options(
118+
"$<${EDG_HAS_DEBUG_INFO}:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>"
119+
"$<${EDG_HAS_DEBUG_INFO}:-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=.>"
120+
"$<${EDG_HAS_DEBUG_INFO}:-fdebug-prefix-map=${CMAKE_BINARY_DIR}=build>"
121+
"$<${EDG_HAS_DEBUG_INFO}:-fmacro-prefix-map=${CMAKE_BINARY_DIR}=build>")
122+
endif()
123+
99124
# Detect the defaults (macro configuration, EDG_BASE, etc.) for this host and
100125
# compiler, used when a configuration doesn't specify them.
101126
include(${CMAKE_SOURCE_DIR}/cmake/host-defaults.cmake)

‎doc/source/build.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,15 @@ and defaults that many configuration macros have). The
607607
``--dump_configuration`` command-line option provides a convenient display of
608608
all configuration macros and their settings.
609609

610+
By default, the ``--version`` and ``--dump_configuration`` output (and the
611+
string that identifies precompiled header files) includes the date and time the
612+
front end was built, so no two builds produce identical executables. Defining
613+
the configuration macro ``BUILD_IDENTIFIER`` as a string literal (with CMake,
614+
``-DEDG_BUILD_IDENTIFIER=``\ *string*) replaces the date and time with that
615+
string, making the build reproducible. Builds of different sources should use
616+
different identifiers so their precompiled headers aren't mistaken for each
617+
other.
618+
610619
A non-legacy target configuration is most easily generated as a derivative from
611620
an existing legacy target configuration using the ``--dump_legacy_as_target``
612621
command-line option. This option takes a target configuration name and

‎lib_src/CMakeLists.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ endif()
1515
# set the project name
1616
project(lib_src NONE)
1717

18+
# Create deterministic archives (with zeroed timestamps, owners, and modes) on
19+
# Linux, where ar and ranlib are expected to be GNU binutils or compatible,
20+
# so that rebuilding the same sources produces the same libraries.
21+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
22+
set(CMAKE_CXX_ARCHIVE_CREATE
23+
"<CMAKE_AR> qcD <TARGET> <LINK_FLAGS> <OBJECTS>")
24+
set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qD <TARGET> <LINK_FLAGS> <OBJECTS>")
25+
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
26+
endif()
27+
1828
# Add the default value of EDG_RUNTIME_LIB to the cache.
1929
if(NOT DEFINED CACHE{EDG_RUNTIME_LIB})
2030
# Use the same environment variables ECCP will be using.

‎lib_src/cmake/lib_build_support.cmake‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,38 @@ function(add_edg_cpp_rt_obj_file src_file_name obj_file_name)
6060
list(APPEND obj_file_deps ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cpfe)
6161
endif()
6262

63+
# eccp runs in the object's directory (which is unique to the target
64+
# platform), where --keep_gen_c leaves the generated C file. Otherwise eccp
65+
# would compile that file in a randomly named temporary directory, whose
66+
# name would end up in the debug information and make the library
67+
# irreproducible.
68+
get_filename_component(obj_dir "${obj_file_name}" DIRECTORY)
69+
70+
# Generate debugging information only for the build types that have it.
71+
# For a reproducible build, also record the source and build directories as
72+
# relative paths in that information (as is done for the front end in the
73+
# top-level CMakeLists.txt). Each option is wrapped separately so that it
74+
# disappears entirely in other build types.
75+
set(debug_options "$<${EDG_HAS_DEBUG_INFO}:-g>")
76+
if(NOT "$CACHE{EDG_BUILD_IDENTIFIER}" STREQUAL "")
77+
list(APPEND debug_options
78+
"$<${EDG_HAS_DEBUG_INFO}:--c_to_obj_option>"
79+
"$<${EDG_HAS_DEBUG_INFO}:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>"
80+
"$<${EDG_HAS_DEBUG_INFO}:--c_to_obj_option>"
81+
"$<${EDG_HAS_DEBUG_INFO}:-fdebug-prefix-map=${CMAKE_BINARY_DIR}=build>")
82+
endif()
83+
6384
add_custom_command(
6485
OUTPUT ${obj_file_name}
6586
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/eccp
66-
# Set the base options
67-
--building_runtime --c++23 -g
68-
# Set the compile definitons
87+
# Set the base options.
88+
--building_runtime --c++23
89+
# Compile the generated C file in the working directory (see obj_dir
90+
# above).
91+
--keep_gen_c
92+
# Add options related to debug builds (as needed).
93+
${debug_options}
94+
# Set the compile definitons.
6995
-DCHECKING=1 -DDEBUG=1
7096
${cmakedef_define_flags}
7197
# Add include dirs.
@@ -84,13 +110,23 @@ function(add_edg_cpp_rt_obj_file src_file_name obj_file_name)
84110
-o ${obj_file_name}
85111
-c ${src_file_name}
86112
DEPENDS ${obj_file_deps}
113+
WORKING_DIRECTORY ${obj_dir}
114+
# Drop the debug options whose generator expressions evaluate to nothing
115+
# (rather than passing eccp empty arguments).
116+
COMMAND_EXPAND_LISTS
87117
)
88118
endfunction()
89119

90120
function(add_edg_cpp_rt_target target_name)
91-
list(TRANSFORM EDG_CINCLDIR_LIST
92-
PREPEND "--sys_include="
93-
OUTPUT_VARIABLE edg_cinl_flags)
121+
set(edg_cinl_flags "")
122+
foreach(edg_cinl_dir IN LISTS EDG_CINCLDIR_LIST)
123+
# Skip empty entries (e.g., from a trailing ":" in EDG_CINCLDIR).
124+
if(NOT edg_cinl_dir STREQUAL "")
125+
get_filename_component(edg_cinl_dir "${edg_cinl_dir}" ABSOLUTE
126+
BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
127+
list(APPEND edg_cinl_flags "--sys_include=${edg_cinl_dir}")
128+
endif()
129+
endforeach()
94130

95131
if(UNIX AND NOT APPLE)
96132
# When building the library on Linux machines, we need to enable g++ mode

‎src/CMakeLists.txt‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
146146
endif()
147147
endif()
148148

149+
# Build identifier
150+
151+
# Replace the build date and time shown by --version (and used to identify
152+
# precompiled headers) with a fixed string, so that rebuilding the same
153+
# sources produces the same executables. (EDG_BUILD_IDENTIFIER is declared in
154+
# the top-level CMakeLists.txt.)
155+
if(NOT "$CACHE{EDG_BUILD_IDENTIFIER}" STREQUAL "")
156+
add_compile_definitions(
157+
"BUILD_IDENTIFIER=\"$CACHE{EDG_BUILD_IDENTIFIER}\"")
158+
endif()
159+
149160
# Enable colored output.
150161

151162
if (${FORCE_COLORED_OUTPUT})
@@ -254,3 +265,33 @@ add_custom_target(cpfe-all)
254265
add_subdirectory(cmake/cpfe)
255266
add_subdirectory(cmake/cpfe-cp)
256267
add_subdirectory(cmake/cdisp)
268+
269+
# GCC otherwise seeds some generated names and the gcov stamps in objects and
270+
# .gcno files with the time of compilation. The seed should differ for every
271+
# file compiled, so derive it from each source's path relative to the
272+
# repository root (which, unlike the absolute path, is the same in every
273+
# checkout).
274+
if(NOT "$CACHE{EDG_BUILD_IDENTIFIER}" STREQUAL "" AND
275+
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
276+
function(add_random_seeds_to_targets_in dir)
277+
get_property(targets DIRECTORY "${dir}" PROPERTY BUILDSYSTEM_TARGETS)
278+
foreach(target IN LISTS targets)
279+
get_target_property(sources "${target}" SOURCES)
280+
get_target_property(source_dir "${target}" SOURCE_DIR)
281+
foreach(source IN LISTS sources)
282+
if(source MATCHES "\\.(c|cc|cpp)$")
283+
get_filename_component(source_path "${source}" ABSOLUTE
284+
BASE_DIR "${source_dir}")
285+
file(RELATIVE_PATH seed "${CMAKE_SOURCE_DIR}" "${source_path}")
286+
set_property(SOURCE "${source}" TARGET_DIRECTORY "${target}"
287+
PROPERTY COMPILE_OPTIONS "-frandom-seed=${seed}")
288+
endif()
289+
endforeach()
290+
endforeach()
291+
get_property(subdirs DIRECTORY "${dir}" PROPERTY SUBDIRECTORIES)
292+
foreach(subdir IN LISTS subdirs)
293+
add_random_seeds_to_targets_in("${subdir}")
294+
endforeach()
295+
endfunction()
296+
add_random_seeds_to_targets_in("${CMAKE_CURRENT_SOURCE_DIR}")
297+
endif()

‎src/cmd_line.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6472,8 +6472,8 @@ file.
64726472
/* Print a banner. */
64736473
fprintf(f_error,
64746474
"/* Configuration data for Edison Design Group C/C++ Front End */\n"
6475-
"/* version %s, built on %s at %s. */\n\n",
6476-
VERSION_NUMBER, build_date, build_time);
6475+
"/* version %s (%s). */\n\n",
6476+
VERSION_NUMBER, build_stamp);
64776477
/* Print the values of all configuration macros. */
64786478
#if defined(ABI_CHANGES_FOR_ARRAY_NEW_AND_DELETE)
64796479
define_numeric_valued_macro(ABI_CHANGES_FOR_ARRAY_NEW_AND_DELETE);
@@ -6718,6 +6718,11 @@ file.
67186718
#else /* !defined(BOOL_ENABLING_POSSIBLE) */
67196719
comment_undefined_macro_name(BOOL_ENABLING_POSSIBLE);
67206720
#endif /* defined(BOOL_ENABLING_POSSIBLE) */
6721+
#if defined(BUILD_IDENTIFIER)
6722+
define_string_valued_macro(BUILD_IDENTIFIER);
6723+
#else /* !defined(BUILD_IDENTIFIER) */
6724+
comment_undefined_macro_name(BUILD_IDENTIFIER);
6725+
#endif /* defined(BUILD_IDENTIFIER) */
67216726
#if defined(BUILTIN_FUNCTIONS_ENABLED)
67226727
define_string_valued_macro(BUILTIN_FUNCTIONS_ENABLED);
67236728
#else /* !defined(BUILTIN_FUNCTIONS_ENABLED) */
@@ -7819,11 +7824,6 @@ file.
78197824
#else /* !defined(DELETE_CAN_BE_FOLDED_INTO_DTOR) */
78207825
comment_undefined_macro_name(DELETE_CAN_BE_FOLDED_INTO_DTOR);
78217826
#endif /* defined(DELETE_CAN_BE_FOLDED_INTO_DTOR) */
7822-
#if defined(DEMO_VERSION_ID)
7823-
define_string_valued_macro(DEMO_VERSION_ID);
7824-
#else /* !defined(DEMO_VERSION_ID) */
7825-
comment_undefined_macro_name(DEMO_VERSION_ID);
7826-
#endif /* defined(DEMO_VERSION_ID) */
78277827
#if defined(DIRECTORY_SEPARATOR)
78287828
define_string_valued_macro(DIRECTORY_SEPARATOR);
78297829
#else /* !defined(DIRECTORY_SEPARATOR) */
@@ -10788,12 +10788,10 @@ Process the arguments on the command line that invoked the compiler.
1078810788
/* Print out compiler version. */
1078910789
check_assertion(opt_value == TRUE);
1079010790
fprintf(f_error,
10791-
"Edison Design Group C/C++ Front End, version %s (%s %s)\n",
10792-
VERSION_NUMBER, build_date, build_time);
10793-
fprintf(f_error, "Copyright 1988-2026 Edison Design Group, Inc.\n");
10794-
#ifdef DEMO_VERSION_ID
10795-
fprintf(f_error, "Demonstration version for %s\n", DEMO_VERSION_ID);
10796-
#endif /* ifdef DEMO_VERSION_ID */
10791+
"Edison Design Group C/C++ Front End, version %s (%s)\n",
10792+
VERSION_NUMBER, build_stamp);
10793+
fprintf(f_error, "Copyright 1988-2026 Edison Design Group, Inc. "
10794+
"and Contributors\n");
1079710795
fputc('\n', f_error);
1079810796
source_file_name_optional = TRUE;
1079910797
break;

‎src/host_envir.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,12 +2551,6 @@ If only one CPU id is needed, HOSTID should be set, and HOSTID2 should be
25512551
left undefined.
25522552
*/
25532553

2554-
/*
2555-
The flag DEMO_VERSION_ID can be defined with a string identifying a demo
2556-
version if this is a demo version. The string is printed on startup with
2557-
the -v option.
2558-
*/
2559-
25602554
/*
25612555
Flag that provides the default value for null_chars_allowed_in_source,
25622556
which controls whether null (zero) characters are allowed in source lines.

0 commit comments

Comments
 (0)