-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
123 lines (104 loc) · 4.54 KB
/
setup.py
File metadata and controls
123 lines (104 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from setuptools import setup, Extension
from setuptools import find_packages
from setuptools.command.build_py import build_py
import sys
import platform
import os
import subprocess
from pathlib import Path
# Platform-specific extension modules
ext_modules = []
class BuildPyCommand(build_py):
"""Custom build command to build Swift helper on macOS."""
def run(self):
# Build Swift helper on macOS
if platform.system() == "Darwin":
self.build_swift_helper()
# Run standard build
build_py.run(self)
def build_swift_helper(self):
"""Build the Swift CLI helper for ScreenCaptureKit backend on macOS."""
swift_dir = Path("src/proctap/swift/screencapture-audio")
if not swift_dir.exists():
print("WARNING: Swift helper source directory not found, skipping Swift build")
print(f" Expected: {swift_dir}")
return
print("Building ScreenCaptureKit Swift helper for macOS...")
try:
# Build with SwiftPM in release mode
result = subprocess.run(
["swift", "build", "-c", "release"],
cwd=swift_dir,
check=True,
capture_output=True,
text=True,
)
print("Swift build completed successfully")
# Copy binary to package bin directory
bin_dir = Path("src/proctap/bin")
bin_dir.mkdir(parents=True, exist_ok=True)
# Detect architecture (arm64 or x86_64)
import platform as plat
arch = plat.machine()
if arch == "arm64":
build_arch = "arm64-apple-macosx"
else:
build_arch = "x86_64-apple-macosx"
binary_src = swift_dir / ".build" / build_arch / "release" / "screencapture-audio"
binary_dst = bin_dir / "screencapture-audio"
if binary_src.exists():
import shutil
shutil.copy2(binary_src, binary_dst)
print(f"Copied Swift helper to {binary_dst}")
# Make executable
os.chmod(binary_dst, 0o755)
else:
print(f"WARNING: Built binary not found at {binary_src}")
print(f" Checked architecture: {build_arch}")
except subprocess.CalledProcessError as e:
print(f"WARNING: Swift build failed: {e}")
print(f"stdout: {e.stdout}")
print(f"stderr: {e.stderr}")
print("ScreenCaptureKit backend will not be functional")
except FileNotFoundError:
print("WARNING: Swift compiler not found. Install Xcode or Swift toolchain.")
print("ScreenCaptureKit backend will not be functional")
# Build native extension only on Windows
if platform.system() == "Windows":
ext_modules = [
Extension(
"proctap._native",
sources=["src/proctap/_native.cpp"],
language="c++",
extra_compile_args=["/std:c++20", "/EHsc", '/utf-8'] if sys.platform == 'win32' else [],
libraries=[
'ole32', 'uuid', 'propsys'
# CoInitializeEx, CoCreateInstance, CoTaskMemAlloc/Free など
# "Avrt", # 将来、AVRT 系の API (AvSetMmThreadCharacteristicsW 等) を使うなら追加
# "Mmdevapi", # 今は LoadLibrary で動的ロードなので必須ではない
],
)
]
print("Building with Windows WASAPI backend (C++ extension)")
elif platform.system() == "Linux":
# Linux: Pure Python backend using PulseAudio (experimental)
print("Building for Linux with PulseAudio backend (experimental)")
print("NOTE: Per-process isolation has limitations on Linux")
elif platform.system() == "Darwin": # macOS
# macOS: ScreenCaptureKit backend via Swift CLI helper (no C extension needed)
print("Building for macOS with ScreenCaptureKit backend (macOS 13+)")
print("NOTE: Swift helper binary will be built and bundled automatically")
else:
print(f"WARNING: Platform '{platform.system()}' is not officially supported")
print("The package will install but audio capture will not work")
setup(
packages=find_packages(where="src"),
package_dir={"": "src"},
ext_modules=ext_modules,
package_data={
"proctap": ["bin/screencapture-audio"], # Include ScreenCaptureKit Swift helper
},
cmdclass={
"build_py": BuildPyCommand,
},
)