From bb8dc6334018ab47efdedd1f2ad671600a66ef64 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 21 Sep 2021 13:52:22 -0500 Subject: [PATCH 1/4] Use -Wl,-R instead of -R Sometimes _is_gcc will fail to identify a compiler as gcc or sometimes there are compilers that act like gcc with different names. Since all platforms that support -R directly supports -Wl,-R, using -Wl,-R should support more use cases --- distutils/tests/test_unixccompiler.py | 4 ++-- distutils/unixccompiler.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index 1008f58a15..93a4efb9c4 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -177,7 +177,7 @@ def gcv(v): elif v == 'GNULD': return 'yes' sysconfig.get_config_var = gcv - self.assertEqual(self.cc.rpath_foo(), '-R/foo') + self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo') # non-GCC non-GNULD sys.platform = 'bar' @@ -187,7 +187,7 @@ def gcv(v): elif v == 'GNULD': return 'no' sysconfig.get_config_var = gcv - self.assertEqual(self.cc.rpath_foo(), '-R/foo') + self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo') @unittest.skipIf(sys.platform == 'win32', "can't test on Windows") def test_cc_overrides_ldshared(self): diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index 349cc1642b..c05919f53d 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -261,7 +261,7 @@ def runtime_library_dir_option(self, dir): # No idea how --enable-new-dtags would be passed on to # ld if this system was using GNU ld. Don't know if a # system like this even exists. - return "-R" + dir + return "-Wl,-R" + dir def library_option(self, lib): return "-l" + lib From 3b20adbbb2db5a4e36957f8fb339a8051f403e75 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 26 Sep 2021 10:38:49 -0500 Subject: [PATCH 2/4] consolidate the two code paths and update comment --- distutils/tests/test_unixccompiler.py | 2 +- distutils/unixccompiler.py | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index 93a4efb9c4..ee2fe99c07 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -177,7 +177,7 @@ def gcv(v): elif v == 'GNULD': return 'yes' sysconfig.get_config_var = gcv - self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo') + self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo') # non-GCC non-GNULD sys.platform = 'bar' diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index c05919f53d..27fd136dcd 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -246,21 +246,16 @@ def runtime_library_dir_option(self, dir): return ["-Wl,+s", "-L" + dir] return ["+s", "-L" + dir] else: - if self._is_gcc(compiler): - # gcc on non-GNU systems does not need -Wl, but can - # use it anyway. Since distutils has always passed in - # -Wl whenever gcc was used in the past it is probably - # safest to keep doing so. - if sysconfig.get_config_var("GNULD") == "yes": - # GNU ld needs an extra option to get a RUNPATH - # instead of just an RPATH. - return "-Wl,--enable-new-dtags,-R" + dir - else: - return "-Wl,-R" + dir + # gcc on non-GNU systems does not need -Wl, but can + # use it anyway. for all compilers including gcc we assume that + # -Wl is the way to pass a compiler option to the linker + # and for all linkers we assume that -R is the way to set + # an rpath. + if sysconfig.get_config_var("GNULD") == "yes": + # GNU ld needs an extra option to get a RUNPATH + # instead of just an RPATH. + return "-Wl,--enable-new-dtags,-R" + dir else: - # No idea how --enable-new-dtags would be passed on to - # ld if this system was using GNU ld. Don't know if a - # system like this even exists. return "-Wl,-R" + dir def library_option(self, lib): From b5030e080f08402b89a3421d1001d82ebb0d436c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 26 Sep 2021 17:44:10 -0400 Subject: [PATCH 3/4] Reword comments and eliminate unnecessary 'else' --- distutils/unixccompiler.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index 27fd136dcd..a07e598890 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -245,18 +245,16 @@ def runtime_library_dir_option(self, dir): if self._is_gcc(compiler): return ["-Wl,+s", "-L" + dir] return ["+s", "-L" + dir] + + # For all compilers, `-Wl` is the presumed way to + # pass a compiler option to the linker and `-R` is + # the way to pass an RPATH. + if sysconfig.get_config_var("GNULD") == "yes": + # GNU ld needs an extra option to get a RUNPATH + # instead of just an RPATH. + return "-Wl,--enable-new-dtags,-R" + dir else: - # gcc on non-GNU systems does not need -Wl, but can - # use it anyway. for all compilers including gcc we assume that - # -Wl is the way to pass a compiler option to the linker - # and for all linkers we assume that -R is the way to set - # an rpath. - if sysconfig.get_config_var("GNULD") == "yes": - # GNU ld needs an extra option to get a RUNPATH - # instead of just an RPATH. - return "-Wl,--enable-new-dtags,-R" + dir - else: - return "-Wl,-R" + dir + return "-Wl,-R" + dir def library_option(self, lib): return "-l" + lib From 42f0cf2d17c82ec2fde18fa74ff2f7fc0a60d892 Mon Sep 17 00:00:00 2001 From: "Kian-Meng, Ang" Date: Thu, 14 Oct 2021 23:25:59 +0800 Subject: [PATCH 4/4] Fix typos --- distutils/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distutils/util.py b/distutils/util.py index 64f06dd4bc..afc23c4e23 100644 --- a/distutils/util.py +++ b/distutils/util.py @@ -134,14 +134,14 @@ def get_macosx_target_ver(): """Return the version of macOS for which we are building. The target version defaults to the version in sysconfig latched at time - the Python interpreter was built, unless overriden by an environment + the Python interpreter was built, unless overridden by an environment variable. If neither source has a value, then None is returned""" syscfg_ver = get_macosx_target_ver_from_syscfg() env_ver = os.environ.get(MACOSX_VERSION_VAR) if env_ver: - # Validate overriden version against sysconfig version, if have both. + # Validate overridden version against sysconfig version, if have both. # Ensure that the deployment target of the build process is not less # than 10.3 if the interpreter was built for 10.3 or later. This # ensures extension modules are built with correct compatibility