diff mbox series

python3-cython: make generated _cyutility.c be reproducible

Message ID 20260424035607.419983-1-zhixiong.chi@windriver.com
State Under Review
Headers show
Series python3-cython: make generated _cyutility.c be reproducible | expand

Commit Message

Zhixiong Chi April 24, 2026, 3:56 a.m. UTC
While python3 module use cython to build library, the generated source file
_cyutility.c is not stable at each build and made the generated library not
be reproducible

This commit replace un-predictable tmpfolder string with fixed symlink in
generated source file to assure the generated library should be reproducible.

Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
---
 ...link-to-the-unpredictable-tmpdir-for.patch | 65 +++++++++++++++++++
 .../python/python3-cython_3.2.4.bb            |  1 +
 2 files changed, 66 insertions(+)
 create mode 100644 meta/recipes-devtools/python/python3-cython/0001-Create-fixed-symlink-to-the-unpredictable-tmpdir-for.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/python/python3-cython/0001-Create-fixed-symlink-to-the-unpredictable-tmpdir-for.patch b/meta/recipes-devtools/python/python3-cython/0001-Create-fixed-symlink-to-the-unpredictable-tmpdir-for.patch
new file mode 100644
index 0000000000..005ee4224c
--- /dev/null
+++ b/meta/recipes-devtools/python/python3-cython/0001-Create-fixed-symlink-to-the-unpredictable-tmpdir-for.patch
@@ -0,0 +1,65 @@ 
+From 42bb8d553defb250cd3ccdd539ff5a9c14a8421a Mon Sep 17 00:00:00 2001
+From: Zhixiong Chi <zhixiong.chi@windriver.com>
+Date: Thu, 23 Apr 2026 00:19:59 -0700
+Subject: [PATCH] Create fixed symlink to the unpredictable tmpdir for
+ sharedmodule
+
+When the option "--generated-shared" is used to generated __cyutility as the
+link https://github.com/scikit-learn/scikit-learn/pull/31151/files, the path
+for filename_table in the generated pyx/c file contains tmp dir which is not
+predictable, and it caused the generated output file is not stable at each
+build and made the generated library is not reproducible [1] between builds.
+
+example as python3_pandas:
+
+vim build/_cyutility.c
+......
+/* #### Code section: filename_table ### */
+
+static const char* const __pyx_f[] = {
+  "../../../../../../../../../../../../tmp/tmpXXXXXX/_cyutility.pyx",
+  "<stringsource>",
+};
+
+Replace with the fixed tmp symlink, it is no harm to tweak comments in source
+file, after applied this commit, vim build/_cyutility.c
+......
+/* #### Code section: filename_table ### */
+
+static const char* const __pyx_f[] = {
+  "../../../../../../../../../../../../tmp/cython_shared/_cyutility.pyx",
+  "<stringsource>",
+};
+
+[1] https://reproducible-builds.org/
+
+Upstream-Status: Submitted [https://github.com/cython/cython/pull/7634]
+Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
+---
+ Cython/Build/SharedModule.py | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/Cython/Build/SharedModule.py b/Cython/Build/SharedModule.py
+index b466e57ed..f99fdabb6 100644
+--- a/Cython/Build/SharedModule.py
++++ b/Cython/Build/SharedModule.py
+@@ -76,9 +76,14 @@ def generate_shared_module(options):
+     context = Main.Context.from_options(options)
+     scope = Symtab.ModuleScope('MemoryView', parent_module = None, context = context, is_package=False)
+ 
++    fixed_tmp_link = "/tmp/cython_shared"
++
+     with tempfile.TemporaryDirectory() as tmpdirname:
+-        pyx_file = os.path.join(tmpdirname, f'{module_name}.pyx')
+-        c_file = os.path.join(tmpdirname, f'{module_name}.c')
++        if os.path.exists(fixed_tmp_link) or os.path.islink(fixed_tmp_link):
++            os.unlink(fixed_tmp_link)
++        os.symlink(tmpdirname, fixed_tmp_link)
++        pyx_file = os.path.join(fixed_tmp_link, f'{module_name}.pyx')
++        c_file = os.path.join(fixed_tmp_link, f'{module_name}.c')
+         with open(pyx_file, 'w'):
+             pass
+         source_desc = FileSourceDescriptor(pyx_file)
+-- 
+2.49.0
+
diff --git a/meta/recipes-devtools/python/python3-cython_3.2.4.bb b/meta/recipes-devtools/python/python3-cython_3.2.4.bb
index 3e889857e1..4c2c8e848c 100644
--- a/meta/recipes-devtools/python/python3-cython_3.2.4.bb
+++ b/meta/recipes-devtools/python/python3-cython_3.2.4.bb
@@ -13,6 +13,7 @@  inherit pypi setuptools3 cython
 
 SRC_URI += " \
     file://0001-Replace-not-predictable-build-path-prefix-with-hardc.patch \
+    file://0001-Create-fixed-symlink-to-the-unpredictable-tmpdir-for.patch \
 "
 
 # No need to depend on self