<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Reproducible build</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93223/reproducible-build</link><description>I want to achieve reproducible builds on my development machine and a gitlab CI/CD server. So far the generated binary differs if I build locally (VS Code + NRFConnect SDK v2.0.0) and remotely (gitlab CI/CD). 
 I added the GNU Build ID to verify easily</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Oct 2022 14:14:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93223/reproducible-build" /><item><title>RE: Reproducible build</title><link>https://devzone.nordicsemi.com/thread/392670?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 14:14:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96c348db-e647-4a39-9a57-54d7ed606c4f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Good to hear! Thanks for letting us know.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reproducible build</title><link>https://devzone.nordicsemi.com/thread/392653?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 13:46:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eadae1c8-5b03-487c-87d9-cb3e6bb78b6f</guid><dc:creator>vcbz</dc:creator><description>&lt;p&gt;Ok, it seems the binaries are now identical :) It was just that my OS was using another CMAKE version. So basically to reproduce the builds one has to check that the same version bundled by the NRF Connect Desktop app in YOUR_NCS_INSTALL_DIR/YOUR_VERSION/zephyr/opt/bin/cmake (currently cmake 3.20.5) is used.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reproducible build</title><link>https://devzone.nordicsemi.com/thread/392618?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 12:23:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67455b99-c4b4-4887-bb22-b829fcfdfa2e</guid><dc:creator>vcbz</dc:creator><description>&lt;p&gt;&amp;gt; A last point is that you need to build with the exact same tools in order to get the same binaries&lt;br /&gt;&lt;br /&gt;Yes, this is what I would think happens in theory in my ci/cd. I have checked the variables passed to cmake. Snippet as ref:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;pre class="code highlight" lang="cmake"&gt;&lt;span id="LC8" class="line" lang="cmake" data-testid="content"&gt;&lt;span class="hljs-keyword"&gt;get_cmake_property(_variableNames VARIABLES)&lt;br /&gt;list (SORT _variableNames)&lt;br /&gt;file&lt;/span&gt;(WRITE vars.txt)&lt;/span&gt;
&lt;span id="LC9" class="line" lang="cmake" data-testid="content"&gt;&lt;span class="hljs-keyword"&gt;foreach&lt;/span&gt; (_variableName &lt;span class="hljs-variable"&gt;${_variableNames}&lt;/span&gt;)&lt;/span&gt;
&lt;span id="LC10" class="line" lang="cmake" data-testid="content"&gt;    &lt;span class="hljs-keyword"&gt;file&lt;/span&gt;(APPEND vars.txt &lt;span class="hljs-string"&gt;&amp;quot;${_variableName}=${${_variableName}}\n&amp;quot;&lt;/span&gt;)&lt;/span&gt;
&lt;span id="LC11" class="line" lang="cmake" data-testid="content"&gt;&lt;span class="hljs-keyword"&gt;endforeach&lt;/span&gt;()&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;I found out in my west native build without vs code, it uses my CMake installation in C:\Prog Files\Cmake&lt;/p&gt;
&lt;p&gt;After uninstalling cmake, and setting the binary path to C:\MY_NCS_SDK_PATH\v2.0.0/opt/bin, I get identical builds between&lt;br /&gt;west and VS code. I will attempt to fix this in the CI/CD and check if it works.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;And about the requirement, is that we would like to have reproducible builds between CI/CD and local builds. It shouldnt matter if a developer uploads the same compiled source code of a specific commit from local machine or server. &lt;br /&gt;This also allows to debug the same software release if uploaded from local machine or if it was uploaded via OTA from the gitlab server artifacts. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reproducible build</title><link>https://devzone.nordicsemi.com/thread/392615?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 12:11:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2dfd6318-19d8-413d-af31-2f1bc1bb6b04</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see you have resolved most of this. A last point is that you need to build with the exact same tools in order to get the same binaries, so the only thing that seems sensible is to also use the docker image in your local builds.&lt;/p&gt;
&lt;p&gt;This seems like a slightly odd requirement though, particularly for development. Out of curiosity, can you share why you want this? I would suggest to keep a local docker image and use that for builds whenever you need something that would be binary identical, but use VS Code with the toolchain from the toolchain manager for every day development and debugging (for simplicity).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reproducible build</title><link>https://devzone.nordicsemi.com/thread/392484?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2022 21:48:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f19447d-2a30-4cc8-a2f8-0511a035e710</guid><dc:creator>vcbz</dc:creator><description>&lt;p&gt;Ok I have found something interesting. I built the project without the gnu build id to try to dissect the difference between the server and local build.&lt;br /&gt;&lt;br /&gt;the changes to the project are in the branch simple&lt;br /&gt;&lt;br /&gt;&lt;a id="" href="https://git.fh-aachen.de/vc9917e/build_id_test/-/tree/simple"&gt;https://git.fh-aachen.de/vc9917e/build_id_test/-/tree/simple&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What I found out is that if I build the project directly with west from the SDK install dir made by NRF-Connect Desktop I get an almost 100% same binary. &lt;br /&gt;&lt;br /&gt;This is the command&lt;/p&gt;
&lt;p&gt;west build --build-dir MY_BUILD_DIR THE_PROJECT_DIR --pristine --board nrf52833dk_nrf52833&lt;/p&gt;
&lt;p&gt;The only difference with the zephyr.bin generated by the ci/cd server&amp;nbsp; is that the zephyr banner at boot is different. Compiling with the server I only obtain the abbreviated hash commit and with the NRF Connect SDK (obtained via NRF Connect desktop app) on my local machine it retrieves the tag version.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/3702f7220affc5bcf377c4e6c41fc320423d5045/kernel/banner.c#L38"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/3702f7220affc5bcf377c4e6c41fc320423d5045/kernel/banner.c#L38&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I guess this is due to how zephyr gets the BUILD version which is obtained via &amp;quot;git describe&amp;quot; and this soley depends on the depth the repo was cloned.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/604f705fda149dea73e5fc830975e2ccefa994c8/cmake/gen_version_h.cmake#L9"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/604f705fda149dea73e5fc830975e2ccefa994c8/cmake/gen_version_h.cmake#L9&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, if I build via the NRF VS Code plugin the binary changes a lot more. The only difference I see is that the VS Code plugin adds to the west build command the following: &amp;quot;-DNCS_TOOLCHAIN_VERSION:STRING=&amp;quot;NONE&amp;quot;. I have to clarify that the binary size is the same, which after analyzing briefly the assembly seems that some sections of the .text file are moved. This in turn makes references to functions/data change in dissassembly (objdump -d zephyr.elf)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reproducible build</title><link>https://devzone.nordicsemi.com/thread/392477?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2022 19:36:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0044479e-6780-405a-9ce5-daaffcf0d6c5</guid><dc:creator>vcbz</dc:creator><description>&lt;p&gt;Second update. Using -fdebug-prefix-map solved the difference in debug path if compiling the project in diff. directories on the same machine (i.e., gitlab ci/cd). However, the gnu build id is still different between local build and server build&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;zephyr_compile_options(-fdebug-prefix-map=${CMAKE_BINARY_DIR}=BUILD_DIR&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=SRC_DIR&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reproducible build</title><link>https://devzone.nordicsemi.com/thread/392443?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2022 14:47:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97c91535-ae15-465f-9998-c72c90718ebe</guid><dc:creator>vcbz</dc:creator><description>&lt;p&gt;I have an update. I madea new branch and changed the build directory and the build id has changed&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://git.fh-aachen.de/vc9917e/build_id_test/-/compare/main...build_dir_change?from_project_id=26912"&gt;https://git.fh-aachen.de/vc9917e/build_id_test/-/compare/main...build_dir_change?from_project_id=26912&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This means that even just changing the build dir affects the binary even though its the same project, toolchain and sdk.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>