Skip to content

Commit

Permalink
build: add CONFIG_APP_REPRODUCIBLE_BUILD menuconfig option to produce…
Browse files Browse the repository at this point in the history
… reproducible binaries
  • Loading branch information
hfudev committed Oct 26, 2021
1 parent a65de0a commit 9919b75
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .gitlab/ci/host-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ test_ldgen_on_host:
variables:
LC_ALL: C.UTF-8

test_reproducible_build:
extends: .host_test_template
script:
- ./tools/ci/test_reproducible_build.sh
artifacts:
when: on_failure
paths:
- "**/sdkconfig"
- "**/build*/*.bin"
- "**/build*/*.elf"
- "**/build*/*.map"
- "**/build*/flasher_args.json"
- "**/build*/*.bin"
- "**/build*/bootloader/*.bin"
- "**/build*/partition_table/*.bin"
expire_in: 1 week

.host_fuzzer_test_template:
extends:
- .host_test_template
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
- "tools/detect_python.sh"
- "tools/detect_python.fish"

- "tools/ci/test_reproducible_build.sh"

.patterns-windows: &patterns-windows
- "tools/windows/**/*"

Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ endif()
if(NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS 8.0.0)
if(CONFIG_COMPILER_HIDE_PATHS_MACROS)
list(APPEND compile_options "-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=.")
list(APPEND compile_options "-fmacro-prefix-map=${IDF_PATH}=IDF")
list(APPEND compile_options "-fmacro-prefix-map=${IDF_PATH}=/IDF")
endif()

if(CONFIG_APP_REPRODUCIBLE_BUILD)
list(APPEND compile_options "-fdebug-prefix-map=${IDF_PATH}=/IDF")
list(APPEND compile_options "-fdebug-prefix-map=${PROJECT_DIR}=/IDF_PROJECT")
list(APPEND compile_options "-fdebug-prefix-map=${BUILD_DIR}=/IDF_BUILD")
endif()
endif()

Expand Down
7 changes: 7 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ mainmenu "Espressif IoT Development Framework Configuration"
config APP_BUILD_USE_FLASH_SECTIONS
bool # Whether to place code/data into memory-mapped flash sections

config APP_REPRODUCIBLE_BUILD
bool "Enable reproducible build"
default n
select COMPILER_HIDE_PATHS_MACROS
help
If enabled, all date, time, and path information would be eliminated.

endmenu # Build type

source "$COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE"
Expand Down
2 changes: 1 addition & 1 deletion components/app_update/esp_app_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
.secure_version = 0,
#endif

#ifdef CONFIG_APP_COMPILE_TIME_DATE
#if defined(CONFIG_APP_COMPILE_TIME_DATE) && !defined(CONFIG_APP_REPRODUCIBLE_BUILD)
.time = __TIME__,
.date = __DATE__,
#else
Expand Down
2 changes: 2 additions & 0 deletions components/bootloader_support/src/bootloader_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,7 @@ void bootloader_enable_random(void)
void bootloader_print_banner(void)
{
ESP_LOGI(TAG, "ESP-IDF %s 2nd stage bootloader", IDF_VER);
#ifndef CONFIG_APP_REPRODUCIBLE_BUILD
ESP_LOGI(TAG, "compile time " __TIME__);
#endif
}
1 change: 1 addition & 0 deletions tools/ci/executable-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ tools/ci/test_build_system.sh
tools/ci/test_build_system_cmake.sh
tools/ci/test_check_kconfigs.py
tools/ci/test_configure_ci_environment.sh
tools/ci/test_reproducible_build.sh
tools/cmake/convert_to_cmake.py
tools/docker/entrypoint.sh
tools/docker/hooks/build
Expand Down
26 changes: 26 additions & 0 deletions tools/ci/test_reproducible_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -euo

for path in \
"examples/get-started/hello_world" \
"examples/bluetooth/nimble/blecent"; do
cd "${IDF_PATH}/${path}"

echo "CONFIG_APP_REPRODUCIBLE_BUILD=y" >>sdkconfig.defaults
rm -f sdkconfig

idf.py -B build_first fullclean build
idf.py -B build_second fullclean build

for item in \
"partition_table/partition-table.bin" \
"bootloader/bootloader.bin" \
"bootloader/bootloader.elf" \
"bootloader/bootloader.map" \
"*.bin" \
"*.elf" \
"*.map"; do
diff -s build_first/${item} build_second/${item} # use glob, don't use double quotes
done
done

0 comments on commit 9919b75

Please sign in to comment.