Skip to content

Commit

Permalink
(dbg) They say don't change too many things at once, I say too many d…
Browse files Browse the repository at this point in the history
…amn commit for this crap
  • Loading branch information
MementoRC committed Jan 28, 2024
1 parent fc8433b commit a4dd422
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 65 deletions.
68 changes: 3 additions & 65 deletions setup/setup_build_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,6 @@
from setup.setup_support import exact_library_name


def _update_extension_for_msvc(extension, compiler):
log.info(f'compiler: {compiler}')
log.info(f'extension: {extension.__dict__}')
[log.info(f'extra_link_args[{i}]: {v}') for i, v in enumerate(extension.__dict__.get('extra_link_args'))]

# MSVCCompiler for VisualC on Windows
if compiler == 'UnixCCompiler':
return

path_to_lib = ''

for i, v in enumerate(extension.__dict__.get('extra_link_args')):

# Replace -L with /LIBPATH: for MSVC
if v.startswith('-L'):
path_to_lib = v[2:]
extension.__dict__['extra_link_args'][i] = f'/LIBPATH:{path_to_lib}'

# Replace -l with the library filename for MSVC
if v.startswith('-l'):
v = v.replace('-l', 'lib')

if os.path.isfile(path_to_lib + v + '.lib'):
extension.__dict__['extra_link_args'][i] = f'{v}.lib'

if os.path.isfile(path_to_lib + v + '.a'):
extension.__dict__['extra_link_args'][i] = f'{v}.a'


def _update_extension_for_c_library(extension, c_lib_path=None, c_flags=None):
from setup.setup_config import LIB_NAME
from setup.setup_support import build_flags

if c_lib_path:
# Update include/lib for C-lib linking.
extension.__dict__.get('include_dirs').append(os.path.join(c_lib_path, 'include'))
extension.__dict__.get('include_dirs').extend(c_flags['include_dirs'])

extension.__dict__.get('library_dirs').insert(0, os.path.join(c_lib_path, 'lib'))
extension.__dict__.get('library_dirs').extend(c_flags['library_dirs'])

# This class will call build_clib.get_library_names() to get the list of libraries to link
# However, this would require the build_clib to know the linking compiler.
# Instead, we simply use build_clib detection of the installed libraries and add them directly
extension.__dict__.get('extra_link_args').extend(c_flags['library_fullnames'])

extension.__dict__['define'] = c_flags['define']
return

try:
# Update include/lib for C-lib linking. Append to the 'extra' args
extension.__dict__.get('include_dirs').extend(build_flags(LIB_NAME, 'I'))

# We need to decipher the name of the library from the pkg-config output
for path in build_flags(LIB_NAME, 'L'):
for lib in build_flags(LIB_NAME, 'l'):
extension.__dict__.get('extra_link_args').append(exact_library_name(lib, path))
except subprocess.CalledProcessError as e:
log.error(f'Error: {e}')
raise e


class BuildCFFISetuptools(_build_ext):
static = False

Expand All @@ -95,7 +33,7 @@ def build_extensions(self):
self.define = _build_clib.build_flags['define']

lib_dir = build_flags(LIB_NAME, 'L', pkg_dir)[0]
link_args_msvc = '/LIBPATH:' + lib_dir.replace('/', '\\')
link_args_msvc = ['/LIBPATH:' + lib_dir.replace('/', '\\')]

for _l in build_flags(LIB_NAME, 'l', pkg_dir):
lib_file, lib_fp = exact_library_name(_l, lib_dir)
Expand All @@ -105,7 +43,7 @@ def build_extensions(self):
_a = lib_file
lib_file = lib_file.replace('.a', '.lib')
os.rename(os.path.join(lib_dir, _a), os.path.join(lib_dir, lib_file))
link_args_msvc += f' {lib_file}'
link_args_msvc.append(lib_file)
else:
self.extensions[0].extra_link_args.append(lib_fp)

Expand All @@ -115,7 +53,7 @@ def build_extensions(self):
self.extensions[0].extra_compile_args.extend(['/MT', '/d2FH4-'])

self.extensions[0].extra_link_args.append('/VERBOSE:LIB')
self.extensions[0].extra_link_args.append(link_args_msvc)
self.extensions[0].extra_link_args.extend(link_args_msvc)

log.info(f'build_extensions: MSVCCompiler: {link_args_msvc}')

Expand Down
4 changes: 4 additions & 0 deletions setup/setup_build_secp256k1_with_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def run(self):
'--enable-exhaustive-tests=no',
'--silent',
]

if os.name == 'nt':
cmd.append('CC=cl')

if 'COINCURVE_CROSS_HOST' in os.environ:
cmd.append(f"--host={os.environ['COINCURVE_CROSS_HOST']}")

Expand Down

0 comments on commit a4dd422

Please sign in to comment.