Skip to content

Commit 3c39ac8

Browse files
committed
Work around naming of static libs.
1 parent 95c0dbc commit 3c39ac8

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

setuptools/_distutils/compilers/C/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ def link(
715715
extra_postargs: list[str] | None = None,
716716
build_temp: str | os.PathLike[str] | None = None,
717717
target_lang: str | None = None,
718+
extra_midargs = None,
718719
):
719720
"""Link a bunch of stuff together to create an executable or
720721
shared library file.
@@ -778,6 +779,7 @@ def link_shared_lib(
778779
build_temp: str | os.PathLike[str] | None = None,
779780
target_lang: str | None = None,
780781
):
782+
raise NotImplementedError('Building shared libs is disabled for Nuitka-Python')
781783
self.link(
782784
Compiler.SHARED_LIBRARY,
783785
objects,
@@ -809,6 +811,7 @@ def link_shared_object(
809811
build_temp: str | os.PathLike[str] | None = None,
810812
target_lang: str | None = None,
811813
):
814+
raise NotImplementedError('Building shared libs is disabled for Nuitka-Python')
812815
self.link(
813816
Compiler.SHARED_OBJECT,
814817
objects,
@@ -837,6 +840,7 @@ def link_executable(
837840
extra_preargs: list[str] | None = None,
838841
extra_postargs: list[str] | None = None,
839842
target_lang: str | None = None,
843+
extra_midargs = None,
840844
):
841845
self.link(
842846
Compiler.EXECUTABLE,
@@ -852,6 +856,7 @@ def link_executable(
852856
extra_postargs,
853857
None,
854858
target_lang,
859+
extra_midargs,
855860
)
856861

857862
# -- Miscellaneous methods -----------------------------------------
@@ -1122,6 +1127,9 @@ def library_filename(
11221127
fmt = getattr(self, lib_type + "_lib_format")
11231128
ext = getattr(self, lib_type + "_lib_extension")
11241129

1130+
if libname.endswith(ext):
1131+
ext = ""
1132+
11251133
dir, base = os.path.split(libname)
11261134
filename = fmt % (base, ext)
11271135
if strip_dir:
@@ -1390,5 +1398,9 @@ def gen_lib_options(
13901398
f"no library file corresponding to '{lib}' found (skipping)"
13911399
)
13921400
else:
1393-
lib_opts.append(compiler.library_option(lib))
1401+
lib_file = compiler.find_library_file(library_dirs, lib_name)
1402+
if lib_file is not None and lib_file.endswith('.a'):
1403+
lib_opts.append(lib_file)
1404+
else:
1405+
lib_opts.append(compiler.library_option(lib))
13941406
return lib_opts

setuptools/_distutils/compilers/C/msvc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ def initialize(self, plat_name: str | None = None) -> None:
311311
# bpo-38597: Always compile with dynamic linking
312312
# Future releases of Python 3.x will include all past
313313
# versions of vcruntime*.dll for compatibility.
314-
self.compile_options = ['/nologo', '/O2', '/W3', '/GL', '/DNDEBUG', '/MD']
314+
self.compile_options = ['/nologo', '/O2', '/W3', '/GL', '/DNDEBUG', '/MT']
315315

316316
self.compile_options_debug = [
317317
'/nologo',
318318
'/Od',
319-
'/MDd',
319+
'/MTd',
320320
'/Zi',
321321
'/W3',
322322
'/D_DEBUG',
@@ -476,6 +476,8 @@ def create_static_lib(
476476
objects, output_dir = self._fix_object_args(objects, output_dir)
477477
output_filename = self.library_filename(output_libname, output_dir=output_dir)
478478

479+
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
480+
479481
if self._need_link(objects, output_filename):
480482
lib_args = objects + ['/OUT:' + output_filename]
481483
if debug:
@@ -503,6 +505,7 @@ def link(
503505
extra_postargs: Iterable[str] | None = None,
504506
build_temp: str | os.PathLike[str] | None = None,
505507
target_lang: str | None = None,
508+
extra_midargs = None,
506509
) -> None:
507510
if not self.initialized:
508511
self.initialize()
@@ -544,6 +547,8 @@ def link(
544547

545548
if extra_preargs:
546549
ld_args[:0] = extra_preargs
550+
if extra_midargs:
551+
ld_args.extend(extra_midargs)
547552
if extra_postargs:
548553
ld_args.extend(extra_postargs)
549554

@@ -598,6 +603,8 @@ def library_option(self, lib):
598603
return self.library_filename(lib)
599604

600605
def find_library_file(self, dirs, lib, debug=False):
606+
if len(dirs) == 1 and os.path.isfile(os.path.join(dirs[0], lib)):
607+
return os.path.join(dirs[0], lib)
601608
# Prefer a debugging library if found (and requested), but deal
602609
# with it if we don't have one.
603610
if debug:

setuptools/_distutils/compilers/C/unix.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ class Compiler(base.Compiler):
138138
if sys.platform[:6] == "darwin":
139139
executables['ranlib'] = ["ranlib"]
140140

141+
# Nuitka: Make sure to use the original settings
142+
executables["compiler"] = sysconfig.get_config_var("CC")
143+
executables["compiler_so"] = sysconfig.get_config_var("CC")
144+
executables["compiler_cxx"] = sysconfig.get_config_var("CXX")
145+
executables["linker_so"] = sysconfig.get_config_var("CC")
146+
executables["linker_exe"] = sysconfig.get_config_var("CC")
147+
141148
# Needed for the filename generation methods provided by the base
142149
# class, CCompiler. NB. whoever instantiates/uses a particular
143150
# UnixCCompiler instance should set 'shared_lib_ext' -- we set a
@@ -229,6 +236,8 @@ def create_static_lib(
229236

230237
output_filename = self.library_filename(output_libname, output_dir=output_dir)
231238

239+
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
240+
232241
if self._need_link(objects, output_filename):
233242
self.mkpath(os.path.dirname(output_filename))
234243
self.spawn(self.archiver + [output_filename] + objects + self.objects)
@@ -261,6 +270,7 @@ def link(
261270
extra_postargs=None,
262271
build_temp=None,
263272
target_lang=None,
273+
extra_midargs=None,
264274
):
265275
objects, output_dir = self._fix_object_args(objects, output_dir)
266276
fixed_args = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
@@ -273,11 +283,14 @@ def link(
273283
output_filename = os.path.join(output_dir, output_filename)
274284

275285
if self._need_link(objects, output_filename):
276-
ld_args = objects + self.objects + lib_opts + ['-o', output_filename]
286+
ld_args = objects + self.objects
277287
if debug:
278288
ld_args[:0] = ['-g']
289+
if extra_midargs:
290+
ld_args += extra_midargs
279291
if extra_preargs:
280292
ld_args[:0] = extra_preargs
293+
ld_args += lib_opts + ['-o', output_filename]
281294
if extra_postargs:
282295
ld_args.extend(extra_postargs)
283296
self.mkpath(os.path.dirname(output_filename))
@@ -286,6 +299,8 @@ def link(
286299
# building an executable or linker_so (with shared options)
287300
# when building a shared library.
288301
building_exe = target_desc == base.Compiler.EXECUTABLE
302+
if not building_exe:
303+
raise NotImplemented("No shared libs in Nuitka-Python")
289304
linker = (
290305
self.linker_exe
291306
if building_exe
@@ -408,10 +423,10 @@ def find_library_file(self, dirs, lib, debug=False):
408423
assume that *all* Unix C compilers do,
409424
ignoring even GCC's "-static" option.
410425
"""
411-
lib_names = (
426+
lib_names = [lib] + [
412427
self.library_filename(lib, lib_type=type)
413428
for type in 'dylib xcode_stub shared static'.split()
414-
)
429+
]
415430

416431
roots = map(self._library_root, dirs)
417432

setuptools/_distutils/file_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def copy_file( # noqa: C901
104104
from distutils._modified import newer
105105
from stat import S_IMODE, ST_ATIME, ST_MODE, ST_MTIME
106106

107+
if not os.path.isfile(src):
108+
src = os.path.join(os.path.dirname(src), "lib" + os.path.basename(src))
109+
if not os.path.isfile(src):
110+
src = os.path.join(os.path.dirname(src), os.path.basename(src) + ".a")
107111
if not os.path.isfile(src):
108112
raise DistutilsFileError(
109113
f"can't copy '{src}': doesn't exist or not a regular file"

0 commit comments

Comments
 (0)