Skip to contentSkip to conversation

perf build: Do not duplicate CFLAGS in Python extension builds

PATCH Applied Jens Remus 3 participants 3 messages Jun 10

Subsystems (2)
lore
Share & tools
lore

Jens Remus

author
#0 lore raw

PATCH 1/1 perf build: Do not duplicate CFLAGS in Python extension builds

setuptools already uses CFLAGS. Passing CFLAGS with additional flags as extra compile arguments causes CFLAGS to effectively get passed twice:

$ make -C tools/perf V=1 JOBS=1
...
building 'perf' extension
gcc [CFLAGS] -fPIC -Iutil/include -I/usr/include/python3.14 \
  -c /root/linux/tools/perf/util/python.c \
  -o python_ext_build/tmp/root/linux/tools/perf/util/python.o \
  [CFLAGS] \
  -fno-strict-aliasing -Wno-write-strings -Wno-unused-parameter \
  -Wno-redundant-decls -Wno-cast-function-type \
  -Wno-declaration-after-statement

---

Notes (jremus):
This patch applies on top of the perf-tools-next tree:

git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git master

Note that my "[PATCH v2] perf build: Respect V=1 for Python extension builds" [1] needs to be applied to actually observe the Python extension build command and output with V=1.

[1]: https://lore.kernel.org/all/[email protected]/

 tools/perf/util/setup.py | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/setup.py +6 -7
index b65b1792ca05..a0ce76624a23 100644
@@ -74,18 +74,17 @@ class install_lib(_install_lib):
         self.build_dir = build_lib
 
 
-cflags = getenv('CFLAGS', '').split()
 # switch off several checks (need to be at the end of cflags list)
-cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
+extra_cflags = ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
 if cc_is_clang:
-    cflags += ["-Wno-unused-command-line-argument" ]
+    extra_cflags += ["-Wno-unused-command-line-argument" ]
     if clang_has_option("-Wno-cast-function-type-mismatch"):
-        cflags += ["-Wno-cast-function-type-mismatch" ]
+        extra_cflags += ["-Wno-cast-function-type-mismatch" ]
 else:
-    cflags += ['-Wno-cast-function-type' ]
+    extra_cflags += ['-Wno-cast-function-type' ]
 
 # The python headers have mixed code with declarations (decls after asserts, for instance)
-cflags += [ "-Wno-declaration-after-statement" ]
+extra_cflags += [ "-Wno-declaration-after-statement" ]
 
 src_perf  = f'{srctree}/tools/perf'
 build_lib = getenv('PYTHON_EXTBUILD_LIB')
@@ -94,7 +93,7 @@ build_tmp = getenv('PYTHON_EXTBUILD_TMP')
 perf = Extension('perf',
                  sources = [ src_perf + '/util/python.c' ],
 		         include_dirs = ['util/include'],
-		         extra_compile_args = cflags,
+		         extra_compile_args = extra_cflags,
                  )
 
 setup(name='perf',
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Jens Remus

setuptools already uses CFLAGS. Passing CFLAGS with additional flags as extra compile arguments causes CFLAGS to effectively get passed twice:

$ make -C tools/perf V=1 JOBS=1
...
building 'perf' extension
gcc [CFLAGS] -fPIC -Iutil/include -I/usr/include/python3.14 \
   -c /root/linux/tools/perf/util/python.c \
   -o python_ext_build/tmp/root/linux/tools/perf/util/python.o \
   [CFLAGS] \
   -fno-strict-aliasing -Wno-write-strings -Wno-unused-parameter \
   -Wno-redundant-decls -Wno-cast-function-type \
   -Wno-declaration-after-statement
Quoted 1 line
Quoted 53 lines

---

Notes (jremus):
This patch applies on top of the perf-tools-next tree:

git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git master

Note that my "[PATCH v2] perf build: Respect V=1 for Python extension builds" [1] needs to be applied to actually observe the Python extension build command and output with V=1.

[1]: https://lore.kernel.org/all/[email protected]/

  tools/perf/util/setup.py | 13 ++++++-------
  1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/setup.py +6 -7
index b65b1792ca05..a0ce76624a23 100644
@@ -74,18 +74,17 @@ class install_lib(_install_lib):
          self.build_dir = build_lib
 
 
-cflags = getenv('CFLAGS', '').split()
  # switch off several checks (need to be at the end of cflags list)
-cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
+extra_cflags = ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
  if cc_is_clang:
-    cflags += ["-Wno-unused-command-line-argument" ]
+    extra_cflags += ["-Wno-unused-command-line-argument" ]
      if clang_has_option("-Wno-cast-function-type-mismatch"):
-        cflags += ["-Wno-cast-function-type-mismatch" ]
+        extra_cflags += ["-Wno-cast-function-type-mismatch" ]
  else:
-    cflags += ['-Wno-cast-function-type' ]
+    extra_cflags += ['-Wno-cast-function-type' ]
 
  # The python headers have mixed code with declarations (decls after asserts, for instance)
-cflags += [ "-Wno-declaration-after-statement" ]
+extra_cflags += [ "-Wno-declaration-after-statement" ]
 
  src_perf  = f'{srctree}/tools/perf'
  build_lib = getenv('PYTHON_EXTBUILD_LIB')
@@ -94,7 +93,7 @@ build_tmp = getenv('PYTHON_EXTBUILD_TMP')
  perf = Extension('perf',
                   sources = [ src_perf + '/util/python.c' ],
  		         include_dirs = ['util/include'],
-		         extra_compile_args = cflags,
+		         extra_compile_args = extra_cflags,
                   )
 
  setup(name='perf',
maintainer Applied
#2 lore raw
Quoted 17 lines · James Clark
Quoted 14 lines · Jens Remus

setuptools already uses CFLAGS. Passing CFLAGS with additional flags as extra compile arguments causes CFLAGS to effectively get passed twice:

$ make -C tools/perf V=1 JOBS=1
...
building 'perf' extension
gcc [CFLAGS] -fPIC -Iutil/include -I/usr/include/python3.14 \
   -c /root/linux/tools/perf/util/python.c \
   -o python_ext_build/tmp/root/linux/tools/perf/util/python.o \
   [CFLAGS] \
   -fno-strict-aliasing -Wno-write-strings -Wno-unused-parameter \
   -Wno-redundant-decls -Wno-cast-function-type \
   -Wno-declaration-after-statement
Quoted 3 lines
Quoted 1 line

Thanks, applied to perf-tools-next, for v7.2.

- Arnaldo