Skip to content

Commit

Permalink
Improve handling available libcurl builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Tester authored and Tester committed Jan 22, 2024
1 parent 5ac5862 commit 42347e6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 24 deletions.
36 changes: 25 additions & 11 deletions scripts/build.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import os
import struct
import platform
import struct

from cffi import FFI


def abs_machine():
machine = platform.machine()

pointer_bits = struct.calcsize("P") * 8
if pointer_bits not in (32, 64):
raise Exception("Unsupported pointer size")

is_64 = pointer_bits == 64

# x86 based archs
if machine in ('AMD64', 'x86_64', 'i686-64', 'i386', 'i686', 'x86'):
return "x86_64" if is_64 else "i686"
# arm based archs
elif machine in ('aarch64', 'arm64', 'armv6l', 'armv7l'):
return "aarch64" if is_64 else "arm"
else:
raise Exception("Unsupported processor")


ffibuilder = FFI()
# arch = "%s-%s" % (os.uname().sysname, os.uname().machine)
uname = platform.uname()
parent_dir = os.path.dirname(os.path.dirname(__file__))

if uname.system == "Windows":
if struct.calcsize("P") * 8 == 64:
libdir = "./lib64"
else:
libdir = "./lib32"
libdir = "./lib"
elif uname.system == "Darwin":
if uname.machine == "x86_64":
libdir = "/Users/runner/work/_temp/install/lib"
else:
libdir = "/usr/local/lib"
libdir = "/Users/runner/work/_temp/install/lib"
else:
libdir = "/usr/local/lib"

libdir += f'/libcurl/build_{abs_machine()}'
os.makedirs(libdir, exist_ok=True)

ffibuilder.set_source(
"curl_cffi._wrapper",
Expand All @@ -41,7 +56,6 @@
extra_compile_args=(
["-Wno-implicit-function-declaration"] if uname.system == "Darwin" else []
),
# extra_link_args=["-Wl,-rpath,$ORIGIN/../libcurl/" + arch],
)

with open(os.path.join(parent_dir, "ffi/cdef.c")) as f:
Expand Down
50 changes: 37 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,53 @@ def get_tag(self):
return python, abi, plat


def abs_machine():
machine = platform.machine()

pointer_bits = struct.calcsize("P") * 8
if pointer_bits not in (32, 64):
raise Exception("Unsupported pointer size")

is_64 = pointer_bits == 64

# x86 based archs
if machine in ('AMD64', 'x86_64', 'i686-64', 'i386', 'i686', 'x86'):
return "x86_64" if is_64 else "i686"
# arm based archs
elif machine in ('aarch64', 'arm64', 'armv6l', 'armv7l'):
return "aarch64" if is_64 else "arm"
else:
raise Exception("Unsupported processor")


def download_so():
uname = platform.uname()
machine = uname.machine
system = platform.system()
machine = abs_machine()

if uname.system == "Windows":
if system == "Windows":
sysname = "win32"
if struct.calcsize("P") * 8 == 64:
machine = "x86_64"
libdir = "./lib64"
libdir = "./lib"
if machine in ("x86_64", "i686"):
so_name = "libcurl.dll"
else:
machine = "i686"
libdir = "./lib32"
so_name = "libcurl.dll"
elif uname.system == "Darwin":
so_name = "SKIP"
elif system == "Darwin":
sysname = "macos"
libdir = "/Users/runner/work/_temp/install/lib"
if machine == "x86_64":
if machine in ("x86_64",):
so_name = "libcurl-impersonate-chrome.4.dylib"
else:
so_name = "SKIP"
else:
sysname = "linux-gnu"
libdir = "/usr/local/lib"
so_name = "libcurl-impersonate-chrome.so"
if machine in ("x86_64", "arm", "aarch64"):
so_name = "libcurl-impersonate-chrome.so"
else:
so_name = "SKIP"

libdir += f'/libcurl/build_{machine}'
os.makedirs(libdir, exist_ok=True)

if so_name == "SKIP":
print(".so file for platform is not available on github.")
Expand All @@ -70,7 +93,8 @@ def download_so():
print("Unpacking downloaded files...")
os.makedirs(libdir, exist_ok=True)
shutil.unpack_archive(file, libdir)
if uname.system == "Windows":

if system == "Windows":
shutil.copy2(f"{libdir}/libcurl.dll", "curl_cffi")


Expand Down

0 comments on commit 42347e6

Please sign in to comment.