@@ -619,7 +619,7 @@ def add_str(content, to_):
619619
620620 # Update <name>-<version>.dist-info/RECORD. This must be last.
621621 #
622- z .writestr (f'{ dist_info_dir } /RECORD' , record .get ())
622+ z .writestr (f'{ dist_info_dir } /RECORD' , record .get (f' { dist_info_dir } /RECORD' ))
623623
624624 st = os .stat (path )
625625 _log ( f'Have created wheel size={ st .st_size } : { path } ' )
@@ -1596,6 +1596,7 @@ def base_compiler(vs=None, pythonflags=None, cpp=False, use_env=True):
15961596 cc = 'em++' if cpp else 'emcc'
15971597 else :
15981598 cc = 'c++' if cpp else 'cc'
1599+ cc = macos_add_cross_flags ( cc )
15991600 return cc , pythonflags
16001601
16011602
@@ -1636,6 +1637,7 @@ def base_linker(vs=None, pythonflags=None, cpp=False, use_env=True):
16361637 linker = 'em++' if cpp else 'emcc'
16371638 else :
16381639 linker = 'c++' if cpp else 'cc'
1640+ linker = macos_add_cross_flags ( linker )
16391641 return linker , pythonflags
16401642
16411643
@@ -1730,6 +1732,9 @@ def wasm():
17301732def pyodide ():
17311733 return os .environ .get ( 'PYODIDE' ) == '1'
17321734
1735+ def linux ():
1736+ return platform .system () == 'Linux'
1737+
17331738class PythonFlags :
17341739 '''
17351740 Compile/link flags for the current python, for example the include path
@@ -1775,11 +1780,38 @@ def __init__(self):
17751780 #if darwin():
17761781 # self.ldflags =
17771782 self .ldflags = run ( f'{ python_config } --ldflags' , capture = 1 ).strip ()
1783+ if linux ():
1784+ # It seems that with python-3.10 on Linux, we can get an
1785+ # incorrect -lcrypt flag that on some systems (e.g. WSL)
1786+ # causes:
1787+ #
1788+ # ImportError: libcrypt.so.2: cannot open shared object file: No such file or directory
1789+ #
1790+ ldflags2 = self .ldflags .replace (' -lcrypt ' , ' ' )
1791+ if ldflags2 != self .ldflags :
1792+ _log (f'### Have removed `-lcrypt` from ldflags: { self .ldflags !r} -> { ldflags2 !r} ' )
1793+ self .ldflags = ldflags2
17781794
17791795 _log (f'self.includes={ self .includes !r} ' )
17801796 _log (f'self.ldflags={ self .ldflags !r} ' )
17811797
17821798
1799+ def macos_add_cross_flags (command ):
1800+ '''
1801+ If running on MacOS and environment variables ARCHFLAGS is set
1802+ (indicating we are cross-building, e.g. for arm64), returns
1803+ `command` with extra flags appended. Otherwise returns unchanged
1804+ `command`.
1805+ '''
1806+ if darwin ():
1807+ archflags = os .environ .get ( 'ARCHFLAGS' )
1808+ if archflags :
1809+ command = f'{ command } { archflags } '
1810+ _log (f'Appending ARCHFLAGS to command: { command } ' )
1811+ return command
1812+ return command
1813+
1814+
17831815def macos_patch ( library , * sublibraries ):
17841816 '''
17851817 If running on MacOS, patches `library` so that all references to items in
@@ -1998,5 +2030,14 @@ def add_file(self, from_, to_, verbose=False):
19982030 if verbose :
19992031 _log (f'Adding file: { os .path .relpath (from_ )} => { to_ } ' )
20002032
2001- def get (self ):
2002- return self .text
2033+ def get (self , record_path = None ):
2034+ '''
2035+ Returns contents of the RECORD file. If `record_path` is
2036+ specified we append a final line `<record_path>,,`; this can be
2037+ used to include the RECORD file itself in the contents, with
2038+ empty hash and size fields.
2039+ '''
2040+ ret = self .text
2041+ if record_path :
2042+ ret += f'{ record_path } ,,\n '
2043+ return ret
0 commit comments