Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,38 @@ def get_current_platform():
return "linux_aarch64"
return "linux_x86_64"

def get_native_library_name(platform_name):
Comment thread
ok-nick marked this conversation as resolved.
Resolved
"""Get the file name of the native library that src/c2pa/lib.py loads."""
if platform_name.endswith('windows-msvc'):
return "c2pa_c.dll"
elif platform_name.endswith('apple-darwin'):
return "libc2pa_c.dylib"
elif platform_name.endswith('linux-gnu'):
return "libc2pa_c.so"
else:
raise ValueError(f"Unknown platform: {platform_name}")

def copy_platform_libraries(platform_name, clean_first=False):
"""Copy libraries for a specific platform to the package libs directory.
"""Copy the native library for a specific platform to the package libs directory.

Only the library loaded at runtime is copied. The c2pa-rs release archives
Comment thread
ok-nick marked this conversation as resolved.
Resolved
also contain static libraries, debug symbols and build metadata
(.lib, .rlib, .pdb, .dSYM, .d), which are not needed and would otherwise
end up in the wheel.

Args:
platform_name: The platform to copy libraries for
clean_first: If True, remove existing files in PACKAGE_LIBS_DIR first
"""
platform_dir = ARTIFACTS_DIR / platform_name

# Ensure the platform directory exists and contains files
# Ensure the platform directory exists and contains the library
if not platform_dir.exists():
raise ValueError(f"Platform directory not found: {platform_dir}")

# Get list of all files in the platform directory
platform_files = list(platform_dir.glob('*'))
if not platform_files:
raise ValueError(f"No files found in platform directory: {platform_dir}")
library_file = platform_dir / get_native_library_name(platform_name)
if not library_file.is_file():
raise ValueError(f"Native library not found: {library_file}")

# Clean and recreate the package libs directory if requested
if clean_first and PACKAGE_LIBS_DIR.exists():
Expand All @@ -142,10 +157,7 @@ def copy_platform_libraries(platform_name, clean_first=False):
# Ensure the package libs directory exists
PACKAGE_LIBS_DIR.mkdir(parents=True, exist_ok=True)

# Copy files from platform-specific directory to the package libs directory
for file in platform_files:
if file.is_file():
shutil.copy2(file, PACKAGE_LIBS_DIR / file.name)
shutil.copy2(library_file, PACKAGE_LIBS_DIR / library_file.name)

def find_available_platforms():
"""Scan the artifacts directory for available platform-specific libraries."""
Expand Down
Loading